upto edit

This commit is contained in:
r0r-5chach 2023-03-26 01:11:08 +00:00
parent 1519a4ebb8
commit b40dbec724
17 changed files with 179 additions and 49 deletions

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="62f6513d" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-03-24T22:04:46.108607Z" />
</component>
</project>

View File

@ -10,7 +10,7 @@
<component name="VisualizationToolProject"> <component name="VisualizationToolProject">
<option name="state"> <option name="state">
<ProjectState> <ProjectState>
<option name="scale" value="0.037278575835022476" /> <option name="scale" value="0.22" />
</ProjectState> </ProjectState>
</option> </option>
</component> </component>

View File

@ -8,7 +8,7 @@ android {
defaultConfig { defaultConfig {
applicationId "xyz.r0r5chach.cpsAssist" applicationId "xyz.r0r5chach.cpsAssist"
minSdk 26 minSdk 29
targetSdk 33 targetSdk 33
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"

View File

@ -8,7 +8,6 @@ import android.widget.Toast;
import xyz.r0r5chach.cpsAssist.ArrayTools; import xyz.r0r5chach.cpsAssist.ArrayTools;
import xyz.r0r5chach.cpsAssist.notes.NotesActivity; import xyz.r0r5chach.cpsAssist.notes.NotesActivity;
/** /**
* This Class defines the definition of the OnCLickListener for the LoginActivity * This Class defines the definition of the OnCLickListener for the LoginActivity
* @author r0r5chach * @author r0r5chach
@ -112,7 +111,7 @@ public class BtnOnClickListener implements View.OnClickListener{
*/ */
private boolean isUser(String[] inputs) { private boolean isUser(String[] inputs) {
for (String[] user: users) { 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; return true;
} }
} }

View File

@ -6,8 +6,16 @@ import android.os.Bundle;
import xyz.r0r5chach.cpsAssist.R; import xyz.r0r5chach.cpsAssist.R;
/**
* This Class defines the processes to run for the login activity for the application
*/
public class LoginActivity extends AppCompatActivity { 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}. <b><i>Note: Otherwise it is null.</i></b>
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

View File

@ -3,13 +3,13 @@ package xyz.r0r5chach.cpsAssist.notes;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.io.File; import java.io.File;
import java.util.List;
import xyz.r0r5chach.cpsAssist.R; import xyz.r0r5chach.cpsAssist.R;
@ -25,7 +25,7 @@ public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent,int viewType) { public ViewHolder onCreateViewHolder(ViewGroup parent,int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notes_item, parent, false); View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notes_item, parent, false);
return new ViewHolder(v); return new ViewHolder(v, this);
} }
@Override @Override
@ -49,14 +49,28 @@ public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
public static class ViewHolder extends RecyclerView.ViewHolder { public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView fileName; private final TextView fileName;
public ViewHolder(View v) { private final Button editButton;
private final Button deleteButton;
public ViewHolder(View v, Adapter adapter) {
super(v); super(v);
fileName = v.findViewById(R.id.fileNameField); 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() { public TextView getFileName() {
return fileName; return fileName;
} }
public Button getEditButton() {
return editButton;
}
public Button getDeleteButton() {
return deleteButton;
}
} }
} }

View File

@ -0,0 +1,7 @@
package xyz.r0r5chach.cpsAssist.notes;
public enum BtnID {
ADD_BUTTON,
EDIT_BUTTON,
DELETE_BUTTON
}

View File

@ -1,13 +1,24 @@
package xyz.r0r5chach.cpsAssist.notes; package xyz.r0r5chach.cpsAssist.notes;
import android.app.AlertDialog;
import android.view.View; 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 java.util.Locale;
import xyz.r0r5chach.cpsAssist.R;
public class BtnOnClickListener implements View.OnClickListener { public class BtnOnClickListener implements View.OnClickListener {
private final Adapter adapter; private final Adapter adapter;
public BtnOnClickListener(Adapter adapter) { public BtnOnClickListener(Adapter adapter) {
this.adapter = adapter; this.adapter = adapter;
} }
@ -15,18 +26,51 @@ public class BtnOnClickListener implements View.OnClickListener {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
String path;
String test = view.getResources().getResourceName(view.getId()).split("/")[1]; String id = view.getResources().getResourceName(view.getId()).split("/")[1];
switch(ButtonID.valueOf(test.toUpperCase(Locale.ROOT))) { switch(BtnID.valueOf(id.toUpperCase(Locale.ROOT))) {
case ADD_BUTTON: case ADD_BUTTON:
onAddClick(); 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; break;
} }
} }
private void onAddClick() { private void onAddClick() {
Notes notes = adapter.getNotes(); adapter.getNotes().createNote();
notes.createNote(); adapter.notifyItemInserted(adapter.getNotes().getAmount());
adapter.notifyItemInserted(notes.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();
}
}

View File

@ -1,5 +0,0 @@
package xyz.r0r5chach.cpsAssist.notes;
public enum ButtonID {
ADD_BUTTON;
}

View File

@ -1,13 +1,15 @@
package xyz.r0r5chach.cpsAssist.notes; package xyz.r0r5chach.cpsAssist.notes;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.nio.file.Files; import java.nio.file.Files;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
public class Notes { public class Notes {
private final List<File> notes; private final List<File> notes;
@ -18,16 +20,39 @@ public class Notes {
this.rootDir = rootDir; this.rootDir = rootDir;
this.username = username; this.username = username;
notes = new ArrayList<>(); notes = new ArrayList<>();
getStoredNotes();
}
private void getStoredNotes() {
notes.addAll(Arrays.asList(Objects.requireNonNull(rootDir.listFiles())));
} }
public void createNote() { public void createNote() {
String fileName = LocalDateTime.now().toString() + "-" + String fileName = LocalDateTime.now().toString() + "-" + username;
username;
//Get current username //Get current username
File note = new File(rootDir, fileName); File note = new File(rootDir, fileName);
notes.add(note); notes.add(note);
try { 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) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -38,14 +63,18 @@ public class Notes {
return notes.get(index); return notes.get(index);
} }
public int getNoteIndex(File note) {
return notes.indexOf(note);
}
public int getAmount() { public int getAmount() {
return notes.size(); return notes.size();
} }
private void writeFile(File file) throws IOException { private void writeFile(File file, String content) throws IOException {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(file.toPath())); OutputStreamWriter fileWriter = new OutputStreamWriter(Files.newOutputStream(file.toPath()));
outputStreamWriter.write("Hi"); fileWriter.write(content);
outputStreamWriter.flush(); fileWriter.flush();
outputStreamWriter.close(); fileWriter.close();
} }
} }

View File

@ -5,6 +5,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView;
import xyz.r0r5chach.cpsAssist.R; import xyz.r0r5chach.cpsAssist.R;
@ -21,8 +22,9 @@ public class NotesActivity extends AppCompatActivity {
private void initRecycler() { private void initRecycler() {
RecyclerView list = findViewById(R.id.notesList); 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.setAdapter(adapter);
list.setLayoutManager(new LinearLayoutManager(this)); list.setLayoutManager(new LinearLayoutManager(this));
adapter.notifyItemRangeChanged(0, adapter.getItemCount());
} }
} }

View File

@ -20,4 +20,5 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView> </androidx.recyclerview.widget.RecyclerView>
</RelativeLayout> </RelativeLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/editTextTextMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine"
android:autofillHints=""
android:hint="@string/note_edit_hint"/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/saveButtonText" />
</LinearLayout>

View File

@ -1,10 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/fileNameField" android:id="@+id/fileNameField"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<Button
android:id="@+id/edit_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/editButtonText" />
<Button
android:id="@+id/delete_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/deleteButtonText" />
</LinearLayout> </LinearLayout>

View File

@ -13,4 +13,8 @@
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
</style> </style>
<style name="edit_dialog">
<item name="android:background">@color/white</item>
<item name="android:textColor">@color/black</item>
</style>
</resources> </resources>

View File

@ -8,4 +8,8 @@
<string name="title_activity_notes">NotesActivity</string> <string name="title_activity_notes">NotesActivity</string>
<!-- Notes View --> <!-- Notes View -->
<string name="addButtonText">Add</string> <string name="addButtonText">Add</string>
<string name="editButtonText">Edit</string>
<string name="deleteButtonText">Delete</string>
<string name="note_edit_hint">Note</string>
<string name="saveButtonText">Save</string>
</resources> </resources>

View File

@ -19,4 +19,8 @@
</style> </style>
<style name="Theme.CpsAssist.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="Theme.CpsAssist.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.CpsAssist.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> <style name="Theme.CpsAssist.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="edit_dialog">
<item name="android:background">@color/black</item>
<item name="android:textColor">@color/white</item>
</style>
</resources> </resources>