Skip to content

Commit a77fbcd

Browse files
committed
Update Dependencies
Signed-off-by: Sanju S <[email protected]>
1 parent d77bbf1 commit a77fbcd

File tree

10 files changed

+52
-49
lines changed

10 files changed

+52
-49
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/build.gradle

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ dependencies {
8282
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
8383
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
8484
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
85-
testImplementation 'junit:junit:4.13.1'
85+
testImplementation 'junit:junit:4.13.2'
8686
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
8787
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
8888

8989
// Architectural Components
90-
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
90+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
9191

9292
// Room
9393
implementation "androidx.room:room-runtime:2.2.6"
@@ -102,25 +102,25 @@ dependencies {
102102
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.4.1'
103103

104104
// Coroutine Lifecycle Scopes
105-
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
106-
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
107-
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
105+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
106+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
107+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
108108

109109

110110
// Navigation Components
111-
implementation "androidx.navigation:navigation-fragment-ktx:2.3.2"
112-
implementation "androidx.navigation:navigation-ui-ktx:2.3.2"
111+
implementation "androidx.navigation:navigation-fragment-ktx:2.3.4"
112+
implementation "androidx.navigation:navigation-ui-ktx:2.3.4"
113113

114114
// material design
115-
implementation 'com.google.android.material:material:1.2.1'
116-
implementation "androidx.recyclerview:recyclerview:1.1.0"
115+
implementation 'com.google.android.material:material:1.3.0'
116+
implementation "androidx.recyclerview:recyclerview:1.2.0"
117117

118118
// Preference DataStore
119-
implementation "androidx.datastore:datastore-preferences:1.0.0-alpha05"
119+
implementation "androidx.datastore:datastore-preferences:1.0.0-alpha06"
120120

121121
// Hilt
122122
implementation "com.google.dagger:hilt-android:2.30.1-alpha"
123123
kapt "com.google.dagger:hilt-android-compiler:2.30.1-alpha"
124-
annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0-alpha02'
124+
annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0-beta01'
125125

126126
}

app/src/main/java/thecodemonks/org/nottzapp/datastore/UIModePreference.kt

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,46 @@ package thecodemonks.org.nottzapp.datastore
3232
import android.content.Context
3333
import androidx.datastore.core.DataStore
3434
import androidx.datastore.preferences.core.Preferences
35+
import androidx.datastore.preferences.core.booleanPreferencesKey
3536
import androidx.datastore.preferences.core.edit
36-
import androidx.datastore.preferences.core.preferencesKey
3737
import androidx.datastore.preferences.createDataStore
3838
import kotlinx.coroutines.flow.Flow
3939
import kotlinx.coroutines.flow.map
40+
import javax.inject.Singleton
4041

41-
class UIModePreference(context: Context) {
42-
private val dataStore: DataStore<Preferences> = context.createDataStore(
43-
name = "ui_mode_preference"
44-
)
42+
abstract class PrefsDataStore(context: Context, fileName: String) {
43+
internal val dataStore: DataStore<Preferences> = context.createDataStore(fileName)
44+
}
4545

46-
suspend fun saveToDataStore(isNightMode: Boolean) {
47-
dataStore.edit { preferences ->
48-
preferences[UI_MODE_KEY] = isNightMode
49-
}
50-
}
46+
class UIModeDataStore(context: Context) :
47+
PrefsDataStore(
48+
context,
49+
PREF_FILE_UI_MODE
50+
),
51+
UIModeImpl {
5152

52-
val uiMode: Flow<Boolean> = dataStore.data
53-
.map { preferences ->
53+
// used to get the data from datastore
54+
override val uiMode: Flow<Boolean>
55+
get() = dataStore.data.map { preferences ->
5456
val uiMode = preferences[UI_MODE_KEY] ?: false
5557
uiMode
5658
}
5759

60+
// used to save the ui preference to datastore
61+
override suspend fun saveToDataStore(isNightMode: Boolean) {
62+
dataStore.edit { preferences ->
63+
preferences[UI_MODE_KEY] = isNightMode
64+
}
65+
}
66+
5867
companion object {
59-
private val UI_MODE_KEY = preferencesKey<Boolean>("ui_mode")
68+
private const val PREF_FILE_UI_MODE = "ui_mode_preference"
69+
private val UI_MODE_KEY = booleanPreferencesKey("ui_mode")
6070
}
6171
}
72+
73+
@Singleton
74+
interface UIModeImpl {
75+
val uiMode: Flow<Boolean>
76+
suspend fun saveToDataStore(isNightMode: Boolean)
77+
}

app/src/main/java/thecodemonks/org/nottzapp/di/AppModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import dagger.Module
3434
import dagger.Provides
3535
import dagger.hilt.InstallIn
3636
import dagger.hilt.android.components.ActivityComponent
37-
import thecodemonks.org.nottzapp.datastore.UIModePreference
37+
import thecodemonks.org.nottzapp.datastore.UIModeDataStore
3838
import thecodemonks.org.nottzapp.db.NotesDatabase
3939
import javax.inject.Singleton
4040

@@ -44,8 +44,8 @@ class AppModule {
4444

4545
@Singleton
4646
@Provides
47-
fun providePreferenceManager(application: Application): UIModePreference {
48-
return UIModePreference(application.applicationContext)
47+
fun providePreferenceManager(application: Application): UIModeDataStore {
48+
return UIModeDataStore(application.applicationContext)
4949
}
5050

5151
@Singleton

app/src/main/java/thecodemonks/org/nottzapp/ui/notes/NotesViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import kotlinx.coroutines.flow.asStateFlow
3838
import kotlinx.coroutines.flow.collect
3939
import kotlinx.coroutines.flow.distinctUntilChanged
4040
import kotlinx.coroutines.launch
41-
import thecodemonks.org.nottzapp.datastore.UIModePreference
41+
import thecodemonks.org.nottzapp.datastore.UIModeDataStore
4242
import thecodemonks.org.nottzapp.model.Notes
4343
import thecodemonks.org.nottzapp.repo.NotesRepo
4444
import thecodemonks.org.nottzapp.utils.NotesViewState
@@ -57,7 +57,7 @@ class NotesViewModel @Inject internal constructor(
5757
val uiState = _uiState.asStateFlow()
5858

5959
// DataStore
60-
private val uiDataStore = UIModePreference(application)
60+
private val uiDataStore = UIModeDataStore(application)
6161

6262
// get UI mode
6363
val getUIMode = uiDataStore.uiMode

app/src/main/res/navigation/nav_graph.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<fragment
8686
android:id="@+id/aboutFragment"
8787
android:name="thecodemonks.org.nottzapp.ui.about.AboutFragment"
88-
android:label="fragment_about"
88+
android:label="@string/menu_about"
8989
tools:layout="@layout/fragment_about" />
9090

9191
</navigation>

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929

3030
// Top-level build file where you can add configuration options common to all sub-projects/modules.
3131
buildscript {
32-
ext.kotlin_version = "1.4.21"
32+
ext.kotlin_version = "1.4.32"
3333
repositories {
3434
google()
3535
jcenter()
3636
}
3737
dependencies {
38-
classpath 'com.android.tools.build:gradle:4.1.2'
38+
classpath 'com.android.tools.build:gradle:4.1.3'
3939
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
40-
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.2"
40+
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.4"
4141
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.30.1-alpha'
4242

4343

0 commit comments

Comments
 (0)