1+ // package com.asemlab.samples.di
2+ //
3+ // import android.content.Context
4+ // import androidx.datastore.core.DataStore
5+ // import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
6+ // import androidx.datastore.preferences.SharedPreferencesMigration
7+ // import androidx.datastore.preferences.core.PreferenceDataStoreFactory
8+ // import androidx.datastore.preferences.core.Preferences
9+ // import androidx.datastore.preferences.core.emptyPreferences
10+ // import androidx.datastore.preferences.preferencesDataStoreFile
11+ // import com.asemlab.screenbrightness.utils.DataStoreUtils
12+ // import dagger.Module
13+ // import dagger.Provides
14+ // import dagger.hilt.InstallIn
15+ // import dagger.hilt.android.qualifiers.ApplicationContext
16+ // import dagger.hilt.components.SingletonComponent
17+ // import kotlinx.coroutines.CoroutineScope
18+ // import kotlinx.coroutines.Dispatchers
19+ // import kotlinx.coroutines.SupervisorJob
20+ // import javax.inject.Singleton
21+ //
22+ // @Module
23+ // @InstallIn(SingletonComponent::class)
24+ // object DataStoreModule {
25+ //
26+ // @Singleton
27+ // @Provides
28+ // fun providePreferencesDataStore(@ApplicationContext appContext: Context): DataStore<Preferences> {
29+ // return PreferenceDataStoreFactory.create(
30+ // corruptionHandler = ReplaceFileCorruptionHandler(
31+ // produceNewData = { emptyPreferences() }
32+ // ),
33+ // // TODO Migrations can be added here if you're migrating from SharedPreferences
34+ // // or changing DataStore schema
35+ // migrations = listOf(SharedPreferencesMigration(appContext, "your_shared_prefs_name")),
36+ // scope = CoroutineScope(Dispatchers.IO + SupervisorJob()), // Application-wide scope
37+ // produceFile = { appContext.preferencesDataStoreFile("user_details") }
38+ // )
39+ // }
40+ //
41+ // @Singleton
42+ // @Provides
43+ // fun provideDataStoreUtils(dataStore: DataStore<Preferences>): DataStoreUtils {
44+ // return DataStoreUtils(dataStore)
45+ // }
46+ // }
0 commit comments