Created Notes Activity and Defined recycler

This commit is contained in:
r0r-5chach 2023-03-18 21:19:23 +00:00
parent a3aa30c6d7
commit d49918d8c4
16 changed files with 164 additions and 12 deletions

View File

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

View File

@ -26,6 +26,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
@ -33,6 +36,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
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'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

View File

@ -11,6 +11,11 @@
android:supportsRtl="true"
android:theme="@style/Theme.CpsAssist"
tools:targetApi="31">
<activity
android:name=".notes.NotesActivity"
android:exported="false"
android:label="@string/title_activity_notes"
android:theme="@style/Theme.CpsAssist.NoActionBar" />
<activity
android:name=".login.LoginActivity"
android:exported="true">

View File

@ -1,4 +0,0 @@
package xyz.r0r5chach.cpsAssist.home;
public class HomeActivity {
}

View File

@ -1,6 +1,5 @@
package xyz.r0r5chach.cpsAssist.login;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;
@ -8,11 +7,12 @@ 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
*/
public class OnClickListener implements View.OnClickListener{
public class BtnOnClickListener implements View.OnClickListener{
/**
* This attribute stores the amount of attempts the user has currently taken
*/
@ -34,7 +34,7 @@ public class OnClickListener implements View.OnClickListener{
* @param usernameField the View for the username 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);
this.currentAttempts = 0;
this.usernameField = usernameField;
@ -56,7 +56,7 @@ public class OnClickListener implements View.OnClickListener{
Intent home = new Intent(view.getContext(), NotesActivity.class);
home.putExtra("username", inputs[0]);
view.getContext().startActivity(home);
((Activity)view.getContext()).finish();
((android.app.Activity)view.getContext()).finish();
}
else {
currentAttempts += 1;

View File

@ -12,6 +12,6 @@ public class LoginActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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)));
}
}

View File

@ -0,0 +1,55 @@
package xyz.r0r5chach.cpsAssist.notes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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;
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
private final List<File> notes;
public Adapter(List<File> notes) {
this.notes = notes;
}
@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);
}
@Override
public void onBindViewHolder(ViewHolder holder, int index) {
File note = notes.get(index);
holder.getFileName().setText(note.getName());
}
@Override
public int getItemCount() {
return 0;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView fileName;
public ViewHolder(View v) {
super(v);
fileName = v.findViewById(R.id.fileNameField);
}
public TextView getFileName() {
return fileName;
}
}
}

View File

@ -0,0 +1,36 @@
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 java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import xyz.r0r5chach.cpsAssist.R;
public class NotesActivity extends AppCompatActivity {
private List<File> notes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notes);
notes = getStoredNotes();
initRecycler();
}
private void initRecycler() {
RecyclerView list =findViewById(R.id.notesList);
list.setAdapter(new Adapter(notes));
list.setLayoutManager(new LinearLayoutManager(this));
}
private List<File> getStoredNotes() {
return Arrays.asList(Objects.requireNonNull(getFilesDir().listFiles()));
}
}

View File

@ -0,0 +1,23 @@
<?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/addButton"
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>

View File

@ -0,0 +1,10 @@
<?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">
<TextView
android:id="@+id/fileNameField"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">48dp</dimen>
</resources>

View File

@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">200dp</dimen>
</resources>

View File

@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">48dp</dimen>
</resources>

View File

@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@ -1,7 +1,11 @@
<resources>
<string name="app_name">cpsAssist</string>
<string name="app_name">CPSAssist</string>
<!-- Login View -->
<string name="usernameFieldHint">Username</string>
<string name="passwordFieldHint">Password</string>
<string name="loginButtonText">Login</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>
</resources>

View File

@ -1,4 +1,4 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.CpsAssist" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
@ -13,4 +13,10 @@
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</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" />
</resources>