-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
id 'kotlin-kapt' | ||
id 'dagger.hilt.android.plugin' | ||
|
||
} | ||
|
||
android { | ||
compileSdk 31 | ||
|
||
defaultConfig { | ||
applicationId "com.example.noteappcompose" | ||
minSdk 23 | ||
targetSdk 31 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
useIR = true | ||
} | ||
buildFeatures { | ||
compose true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion compose_version | ||
kotlinCompilerVersion '1.5.21' | ||
} | ||
packagingOptions { | ||
resources { | ||
excludes += '/META-INF/{AL2.0,LGPL2.1}' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.4.0' | ||
implementation 'com.google.android.material:material:1.4.0' | ||
implementation "androidx.compose.ui:ui:$compose_version" | ||
implementation "androidx.compose.material:material:$compose_version" | ||
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" | ||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0' | ||
implementation 'androidx.activity:activity-compose:1.4.0' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" | ||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" | ||
|
||
// Compose dependencies | ||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0-beta01" | ||
implementation "androidx.navigation:navigation-compose:2.4.0-alpha09" | ||
implementation "androidx.compose.material:material-icons-extended:$compose_version" | ||
implementation "androidx.hilt:hilt-navigation-compose:1.0.0-alpha03" | ||
|
||
// Coroutines | ||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' | ||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1' | ||
|
||
//Dagger - Hilt | ||
implementation "com.google.dagger:hilt-android:2.38.1" | ||
kapt "com.google.dagger:hilt-android-compiler:2.37" | ||
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03" | ||
kapt "androidx.hilt:hilt-compiler:1.0.0" | ||
|
||
// Room | ||
implementation "androidx.room:room-runtime:2.3.0" | ||
kapt "androidx.room:room-compiler:2.3.0" | ||
|
||
// Kotlin Extensions and Coroutines support for Room | ||
implementation "androidx.room:room-ktx:2.3.0" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.noteappcompose | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.example.noteappcompose", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.noteappcompose"> | ||
|
||
<application | ||
android:name=".NoteApp" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.NoteAppCompose"> | ||
<activity | ||
android:name=".feature_note.presentation.MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.NoteAppCompose.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.noteappcompose | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class NoteApp: Application() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.noteappcompose.di | ||
|
||
import android.app.Application | ||
import androidx.room.Room | ||
import com.example.noteappcompose.feature_note.data.data_source.NoteDatabase | ||
import com.example.noteappcompose.feature_note.data.data_source.NoteRepositoryImpl | ||
import com.example.noteappcompose.feature_note.domain.repository.NoteRepository | ||
import com.example.noteappcompose.feature_note.domain.use_case.* | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNoteDatabase(app: Application): NoteDatabase { | ||
return Room.databaseBuilder( | ||
app, | ||
NoteDatabase::class.java, | ||
NoteDatabase.DATABASE_NAME | ||
).build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNoteRepository (db: NoteDatabase): NoteRepository { | ||
return NoteRepositoryImpl(db.noteDao) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNoteUseCases(repository: NoteRepository): NoteUseCase { | ||
return NoteUseCase( | ||
getNotes = GetNotes(repository), | ||
deleteNote = DeleteNote(repository), | ||
addNote = AddNote(repository), | ||
getNote = GetNote(repository) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.noteappcompose.feature_note.data.data_source | ||
|
||
import androidx.room.* | ||
import com.example.noteappcompose.feature_note.domain.model.Note | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface NoteDao { | ||
|
||
@Query("SELECT * FROM note") | ||
fun getNotes(): Flow<List<Note>> | ||
|
||
@Query("SELECT * FROM note WHERE id = :id") | ||
suspend fun getNotesById(id: Int): Note? | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertNote(note: Note) | ||
|
||
@Delete | ||
suspend fun deleteNote(note: Note) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.noteappcompose.feature_note.data.data_source | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.example.noteappcompose.feature_note.domain.model.Note | ||
|
||
@Database( entities = [Note::class], version = 1) | ||
abstract class NoteDatabase: RoomDatabase() { | ||
|
||
abstract val noteDao: NoteDao | ||
|
||
companion object { | ||
const val DATABASE_NAME = "notes_db" | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.noteappcompose.feature_note.data.data_source | ||
|
||
import com.example.noteappcompose.feature_note.domain.model.Note | ||
import com.example.noteappcompose.feature_note.domain.repository.NoteRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class NoteRepositoryImpl(private val dao: NoteDao): NoteRepository { | ||
override fun getNotes(): Flow<List<Note>> { | ||
return dao.getNotes() | ||
} | ||
|
||
override suspend fun getNotesById(id: Int): Note? { | ||
return dao.getNotesById(id) | ||
} | ||
|
||
override suspend fun insertNote(note: Note) { | ||
dao.insertNote(note) | ||
} | ||
|
||
override suspend fun deleteNote(note: Note) { | ||
dao.deleteNote(note) | ||
} | ||
} |