Skip to content

Commit eec3b49

Browse files
committed
Implemented a notes app with features for creating, viewing, editing, and deleting notes.
0 parents  commit eec3b49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1615
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetDropDown.xml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
id("com.google.devtools.ksp")
5+
id("androidx.navigation.safeargs.kotlin")
6+
id("kotlin-parcelize")
7+
8+
9+
10+
}
11+
12+
android {
13+
namespace = "com.example.notesapp"
14+
compileSdk = 34
15+
16+
defaultConfig {
17+
applicationId = "com.example.notesapp"
18+
minSdk = 24
19+
targetSdk = 34
20+
versionCode = 1
21+
versionName = "1.0"
22+
23+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
24+
}
25+
26+
buildTypes {
27+
release {
28+
isMinifyEnabled = false
29+
proguardFiles(
30+
getDefaultProguardFile("proguard-android-optimize.txt"),
31+
"proguard-rules.pro"
32+
)
33+
}
34+
}
35+
compileOptions {
36+
sourceCompatibility = JavaVersion.VERSION_1_8
37+
targetCompatibility = JavaVersion.VERSION_1_8
38+
}
39+
kotlinOptions {
40+
jvmTarget = "1.8"
41+
}
42+
buildFeatures {
43+
viewBinding = true
44+
}
45+
}
46+
47+
dependencies {
48+
49+
implementation("androidx.core:core-ktx:1.12.0")
50+
implementation("androidx.appcompat:appcompat:1.6.1")
51+
implementation("com.google.android.material:material:1.9.0")
52+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
53+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
54+
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")
55+
56+
57+
58+
// Room
59+
implementation("androidx.room:room-runtime:2.5.2")
60+
implementation("androidx.navigation:navigation-fragment-ktx:2.7.3")
61+
implementation("androidx.navigation:navigation-ui-ktx:2.7.3")
62+
annotationProcessor("androidx.room:room-compiler:2.5.2")
63+
ksp("androidx.room:room-compiler:2.5.2")
64+
implementation("androidx.room:room-ktx:2.5.2")
65+
66+
testImplementation("junit:junit:4.13.2")
67+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
68+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
69+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.notesapp
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.notesapp", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.NotesApp"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.notesapp
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
import com.example.notesapp.databinding.ActivityMainBinding
6+
7+
class MainActivity : AppCompatActivity() {
8+
private lateinit var binding: ActivityMainBinding
9+
override fun onCreate(savedInstanceState: Bundle?) {
10+
super.onCreate(savedInstanceState)
11+
binding = ActivityMainBinding.inflate(layoutInflater)
12+
setContentView(binding.root)
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.example.notesapp.adapter
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Context
5+
import android.view.LayoutInflater
6+
import android.view.ViewGroup
7+
import androidx.navigation.findNavController
8+
import androidx.recyclerview.widget.RecyclerView
9+
import androidx.recyclerview.widget.RecyclerView.ViewHolder
10+
import com.example.notesapp.data.Note
11+
import com.example.notesapp.databinding.NoteItemBinding
12+
import com.example.notesapp.fragment.NoteListFragmentDirections
13+
14+
class NotesAdapter(val context: Context, private var noteList: List<Note>) : RecyclerView.Adapter<NotesAdapter.NotesViewHolder>() {
15+
16+
inner class NotesViewHolder(val binding: NoteItemBinding) : ViewHolder(binding.root)
17+
18+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotesViewHolder {
19+
val binding = NoteItemBinding.inflate(LayoutInflater.from(context), parent, false)
20+
return NotesViewHolder(binding)
21+
}
22+
23+
override fun onBindViewHolder(holder: NotesViewHolder, position: Int) {
24+
val note = noteList[position]
25+
val myHolder = holder.binding
26+
myHolder.noteNameTv.text = note.name
27+
myHolder.dateTv.text = note.date
28+
myHolder.root.setOnClickListener {
29+
val action = NoteListFragmentDirections.actionNoteListFragmentToDetailFragment(note)
30+
it.findNavController().navigate(action)
31+
}
32+
}
33+
34+
override fun getItemCount() = noteList.size
35+
36+
@SuppressLint("NotifyDataSetChanged")
37+
fun setData(newNotesList: List<Note>) {
38+
noteList = newNotesList
39+
notifyDataSetChanged()
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.example.notesapp.data
2+
3+
import android.os.Parcelable
4+
import androidx.room.ColumnInfo
5+
import androidx.room.Entity
6+
import androidx.room.PrimaryKey
7+
import kotlinx.parcelize.Parcelize
8+
9+
@Parcelize
10+
@Entity(tableName = "notesTable")
11+
data class Note(
12+
@PrimaryKey(autoGenerate = true) val id: Long = 0,
13+
@ColumnInfo(name = "name") val name: String,
14+
@ColumnInfo(name = "note") val note: String,
15+
@ColumnInfo(name = "date") val date: String
16+
): Parcelable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.notesapp.data
2+
3+
import androidx.lifecycle.LiveData
4+
import androidx.room.Dao
5+
import androidx.room.Delete
6+
import androidx.room.Insert
7+
import androidx.room.Query
8+
import androidx.room.Update
9+
10+
@Dao
11+
interface NoteDao {
12+
13+
@Query(value = "SELECT * FROM notesTable ORDER BY id ASC")
14+
fun readAllData(): LiveData<List<Note>>
15+
16+
@Insert
17+
suspend fun addNote(note: Note)
18+
19+
@Update
20+
suspend fun updateNote(note: Note)
21+
22+
@Delete
23+
suspend fun deleteNote(note: Note)
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.notesapp.data
2+
3+
import android.content.Context
4+
import androidx.room.Database
5+
import androidx.room.Room
6+
import androidx.room.RoomDatabase
7+
8+
@Database(entities = [Note::class], version = 1, exportSchema = false)
9+
abstract class NoteDatabase : RoomDatabase() {
10+
11+
abstract fun noteDao(): NoteDao
12+
13+
companion object {
14+
@Volatile
15+
private var INSTANCE: NoteDatabase? = null
16+
17+
fun getDatabase(context: Context): NoteDatabase {
18+
var tempInstance = INSTANCE
19+
if (tempInstance != null) {
20+
return tempInstance
21+
}
22+
23+
synchronized(this) {
24+
val instance = Room.databaseBuilder(
25+
context.applicationContext, NoteDatabase::class.java, "notes_database"
26+
).build()
27+
tempInstance = instance
28+
return instance
29+
}
30+
31+
}
32+
33+
}
34+
}

0 commit comments

Comments
 (0)