Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dannyk-kago committed Jan 9, 2022
0 parents commit 22973f6
Show file tree
Hide file tree
Showing 70 changed files with 2,074 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
91 changes: 91 additions & 0 deletions app/build.gradle
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"
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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)
}
}
26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
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>
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/noteappcompose/NoteApp.kt
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()
45 changes: 45 additions & 0 deletions app/src/main/java/com/example/noteappcompose/di/AppModule.kt
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)
}
}
Loading

0 comments on commit 22973f6

Please sign in to comment.