commit 0c1f05086857b1b8b35f2f561c21c9d877cdf8ae Author: Bradley Bickford Date: Sun Apr 13 19:29:31 2025 -0400 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..97f0a8e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..74dd639 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..4a9fb23 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,49 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.coldlightalchemist.notesapp" + compileSdk = 35 + + defaultConfig { + applicationId = "com.coldlightalchemist.notesapp" + minSdk = 24 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} + +dependencies { + + val room_version = "2.7.0" + + implementation("androidx.room:room-runtime:$room_version") + annotationProcessor("androidx.room:room-compiler:$room_version") + + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) + +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/coldlightalchemist/notesapp/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/coldlightalchemist/notesapp/ExampleInstrumentedTest.java new file mode 100644 index 0000000..928a679 --- /dev/null +++ b/app/src/androidTest/java/com/coldlightalchemist/notesapp/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.coldlightalchemist.notesapp; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.coldlightalchemist.notesapp", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..94dabdc --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/coldlightalchemist/notesapp/MainActivity.java b/app/src/main/java/com/coldlightalchemist/notesapp/MainActivity.java new file mode 100644 index 0000000..d3b330f --- /dev/null +++ b/app/src/main/java/com/coldlightalchemist/notesapp/MainActivity.java @@ -0,0 +1,87 @@ +package com.coldlightalchemist.notesapp; + +import static android.view.View.INVISIBLE; +import static android.view.View.VISIBLE; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.coldlightalchemist.notesapp.db.NoteDB; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +public class MainActivity extends AppCompatActivity { + private NoteDB db; + + private FloatingActionButton fab; + + private RecyclerView notesRecyclerView; + + private TextView noNotesText; + + private NotesRecyclerViewAdapter noteAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + db = NoteDB.getDB(getApplicationContext()); + + notesRecyclerView = (RecyclerView) findViewById(R.id.noteRecyclerView); + notesRecyclerView.setLayoutManager(new LinearLayoutManager(this)); + + noteAdapter = new NotesRecyclerViewAdapter(db.noteDAO()); + + notesRecyclerView.setAdapter(noteAdapter); + + noNotesText = (TextView) findViewById(R.id.noNotesTextView); + + fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setOnClickListener((v) -> { + Intent newNoteIntent = new Intent(v.getContext(), NewNote.class); + startActivity(newNoteIntent); + }); + + if (db.noteDAO().getAll().isEmpty()) { + Log.d("UIVIS", "This should be what runs when the DB is empty"); + noNotesText.setVisibility(VISIBLE); + notesRecyclerView.setVisibility(View.GONE); + } else { + Log.d("UIVIS", "This should only run if there is something in the DB"); + Log.d("UIVIS", "DB Count: " + db.noteDAO().getAll().size()); + noNotesText.setVisibility(View.GONE); + notesRecyclerView.setVisibility(VISIBLE); + } + } + + @Override + protected void onResume() { + super.onResume(); + + notesRecyclerView.setAdapter(noteAdapter); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + db.close(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/coldlightalchemist/notesapp/NewNote.java b/app/src/main/java/com/coldlightalchemist/notesapp/NewNote.java new file mode 100644 index 0000000..88f54c0 --- /dev/null +++ b/app/src/main/java/com/coldlightalchemist/notesapp/NewNote.java @@ -0,0 +1,54 @@ +package com.coldlightalchemist.notesapp; + +import android.os.Bundle; +import android.widget.Button; +import android.widget.EditText; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.coldlightalchemist.notesapp.db.NoteDB; +import com.coldlightalchemist.notesapp.db.entities.Note; +import com.google.android.material.snackbar.Snackbar; + +public class NewNote extends AppCompatActivity { + + private EditText newNoteTitle; + + private EditText newNoteContent; + + private Button saveNote; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_new_note); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + newNoteTitle = (EditText) findViewById(R.id.newNoteTitle); + newNoteContent = (EditText) findViewById(R.id.newNoteContent); + + saveNote = (Button) findViewById(R.id.saveNote); + saveNote.setOnClickListener((v) -> { + if(newNoteTitle.getText().toString().isEmpty() || newNoteContent.getText().toString().isEmpty()) { + Snackbar.make(v, "You must have a title and content", Snackbar.LENGTH_LONG).show(); + return; + } + + Note note = new Note(); + note.noteTitle = newNoteTitle.getText().toString(); + note.noteContent = newNoteContent.getText().toString(); + + NoteDB.getDB(getApplicationContext()).noteDAO().insertAll(note); + finish(); + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldlightalchemist/notesapp/NotesRecyclerViewAdapter.java b/app/src/main/java/com/coldlightalchemist/notesapp/NotesRecyclerViewAdapter.java new file mode 100644 index 0000000..066adb3 --- /dev/null +++ b/app/src/main/java/com/coldlightalchemist/notesapp/NotesRecyclerViewAdapter.java @@ -0,0 +1,62 @@ +package com.coldlightalchemist.notesapp; + +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 com.coldlightalchemist.notesapp.db.NoteDB; +import com.coldlightalchemist.notesapp.db.dao.NoteDAO; +import com.coldlightalchemist.notesapp.db.entities.Note; + +public class NotesRecyclerViewAdapter extends RecyclerView.Adapter { + private final NoteDAO noteSource; + + public static class NoteRecyclerViewHolder extends RecyclerView.ViewHolder { + private final TextView rvNoteTitle; + + private Note note; + + public NoteRecyclerViewHolder(View itemView) { + super(itemView); + + rvNoteTitle = itemView.findViewById(R.id.noteTitle); + } + + public void setNote(Note note) { + this.note = note; + + rvNoteTitle.setText(note.noteTitle); + } + + public Note getNote() { + return note; + } + } + + public NotesRecyclerViewAdapter(NoteDAO noteSource) { + this.noteSource = noteSource; + } + + @NonNull + @Override + public NoteRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.note_recycler_view_item, parent, false); + + return new NoteRecyclerViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull NoteRecyclerViewHolder holder, int position) { + holder.setNote(noteSource.getAll().get(position)); + } + + @Override + public int getItemCount() { + return noteSource.getAll().size(); + } +} diff --git a/app/src/main/java/com/coldlightalchemist/notesapp/db/NoteDB.java b/app/src/main/java/com/coldlightalchemist/notesapp/db/NoteDB.java new file mode 100644 index 0000000..44892a9 --- /dev/null +++ b/app/src/main/java/com/coldlightalchemist/notesapp/db/NoteDB.java @@ -0,0 +1,27 @@ +package com.coldlightalchemist.notesapp.db; + +import android.content.Context; + +import androidx.room.Database; +import androidx.room.Room; +import androidx.room.RoomDatabase; + +import com.coldlightalchemist.notesapp.db.dao.NoteDAO; +import com.coldlightalchemist.notesapp.db.entities.Note; + +@Database(entities = {Note.class}, version = 1) +public abstract class NoteDB extends RoomDatabase { + public abstract NoteDAO noteDAO(); + + private static NoteDB db; + + public static NoteDB getDB(Context applicationContext) { + if (db == null) { + db = Room.databaseBuilder(applicationContext, NoteDB.class, "Notes") + .allowMainThreadQueries() + .build(); + } + + return db; + } +} diff --git a/app/src/main/java/com/coldlightalchemist/notesapp/db/dao/NoteDAO.java b/app/src/main/java/com/coldlightalchemist/notesapp/db/dao/NoteDAO.java new file mode 100644 index 0000000..5b48834 --- /dev/null +++ b/app/src/main/java/com/coldlightalchemist/notesapp/db/dao/NoteDAO.java @@ -0,0 +1,28 @@ +package com.coldlightalchemist.notesapp.db.dao; + +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; + +import com.coldlightalchemist.notesapp.db.entities.Note; + +import java.util.List; + +@Dao +public interface NoteDAO { + @Query("SELECT * FROM notes") + List getAll(); + + @Query("SELECT * FROM notes WHERE note_id IN (:noteIDs)") + List loadAllByIDs(int[] noteIDs); + + @Query("SELECT * FROM notes WHERE note_title = :noteTitle") + Note getNoteByTitle(String noteTitle); + + @Insert + void insertAll(Note... notes); + + @Delete + void delete(Note note); +} diff --git a/app/src/main/java/com/coldlightalchemist/notesapp/db/entities/Note.java b/app/src/main/java/com/coldlightalchemist/notesapp/db/entities/Note.java new file mode 100644 index 0000000..05aab4f --- /dev/null +++ b/app/src/main/java/com/coldlightalchemist/notesapp/db/entities/Note.java @@ -0,0 +1,18 @@ +package com.coldlightalchemist.notesapp.db.entities; + +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + +@Entity(tableName = "notes") +public class Note { + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "note_id") + public int id; + + @ColumnInfo(name = "note_title") + public String noteTitle; + + @ColumnInfo(name = "note_content") + public String noteContent; +} diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..9173deb --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_new_note.xml b/app/src/main/res/layout/activity_new_note.xml new file mode 100644 index 0000000..c70f383 --- /dev/null +++ b/app/src/main/res/layout/activity_new_note.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + +