upto edit
This commit is contained in:
parent
1519a4ebb8
commit
b40dbec724
|
|
@ -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>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<component name="VisualizationToolProject">
|
||||
<option name="state">
|
||||
<ProjectState>
|
||||
<option name="scale" value="0.037278575835022476" />
|
||||
<option name="scale" value="0.22" />
|
||||
</ProjectState>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "xyz.r0r5chach.cpsAssist"
|
||||
minSdk 26
|
||||
minSdk 29
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}. <b><i>Note: Otherwise it is null.</i></b>
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
|||
|
|
@ -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<Adapter.ViewHolder> {
|
|||
@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<Adapter.ViewHolder> {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package xyz.r0r5chach.cpsAssist.notes;
|
||||
|
||||
public enum BtnID {
|
||||
ADD_BUTTON,
|
||||
EDIT_BUTTON,
|
||||
DELETE_BUTTON
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package xyz.r0r5chach.cpsAssist.notes;
|
||||
|
||||
public enum ButtonID {
|
||||
ADD_BUTTON;
|
||||
}
|
||||
|
|
@ -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<File> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -20,4 +20,5 @@
|
|||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -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>
|
||||
|
|
@ -1,10 +1,24 @@
|
|||
<?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:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fileNameField"
|
||||
android:layout_width="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>
|
||||
|
|
@ -13,4 +13,8 @@
|
|||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
<style name="edit_dialog">
|
||||
<item name="android:background">@color/white</item>
|
||||
<item name="android:textColor">@color/black</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -8,4 +8,8 @@
|
|||
<string name="title_activity_notes">NotesActivity</string>
|
||||
<!-- Notes View -->
|
||||
<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>
|
||||
|
|
@ -19,4 +19,8 @@
|
|||
</style>
|
||||
<style name="Theme.CpsAssist.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
<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>
|
||||
Loading…
Reference in New Issue