mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 22:17:03 +05:30
refactor: move datastore module to common
This commit is contained in:
parent
d31da62cfe
commit
93b593bd41
3 changed files with 2 additions and 2 deletions
|
@ -25,7 +25,6 @@ dependencies {
|
|||
api(libs.napier)
|
||||
api(libs.okhttp.core)
|
||||
api(libs.retrofit)
|
||||
api(libs.androidx.datastore)
|
||||
|
||||
implementation(platform(libs.okhttp.bom))
|
||||
implementation(libs.kotlinx.serialization.core)
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright © Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.core.persistence
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.core.DataMigration
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.core.DataStoreFactory
|
||||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.PreferencesFileSerializer
|
||||
import androidx.datastore.preferences.core.emptyPreferences
|
||||
import androidx.datastore.preferences.preferencesDataStoreFile
|
||||
import com.deliveryhero.whetstone.app.ApplicationScope
|
||||
import com.squareup.anvil.annotations.ContributesTo
|
||||
import com.squareup.anvil.annotations.optional.ForScope
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoSet
|
||||
import io.github.aakira.napier.Napier
|
||||
|
||||
@Module
|
||||
@ContributesTo(ApplicationScope::class)
|
||||
object PreferencesStoreModule {
|
||||
@Provides
|
||||
fun providePreferencesDataStore(
|
||||
@ForScope(ApplicationScope::class) context: Context,
|
||||
migrations: Set<@JvmSuppressWildcards DataMigration<@JvmSuppressWildcards Preferences>>,
|
||||
): DataStore<@JvmSuppressWildcards Preferences> {
|
||||
return DataStoreFactory.create(
|
||||
corruptionHandler =
|
||||
ReplaceFileCorruptionHandler {
|
||||
Napier.d(throwable = it) {
|
||||
"Preferences data store corruption detected, returning empty preferences."
|
||||
}
|
||||
emptyPreferences()
|
||||
},
|
||||
migrations = migrations.toList(),
|
||||
produceFile = { context.preferencesDataStoreFile("claw_preferences") },
|
||||
serializer = PreferencesFileSerializer,
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@IntoSet
|
||||
fun firstMigration(): DataMigration<Preferences> =
|
||||
object : DataMigration<Preferences> {
|
||||
override suspend fun shouldMigrate(currentData: Preferences): Boolean = false
|
||||
|
||||
override suspend fun migrate(currentData: Preferences): Preferences = currentData
|
||||
|
||||
override suspend fun cleanUp() {}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue