Skip to content

Commit 9e4f5ce

Browse files
committed
MVP
1 parent 2b81827 commit 9e4f5ce

34 files changed

Lines changed: 382 additions & 37 deletions

File tree

app/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ dependencies {
7878
implementation(libs.lifecycle.runtime.ktx)
7979
implementation(libs.hilt)
8080
implementation(libs.navigation.compose)
81-
implementation(libs.firebase.auth)
81+
implementation(libs.firebase.bom)
82+
implementation(libs.firebase.auth.ktx)
83+
implementation(libs.firebase.database.ktx)
8284
implementation(libs.play.services.auth)
8385
implementation(libs.facebook)
8486
implementation(libs.kotlin.serialization)

app/src/main/java/com/viplearner/notes/VIPNotesApp.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package com.viplearner.notes
22

33
import android.app.Application
4+
import com.google.firebase.database.ktx.database
5+
import com.google.firebase.ktx.Firebase
46
import dagger.hilt.android.HiltAndroidApp
57
import timber.log.Timber
68

79
@HiltAndroidApp
810
class VIPNotesApp : Application(){
911
override fun onCreate() {
1012

11-
Timber.plant(Timber.DebugTree())
13+
if(BuildConfig.DEBUG) {
14+
Timber.plant(Timber.DebugTree())
15+
}
16+
Firebase.database.setPersistenceEnabled(true)
1217

1318
super.onCreate()
1419
}

common/data/local/src/androidTest/java/com/viplearner/common/data/local/NotesDaoTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.viplearner.common.data.local
22

3-
import android.util.Log
43
import androidx.room.Room
54
import androidx.test.core.app.ApplicationProvider
65
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -47,7 +46,7 @@ class NoteDaoTest {
4746
)
4847
noteDao.upsert(note)
4948

50-
val noteList = noteDao.getAll().first()
49+
val noteList = noteDao.getAllFlow().first()
5150
assert(noteList.contains(note))
5251
}
5352
}
@@ -96,7 +95,7 @@ class NoteDaoTest {
9695
noteDao.upsert(note)
9796
noteDao.delete(note.uuid)
9897

99-
val favouriteList = noteDao.getAll().first()
98+
val favouriteList = noteDao.getAllFlow().first()
10099
assert(favouriteList.contains(note).not())
101100
}
102101
}

common/data/local/src/main/java/com/viplearner/common/data/local/dao/NotesDao.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import kotlinx.coroutines.flow.Flow
1010
interface NotesDao {
1111
@Query("SELECT * from Notes" +
1212
" ORDER BY timeLastEdited DESC")
13-
fun getAll(): Flow<List<Note>>
13+
fun getAllFlow(): Flow<List<Note>>
14+
15+
@Query("SELECT * from Notes" +
16+
" ORDER BY timeLastEdited DESC")
17+
fun getAll(): List<Note>
1418

1519
@Query("SELECT * " +
1620
"FROM Notes " +
@@ -25,6 +29,9 @@ interface NotesDao {
2529
"WHERE uuid=:uuid")
2630
fun getNoteUsingUUID(uuid: String): Note
2731

32+
@Query("SELECT EXISTS(SELECT * FROM Notes WHERE :uuid = uuid)")
33+
fun noteExists(uuid: String): Boolean
34+
2835
@Upsert
2936
fun upsert(note: Note)
3037

common/data/local/src/main/java/com/viplearner/common/data/local/database/NotesDatabase.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import com.viplearner.common.data.local.dto.Note
88

99
@Database(
1010
entities = [Note::class],
11-
version = 2,
11+
version = 3,
1212
exportSchema = true,
1313
autoMigrations = [
14-
AutoMigration(from = 1, to = 2)
14+
AutoMigration(from = 1, to = 2),
15+
AutoMigration(from = 2, to = 3)
1516
]
1617
)
1718
abstract class NotesDatabase : RoomDatabase() {

common/data/local/src/main/java/com/viplearner/common/data/local/dto/Note.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ data class Note(
1111
@ColumnInfo(name = "title") val title: String,
1212
@ColumnInfo(name = "content") val content: String,
1313
@ColumnInfo(name = "timeLastEdited") val timeLastEdited: Long,
14-
@ColumnInfo(name = "isPinned", defaultValue = "0") var isPinned: Boolean
14+
@ColumnInfo(name = "isPinned", defaultValue = "0") var isPinned: Boolean,
15+
@ColumnInfo(name = "isDeleted", defaultValue = "false") var isDeleted: Boolean = false
1516
)

common/data/local/src/main/java/com/viplearner/common/data/local/mapper/ListItemToEntity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ fun Note.toNoteEntity(): NoteEntity =
99
title = title,
1010
content = content,
1111
timeLastEdited = timeLastEdited,
12-
isPinned = isPinned
12+
isPinned = isPinned,
13+
isDeleted = isDeleted
1314
)

common/data/remote/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ android {
3939
dependencies {
4040
implementation(project(":common:domain"))
4141
implementation(libs.activity)
42-
implementation(libs.firebase.auth)
4342
implementation(libs.jakewharton.timber)
4443
implementation(libs.play.services.auth)
4544
implementation(libs.core.ktx)
45+
implementation(libs.firebase.bom)
4646
implementation(libs.bundles.ktor)
4747
implementation(libs.kotlin.serialization)
4848
implementation(libs.hilt)
4949
implementation(libs.junit4)
50+
implementation(libs.firebase.database.ktx)
51+
implementation(libs.firebase.auth.ktx)
5052
kapt(libs.hilt.compiler)
5153
}

common/data/remote/src/main/java/com/viplearner/common/data/remote/auth_repository/AuthRepositoryImpl.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.google.firebase.auth.ktx.auth
44
import com.google.firebase.ktx.Firebase
55
import com.viplearner.common.domain.auth_repository.AuthRepository
66
import com.viplearner.common.domain.entity.UserData
7-
import kotlinx.coroutines.ExperimentalCoroutinesApi
87
import kotlinx.coroutines.tasks.await
98
import timber.log.Timber
109

@@ -34,7 +33,6 @@ class AuthRepositoryImpl: AuthRepository {
3433

3534
}
3635

37-
@OptIn(ExperimentalCoroutinesApi::class)
3836
override suspend fun signUp(email: String, password: String): UserData {
3937
try{
4038
Timber.d("AuthRepository signUp: $email $password")

common/data/remote/src/main/java/com/viplearner/common/data/remote/auth_repository/di/AuthRepositoryModule.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import javax.inject.Singleton
1111
@InstallIn(SingletonComponent::class)
1212
@Module
1313
object AuthRepositoryModule {
14-
15-
1614
@Provides
1715
@Singleton
1816
fun provideAuthRepository(): AuthRepository = AuthRepositoryImpl()

0 commit comments

Comments
 (0)