diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
deleted file mode 100644
index 1ecbe7a..0000000
--- a/.idea/deploymentTargetDropDown.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d47f433..cb3f61e 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -10,7 +10,7 @@
diff --git a/app/build.gradle b/app/build.gradle
index 21c70cf..caa9c32 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "xyz.r0r5chach.cpsAssist"
- minSdk 26
+ minSdk 29
targetSdk 33
versionCode 1
versionName "1.0"
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/login/BtnOnClickListener.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/login/BtnOnClickListener.java
index 8b198b6..dc58ff0 100644
--- a/app/src/main/java/xyz/r0r5chach/cpsAssist/login/BtnOnClickListener.java
+++ b/app/src/main/java/xyz/r0r5chach/cpsAssist/login/BtnOnClickListener.java
@@ -8,7 +8,6 @@ import android.widget.Toast;
import xyz.r0r5chach.cpsAssist.ArrayTools;
import xyz.r0r5chach.cpsAssist.notes.NotesActivity;
-
/**
* This Class defines the definition of the OnCLickListener for the LoginActivity
* @author r0r5chach
@@ -112,7 +111,7 @@ public class BtnOnClickListener implements View.OnClickListener{
*/
private boolean isUser(String[] inputs) {
for (String[] user: users) {
- if (inputs[0].equals(user[0]) || inputs[1].equals(user[1])) {
+ if (inputs[0].equals(user[0]) && inputs[1].equals(user[1])) {
return true;
}
}
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/login/LoginActivity.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/login/LoginActivity.java
index 2c69c31..9ba6ef4 100644
--- a/app/src/main/java/xyz/r0r5chach/cpsAssist/login/LoginActivity.java
+++ b/app/src/main/java/xyz/r0r5chach/cpsAssist/login/LoginActivity.java
@@ -6,8 +6,16 @@ import android.os.Bundle;
import xyz.r0r5chach.cpsAssist.R;
+/**
+ * This Class defines the processes to run for the login activity for the application
+ */
public class LoginActivity extends AppCompatActivity {
-
+ /**
+ * This method defines what to do when the activity is created
+ * @param savedInstanceState If the activity is being re-initialized after
+ * previously being shut down then this Bundle contains the data it most
+ * recently supplied in {@link #onSaveInstanceState}. Note: Otherwise it is null.
+ */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Adapter.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Adapter.java
index 8724636..eb42c35 100644
--- a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Adapter.java
+++ b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Adapter.java
@@ -3,13 +3,13 @@ package xyz.r0r5chach.cpsAssist.notes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.io.File;
-import java.util.List;
import xyz.r0r5chach.cpsAssist.R;
@@ -25,7 +25,7 @@ public class Adapter extends RecyclerView.Adapter {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent,int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notes_item, parent, false);
- return new ViewHolder(v);
+ return new ViewHolder(v, this);
}
@Override
@@ -49,14 +49,28 @@ public class Adapter extends RecyclerView.Adapter {
public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView fileName;
- public ViewHolder(View v) {
+ private final Button editButton;
+ private final Button deleteButton;
+ public ViewHolder(View v, Adapter adapter) {
super(v);
fileName = v.findViewById(R.id.fileNameField);
+ editButton = v.findViewById(R.id.edit_Button);
+ deleteButton = v.findViewById(R.id.delete_Button);
+ editButton.setOnClickListener(new BtnOnClickListener(adapter));
+ deleteButton.setOnClickListener(new BtnOnClickListener(adapter));
}
public TextView getFileName() {
return fileName;
}
+
+ public Button getEditButton() {
+ return editButton;
+ }
+
+ public Button getDeleteButton() {
+ return deleteButton;
+ }
}
}
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/BtnID.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/BtnID.java
new file mode 100644
index 0000000..e710f9f
--- /dev/null
+++ b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/BtnID.java
@@ -0,0 +1,7 @@
+package xyz.r0r5chach.cpsAssist.notes;
+
+public enum BtnID {
+ ADD_BUTTON,
+ EDIT_BUTTON,
+ DELETE_BUTTON
+}
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/BtnOnClickListener.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/BtnOnClickListener.java
index a459a9f..2dde243 100644
--- a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/BtnOnClickListener.java
+++ b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/BtnOnClickListener.java
@@ -1,13 +1,24 @@
package xyz.r0r5chach.cpsAssist.notes;
+import android.app.AlertDialog;
import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.util.Locale;
+import xyz.r0r5chach.cpsAssist.R;
+
+
public class BtnOnClickListener implements View.OnClickListener {
private final Adapter adapter;
-
public BtnOnClickListener(Adapter adapter) {
this.adapter = adapter;
}
@@ -15,18 +26,51 @@ public class BtnOnClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
-
- String test = view.getResources().getResourceName(view.getId()).split("/")[1];
- switch(ButtonID.valueOf(test.toUpperCase(Locale.ROOT))) {
+ String path;
+ String id = view.getResources().getResourceName(view.getId()).split("/")[1];
+ switch(BtnID.valueOf(id.toUpperCase(Locale.ROOT))) {
case ADD_BUTTON:
onAddClick();
+ Toast.makeText(view.getContext(), "File Created", Toast.LENGTH_LONG).show();
+ break;
+ case EDIT_BUTTON:
+ path = getPath(view);
+ onEditClick(path, view);
+ break;
+ case DELETE_BUTTON:
+ path = getPath(view);
+ onDeleteClick(path);
+ Toast.makeText(view.getContext(), "File Deleted" , Toast.LENGTH_LONG).show();
break;
}
}
private void onAddClick() {
- Notes notes = adapter.getNotes();
- notes.createNote();
- adapter.notifyItemInserted(notes.getAmount());
+ adapter.getNotes().createNote();
+ adapter.notifyItemInserted(adapter.getNotes().getAmount());
}
-}
+
+ private void onEditClick(String path, View v) {
+ File tmp = new File(v.getContext().getExternalFilesDir(null) + "/" + path); //load file into var
+ FileReader r = null;
+ AlertDialog.Builder dialog = new AlertDialog.Builder(v.getContext());
+ dialog.setTitle("Edit Note");
+ dialog.setView(R.layout.edit_dialog);
+ dialog.create().show();
+ //TODO: get text from dialog and save to file
+ //TODO: set text in dialog to what is in note
+ adapter.getNotes().updateNote(tmp, "");
+ adapter.notifyItemChanged(adapter.getNotes().getNoteIndex(tmp));
+ }
+
+ private void onDeleteClick(String path) {
+ adapter.notifyItemRemoved(adapter.getNotes().deleteNote(path));
+ }
+
+ private String getPath(View v) {
+ LinearLayout row = (LinearLayout) v.getParent();
+ TextView name = row.findViewById(R.id.fileNameField);
+ return name.getText().toString();
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/ButtonID.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/ButtonID.java
deleted file mode 100644
index d91dd58..0000000
--- a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/ButtonID.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package xyz.r0r5chach.cpsAssist.notes;
-
-public enum ButtonID {
- ADD_BUTTON;
-}
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Notes.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Notes.java
index f25cdd0..d150593 100644
--- a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Notes.java
+++ b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/Notes.java
@@ -1,13 +1,15 @@
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.Arrays;
import java.util.List;
+import java.util.Objects;
public class Notes {
private final List notes;
@@ -18,16 +20,39 @@ public class Notes {
this.rootDir = rootDir;
this.username = username;
notes = new ArrayList<>();
+ getStoredNotes();
+ }
+
+ private void getStoredNotes() {
+ notes.addAll(Arrays.asList(Objects.requireNonNull(rootDir.listFiles())));
}
public void createNote() {
- String fileName = LocalDateTime.now().toString() + "-" +
- username;
+ String fileName = LocalDateTime.now().toString() + "-" + username;
//Get current username
File note = new File(rootDir, fileName);
notes.add(note);
try {
- writeFile(note);
+ writeFile(note, "");
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public int deleteNote(String path) {
+ File tmp = new File(rootDir.getAbsolutePath() + "/" + path);
+ int index = getNoteIndex(tmp);
+ notes.remove(index);
+ if (tmp.delete()) {
+ return index;
+ }
+ return -1;
+ }
+
+ public void updateNote(File note, String content) {
+ try {
+ writeFile(note, content);
}
catch (IOException e) {
e.printStackTrace();
@@ -38,14 +63,18 @@ public class Notes {
return notes.get(index);
}
+ public int getNoteIndex(File note) {
+ return notes.indexOf(note);
+ }
+
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();
+ private void writeFile(File file, String content) throws IOException {
+ OutputStreamWriter fileWriter = new OutputStreamWriter(Files.newOutputStream(file.toPath()));
+ fileWriter.write(content);
+ fileWriter.flush();
+ fileWriter.close();
}
}
diff --git a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/NotesActivity.java b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/NotesActivity.java
index e39878f..6345b7d 100644
--- a/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/NotesActivity.java
+++ b/app/src/main/java/xyz/r0r5chach/cpsAssist/notes/NotesActivity.java
@@ -5,6 +5,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
+import android.widget.TextView;
import xyz.r0r5chach.cpsAssist.R;
@@ -21,8 +22,9 @@ public class NotesActivity extends AppCompatActivity {
private void initRecycler() {
RecyclerView list = findViewById(R.id.notesList);
- adapter = new Adapter(getFilesDir(), getIntent().getStringExtra("username"));
+ adapter = new Adapter(getExternalFilesDir(null), getIntent().getStringExtra("username"));
list.setAdapter(adapter);
list.setLayoutManager(new LinearLayoutManager(this));
+ adapter.notifyItemRangeChanged(0, adapter.getItemCount());
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_notes.xml b/app/src/main/res/layout/activity_notes.xml
index 8cb368b..d19daa7 100644
--- a/app/src/main/res/layout/activity_notes.xml
+++ b/app/src/main/res/layout/activity_notes.xml
@@ -20,4 +20,5 @@
android:layout_height="match_parent">
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/edit_dialog.xml b/app/src/main/res/layout/edit_dialog.xml
new file mode 100644
index 0000000..39c89f8
--- /dev/null
+++ b/app/src/main/res/layout/edit_dialog.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/notes_item.xml b/app/src/main/res/layout/notes_item.xml
index 5824ade..b594e9b 100644
--- a/app/src/main/res/layout/notes_item.xml
+++ b/app/src/main/res/layout/notes_item.xml
@@ -1,10 +1,24 @@
+ android:layout_height="wrap_content">
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index 4f577df..601bd4b 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -13,4 +13,8 @@
- ?attr/colorPrimaryVariant
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6a49220..48772d3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -8,4 +8,8 @@
NotesActivity
Add
+ Edit
+ Delete
+ Note
+ Save
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 07d83dd..4cdcc02 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -19,4 +19,8 @@
+
\ No newline at end of file