commit
90c6f055dd
|
|
@ -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="adb-62f6513d-bkDenR._adb-tls-connect._tcp" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</runningDeviceTargetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2023-03-18T17:23:33.549301Z" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<component name="VisualizationToolProject">
|
<component name="VisualizationToolProject">
|
||||||
<option name="state">
|
<option name="state">
|
||||||
<ProjectState>
|
<ProjectState>
|
||||||
<option name="scale" value="0.053000877083072294" />
|
<option name="scale" value="0.22" />
|
||||||
</ProjectState>
|
</ProjectState>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "xyz.r0r5chach.cpsAssist"
|
applicationId "xyz.r0r5chach.cpsAssist"
|
||||||
minSdk 24
|
minSdk 29
|
||||||
targetSdk 33
|
targetSdk 33
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|
@ -26,6 +26,9 @@ android {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
buildFeatures {
|
||||||
|
viewBinding true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
@ -33,6 +36,8 @@ dependencies {
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'com.google.android.material:material:1.8.0'
|
implementation 'com.google.android.material:material:1.8.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
|
implementation 'androidx.navigation:navigation-fragment:2.5.3'
|
||||||
|
implementation 'androidx.navigation:navigation-ui:2.5.3'
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
|
@ -11,6 +10,11 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.CpsAssist"
|
android:theme="@style/Theme.CpsAssist"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".notes.NotesActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/title_activity_notes"/>
|
||||||
|
<activity android:name=".main.MainActivity"/>
|
||||||
<activity
|
<activity
|
||||||
android:name=".login.LoginActivity"
|
android:name=".login.LoginActivity"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist;
|
||||||
|
|
||||||
|
public enum BtnID {
|
||||||
|
ADD_BUTTON,
|
||||||
|
EDIT_BUTTON,
|
||||||
|
DELETE_BUTTON,
|
||||||
|
NOTES_BUTTON,
|
||||||
|
QUIZ_BUTTON
|
||||||
|
}
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
package xyz.r0r5chach.cpsAssist.home;
|
|
||||||
|
|
||||||
public class HomeActivity {
|
|
||||||
}
|
|
||||||
|
|
@ -7,12 +7,13 @@ import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import xyz.r0r5chach.cpsAssist.ArrayTools;
|
import xyz.r0r5chach.cpsAssist.ArrayTools;
|
||||||
|
import xyz.r0r5chach.cpsAssist.main.MainActivity;
|
||||||
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
|
||||||
*/
|
*/
|
||||||
public class OnClickListener implements View.OnClickListener{
|
public class BtnOnClickListener implements View.OnClickListener{
|
||||||
/**
|
/**
|
||||||
* This attribute stores the amount of attempts the user has currently taken
|
* This attribute stores the amount of attempts the user has currently taken
|
||||||
*/
|
*/
|
||||||
|
|
@ -34,7 +35,7 @@ public class OnClickListener implements View.OnClickListener{
|
||||||
* @param usernameField the View for the username field of the UI
|
* @param usernameField the View for the username field of the UI
|
||||||
* @param passwordField the View for the password field of the UI
|
* @param passwordField the View for the password field of the UI
|
||||||
*/
|
*/
|
||||||
public OnClickListener(EditText usernameField, EditText passwordField, String users) {
|
public BtnOnClickListener(EditText usernameField, EditText passwordField, String users) {
|
||||||
initUsers(users);
|
initUsers(users);
|
||||||
this.currentAttempts = 0;
|
this.currentAttempts = 0;
|
||||||
this.usernameField = usernameField;
|
this.usernameField = usernameField;
|
||||||
|
|
@ -53,10 +54,11 @@ public class OnClickListener implements View.OnClickListener{
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isUser(inputs)) {
|
if (isUser(inputs)) {
|
||||||
Intent home = new Intent(view.getContext(), NotesActivity.class);
|
Intent home = new Intent(view.getContext(), MainActivity.class);
|
||||||
home.putExtra("username", inputs[0]);
|
home.putExtra("username", inputs[0]);
|
||||||
view.getContext().startActivity(home);
|
view.getContext().startActivity(home);
|
||||||
((Activity)view.getContext()).finish();
|
Activity login = (Activity) view.getContext();
|
||||||
|
login.finish();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currentAttempts += 1;
|
currentAttempts += 1;
|
||||||
|
|
@ -110,7 +112,7 @@ public class OnClickListener 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,12 +6,20 @@ 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);
|
||||||
setContentView(R.layout.activity_login);
|
setContentView(R.layout.activity_login);
|
||||||
findViewById(R.id.loginButton).setOnClickListener(new OnClickListener(findViewById(R.id.userNameField), findViewById(R.id.passwordField), getString(R.string.users)));
|
findViewById(R.id.loginButton).setOnClickListener(new BtnOnClickListener(findViewById(R.id.userNameField), findViewById(R.id.passwordField), getString(R.string.users)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist.main;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import xyz.r0r5chach.cpsAssist.BtnID;
|
||||||
|
import xyz.r0r5chach.cpsAssist.quiz.QuizActivity;
|
||||||
|
import xyz.r0r5chach.cpsAssist.notes.NotesActivity;
|
||||||
|
|
||||||
|
public class BtnOnClickListener implements View.OnClickListener{
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
String id = v.getResources().getResourceName(v.getId()).split("/")[1];
|
||||||
|
Intent intent = null;
|
||||||
|
switch(BtnID.valueOf(id.toUpperCase(Locale.ROOT))) {
|
||||||
|
case NOTES_BUTTON:
|
||||||
|
intent = new Intent(v.getContext(), NotesActivity.class);
|
||||||
|
break;
|
||||||
|
case QUIZ_BUTTON:
|
||||||
|
intent = new Intent(v.getContext(), QuizActivity.class);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Activity main = (Activity) v.getContext();
|
||||||
|
if (intent != null) {
|
||||||
|
intent.putExtra("username", main.getIntent().getStringExtra("username"));
|
||||||
|
main.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist.main;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import xyz.r0r5chach.cpsAssist.R;
|
||||||
|
import xyz.r0r5chach.cpsAssist.main.BtnOnClickListener;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
setTitle("Home- " + getIntent().getStringExtra("username"));
|
||||||
|
findViewById(R.id.notes_button).setOnClickListener(new BtnOnClickListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
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 xyz.r0r5chach.cpsAssist.R;
|
||||||
|
|
||||||
|
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
|
||||||
|
|
||||||
|
private final Notes notes;
|
||||||
|
|
||||||
|
public Adapter(File path, String username) {
|
||||||
|
notes = getStoredNotes(path, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@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, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(ViewHolder holder, int index) {
|
||||||
|
File note = notes.getNote(index);
|
||||||
|
holder.getFileName().setText(note.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
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;
|
||||||
|
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,98 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist.notes;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import xyz.r0r5chach.cpsAssist.BtnID;
|
||||||
|
import xyz.r0r5chach.cpsAssist.R;
|
||||||
|
|
||||||
|
|
||||||
|
public class BtnOnClickListener implements View.OnClickListener {
|
||||||
|
private final Adapter adapter;
|
||||||
|
|
||||||
|
public BtnOnClickListener(Adapter adapter) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
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() {
|
||||||
|
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
|
||||||
|
EditText editField = new EditText(v.getContext());
|
||||||
|
editField.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||||
|
AlertDialog dialog = editDialog(v, tmp, editField);
|
||||||
|
initNoteText(editField, tmp);
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist.notes;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
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;
|
||||||
|
private final File rootDir;
|
||||||
|
private final String username;
|
||||||
|
|
||||||
|
public Notes(File rootDir, String username) {
|
||||||
|
this.rootDir = rootDir;
|
||||||
|
this.username = username;
|
||||||
|
notes = new ArrayList<>();
|
||||||
|
getStoredNotes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getStoredNotes() {
|
||||||
|
for (File note: Objects.requireNonNull(rootDir.listFiles())) {
|
||||||
|
if (note.getName().contains(username)) {
|
||||||
|
notes.add(note);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getNote(int index) {
|
||||||
|
return notes.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNoteIndex(File note) {
|
||||||
|
return notes.indexOf(note);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount() {
|
||||||
|
return notes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeFile(File file, String content) throws IOException {
|
||||||
|
OutputStreamWriter fileWriter = new OutputStreamWriter(Files.newOutputStream(file.toPath()));
|
||||||
|
fileWriter.write(content);
|
||||||
|
fileWriter.flush();
|
||||||
|
fileWriter.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist.notes;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import xyz.r0r5chach.cpsAssist.R;
|
||||||
|
|
||||||
|
public class NotesActivity extends AppCompatActivity {
|
||||||
|
private Adapter adapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_notes);
|
||||||
|
initRecycler();
|
||||||
|
setTitle("Notes- " + getIntent().getStringExtra("username"));
|
||||||
|
findViewById(R.id.add_Button).setOnClickListener(new BtnOnClickListener(adapter));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initRecycler() {
|
||||||
|
RecyclerView list = findViewById(R.id.notesList);
|
||||||
|
adapter = new Adapter(getExternalFilesDir(null), getIntent().getStringExtra("username"));
|
||||||
|
list.setAdapter(adapter);
|
||||||
|
list.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
adapter.notifyItemRangeChanged(0, adapter.getItemCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package xyz.r0r5chach.cpsAssist.quiz;
|
||||||
|
|
||||||
|
public class QuizActivity {
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?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"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
@ -15,7 +16,8 @@
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="@string/usernameFieldHint"
|
android:hint="@string/usernameFieldHint"
|
||||||
android:inputType="textPersonName"
|
android:inputType="textPersonName"
|
||||||
android:minHeight="48dp" />
|
android:minHeight="48dp"
|
||||||
|
tools:ignore="VisualLintTextFieldSize" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/passwordField"
|
android:id="@+id/passwordField"
|
||||||
|
|
@ -27,7 +29,8 @@
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="@string/passwordFieldHint"
|
android:hint="@string/passwordFieldHint"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
android:minHeight="48dp" />
|
android:minHeight="48dp"
|
||||||
|
tools:ignore="VisualLintTextFieldSize" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/loginButton"
|
android:id="@+id/loginButton"
|
||||||
|
|
@ -35,5 +38,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="125dp"
|
android:layout_marginStart="125dp"
|
||||||
android:layout_marginEnd="125dp"
|
android:layout_marginEnd="125dp"
|
||||||
android:text="@string/loginButtonText" />
|
android:text="@string/loginButtonText"
|
||||||
|
tools:ignore="VisualLintButtonSize" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?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">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/notes_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/note_edit_hint" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/quiz_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/quiz_button_text" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context=".notes.NotesActivity">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/add_Button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="275dp"
|
||||||
|
android:layout_marginTop="650dp"
|
||||||
|
android:text="@string/addButtonText" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/notesList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
@ -0,0 +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="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>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">48dp</dimen>
|
||||||
|
</resources>
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">200dp</dimen>
|
||||||
|
</resources>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">48dp</dimen>
|
||||||
|
</resources>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
</resources>
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">cpsAssist</string>
|
<string name="app_name">CPSAssist</string>
|
||||||
|
<!-- Login View -->
|
||||||
<string name="usernameFieldHint">Username</string>
|
<string name="usernameFieldHint">Username</string>
|
||||||
<string name="passwordFieldHint">Password</string>
|
<string name="passwordFieldHint">Password</string>
|
||||||
<string name="loginButtonText">Login</string>
|
<string name="loginButtonText">Login</string>
|
||||||
<string name="users">josh#pass%kofi#pass%jaiwin#pass</string>
|
<string name="users">josh#pass%kofi#pass%jaiwin#pass</string>
|
||||||
|
<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>
|
||||||
|
<string name="quiz_button_text">Quiz</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources>
|
||||||
<!-- Base application theme. -->
|
<!-- Base application theme. -->
|
||||||
<style name="Theme.CpsAssist" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
<style name="Theme.CpsAssist" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||||
<!-- Primary brand color. -->
|
<!-- Primary brand color. -->
|
||||||
|
|
@ -13,4 +13,14 @@
|
||||||
<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="Theme.CpsAssist.NoActionBar">
|
||||||
|
<item name="windowActionBar">false</item>
|
||||||
|
<item name="windowNoTitle">true</item>
|
||||||
|
</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>
|
</resources>
|
||||||
Loading…
Reference in New Issue