layout edits
This commit is contained in:
parent
e0949f115c
commit
1519a4ebb8
|
|
@ -8,7 +8,7 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "xyz.r0r5chach.cpsAssist"
|
||||
minSdk 24
|
||||
minSdk 26
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.r0r5chach.cpsAssist.login;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
|
@ -56,7 +57,8 @@ public class BtnOnClickListener implements View.OnClickListener{
|
|||
Intent home = new Intent(view.getContext(), NotesActivity.class);
|
||||
home.putExtra("username", inputs[0]);
|
||||
view.getContext().startActivity(home);
|
||||
((android.app.Activity)view.getContext()).finish();
|
||||
Activity login = (Activity) view.getContext();
|
||||
login.finish();
|
||||
}
|
||||
else {
|
||||
currentAttempts += 1;
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ import xyz.r0r5chach.cpsAssist.R;
|
|||
|
||||
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
|
||||
|
||||
private final List<File> notes;
|
||||
private final Notes notes;
|
||||
|
||||
public Adapter(List<File> notes) {
|
||||
this.notes = notes;
|
||||
public Adapter(File path, String username) {
|
||||
notes = getStoredNotes(path, username);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -30,15 +30,22 @@ public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int index) {
|
||||
File note = notes.get(index);
|
||||
File note = notes.getNote(index);
|
||||
holder.getFileName().setText(note.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 0;
|
||||
return notes.getAmount();
|
||||
}
|
||||
|
||||
public Notes getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
private Notes getStoredNotes(File path, String username) {
|
||||
return new Notes(path, username);
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView fileName;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package xyz.r0r5chach.cpsAssist.notes;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class BtnOnClickListener implements View.OnClickListener {
|
||||
private final Adapter adapter;
|
||||
|
||||
|
||||
public BtnOnClickListener(Adapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
String test = view.getResources().getResourceName(view.getId()).split("/")[1];
|
||||
switch(ButtonID.valueOf(test.toUpperCase(Locale.ROOT))) {
|
||||
case ADD_BUTTON:
|
||||
onAddClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void onAddClick() {
|
||||
Notes notes = adapter.getNotes();
|
||||
notes.createNote();
|
||||
adapter.notifyItemInserted(notes.getAmount());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package xyz.r0r5chach.cpsAssist.notes;
|
||||
|
||||
public enum ButtonID {
|
||||
ADD_BUTTON;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package xyz.r0r5chach.cpsAssist.notes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Notes {
|
||||
private final List<File> notes;
|
||||
private final File rootDir;
|
||||
private final String username;
|
||||
|
||||
public Notes(File rootDir, String username) {
|
||||
this.rootDir = rootDir;
|
||||
this.username = username;
|
||||
notes = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void createNote() {
|
||||
String fileName = LocalDateTime.now().toString() + "-" +
|
||||
username;
|
||||
//Get current username
|
||||
File note = new File(rootDir, fileName);
|
||||
notes.add(note);
|
||||
try {
|
||||
writeFile(note);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public File getNote(int index) {
|
||||
return notes.get(index);
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return notes.size();
|
||||
}
|
||||
|
||||
private void writeFile(File file) throws IOException {
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(file.toPath()));
|
||||
outputStreamWriter.write("Hi");
|
||||
outputStreamWriter.flush();
|
||||
outputStreamWriter.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -6,31 +6,23 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import xyz.r0r5chach.cpsAssist.R;
|
||||
|
||||
public class NotesActivity extends AppCompatActivity {
|
||||
private List<File> notes;
|
||||
private Adapter adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_notes);
|
||||
notes = getStoredNotes();
|
||||
initRecycler();
|
||||
findViewById(R.id.add_Button).setOnClickListener(new BtnOnClickListener(adapter));
|
||||
}
|
||||
|
||||
private void initRecycler() {
|
||||
RecyclerView list =findViewById(R.id.notesList);
|
||||
list.setAdapter(new Adapter(notes));
|
||||
RecyclerView list = findViewById(R.id.notesList);
|
||||
adapter = new Adapter(getFilesDir(), getIntent().getStringExtra("username"));
|
||||
list.setAdapter(adapter);
|
||||
list.setLayoutManager(new LinearLayoutManager(this));
|
||||
}
|
||||
|
||||
private List<File> getStoredNotes() {
|
||||
return Arrays.asList(Objects.requireNonNull(getFilesDir().listFiles()));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue