Notes finished
This commit is contained in:
parent
b40dbec724
commit
da306d6270
|
|
@ -1,17 +1,19 @@
|
||||||
package xyz.r0r5chach.cpsAssist.notes;
|
package xyz.r0r5chach.cpsAssist.notes;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.text.InputType;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
import xyz.r0r5chach.cpsAssist.R;
|
import xyz.r0r5chach.cpsAssist.R;
|
||||||
|
|
||||||
|
|
@ -52,15 +54,11 @@ public class BtnOnClickListener implements View.OnClickListener {
|
||||||
|
|
||||||
private void onEditClick(String path, View v) {
|
private void onEditClick(String path, View v) {
|
||||||
File tmp = new File(v.getContext().getExternalFilesDir(null) + "/" + path); //load file into var
|
File tmp = new File(v.getContext().getExternalFilesDir(null) + "/" + path); //load file into var
|
||||||
FileReader r = null;
|
EditText editField = new EditText(v.getContext());
|
||||||
AlertDialog.Builder dialog = new AlertDialog.Builder(v.getContext());
|
editField.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||||
dialog.setTitle("Edit Note");
|
AlertDialog dialog = editDialog(v, tmp, editField);
|
||||||
dialog.setView(R.layout.edit_dialog);
|
initNoteText(editField, tmp);
|
||||||
dialog.create().show();
|
dialog.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) {
|
private void onDeleteClick(String path) {
|
||||||
|
|
@ -73,4 +71,36 @@ public class BtnOnClickListener implements View.OnClickListener {
|
||||||
return name.getText().toString();
|
return name.getText().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AlertDialog editDialog(View v, File note, TextView editField) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
|
||||||
|
builder.setTitle("Edit Note");
|
||||||
|
builder.setView(editField);
|
||||||
|
builder.setPositiveButton("Save", new DialogOnClickListener(adapter, note, editField));
|
||||||
|
builder.setNegativeButton("Cancel", new DialogOnClickListener());
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private AlertDialog viewDialog(View v) {
|
||||||
|
AlertDialog.Builder dialog = new AlertDialog.Builder(v.getContext());
|
||||||
|
dialog.setTitle("View Note");
|
||||||
|
dialog.setMessage("note"); //TODO: Get selected file's note
|
||||||
|
return dialog.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initNoteText(TextView editField, File note) {
|
||||||
|
try {
|
||||||
|
Scanner r = new Scanner(note);
|
||||||
|
StringBuilder text = new StringBuilder();
|
||||||
|
while (r.hasNextLine()) {
|
||||||
|
text.append(r.nextLine());
|
||||||
|
}
|
||||||
|
editField.setText(text.toString());
|
||||||
|
r.close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist.notes;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import xyz.r0r5chach.cpsAssist.R;
|
||||||
|
|
||||||
|
public class DialogOnClickListener implements DialogInterface.OnClickListener {
|
||||||
|
private Adapter adapter;
|
||||||
|
private File note;
|
||||||
|
private TextView editField;
|
||||||
|
|
||||||
|
|
||||||
|
public DialogOnClickListener() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DialogOnClickListener(Adapter adapter, File note, TextView editField) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
this.note = note;
|
||||||
|
this.editField = editField;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
AlertDialog d = (AlertDialog) dialog;
|
||||||
|
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||||
|
adapter.getNotes().updateNote(note, editField.getText().toString());
|
||||||
|
adapter.notifyItemChanged(adapter.getNotes().getNoteIndex(note));
|
||||||
|
}
|
||||||
|
d.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
<?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>
|
|
||||||
Loading…
Reference in New Issue