@@ -2,8 +2,9 @@ package net.mullvad.mullvadvpn.di
2
2
3
3
import android.content.ComponentName
4
4
import android.content.Context
5
- import android.content.SharedPreferences
6
5
import android.content.pm.PackageManager
6
+ import androidx.datastore.core.DataStore
7
+ import androidx.datastore.dataStore
7
8
import kotlinx.coroutines.Dispatchers
8
9
import kotlinx.coroutines.MainScope
9
10
import net.mullvad.mullvadvpn.BuildConfig
@@ -20,14 +21,17 @@ import net.mullvad.mullvadvpn.repository.ChangelogRepository
20
21
import net.mullvad.mullvadvpn.repository.CustomListsRepository
21
22
import net.mullvad.mullvadvpn.repository.InAppNotificationController
22
23
import net.mullvad.mullvadvpn.repository.NewDeviceRepository
23
- import net.mullvad.mullvadvpn.repository.PrivacyDisclaimerRepository
24
24
import net.mullvad.mullvadvpn.repository.ProblemReportRepository
25
25
import net.mullvad.mullvadvpn.repository.RelayListFilterRepository
26
26
import net.mullvad.mullvadvpn.repository.RelayListRepository
27
27
import net.mullvad.mullvadvpn.repository.RelayOverridesRepository
28
28
import net.mullvad.mullvadvpn.repository.SettingsRepository
29
29
import net.mullvad.mullvadvpn.repository.SplashCompleteRepository
30
30
import net.mullvad.mullvadvpn.repository.SplitTunnelingRepository
31
+ import net.mullvad.mullvadvpn.repository.UserPreferences
32
+ import net.mullvad.mullvadvpn.repository.UserPreferencesMigration
33
+ import net.mullvad.mullvadvpn.repository.UserPreferencesRepository
34
+ import net.mullvad.mullvadvpn.repository.UserPreferencesSerializer
31
35
import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository
32
36
import net.mullvad.mullvadvpn.ui.MainActivity
33
37
import net.mullvad.mullvadvpn.ui.serviceconnection.AppVersionInfoRepository
@@ -99,16 +103,13 @@ import net.mullvad.mullvadvpn.viewmodel.location.SearchLocationViewModel
99
103
import net.mullvad.mullvadvpn.viewmodel.location.SelectLocationListViewModel
100
104
import net.mullvad.mullvadvpn.viewmodel.location.SelectLocationViewModel
101
105
import org.apache.commons.validator.routines.InetAddressValidator
102
- import org.koin.android.ext.koin.androidApplication
103
106
import org.koin.android.ext.koin.androidContext
104
107
import org.koin.core.module.dsl.viewModel
105
108
import org.koin.core.qualifier.named
106
109
import org.koin.dsl.module
107
110
108
111
val uiModule = module {
109
- single<SharedPreferences >(named(APP_PREFERENCES_NAME )) {
110
- androidApplication().getSharedPreferences(APP_PREFERENCES_NAME , Context .MODE_PRIVATE )
111
- }
112
+ single<DataStore <UserPreferences >> { androidContext().userPreferencesStore }
112
113
113
114
single<PackageManager > { androidContext().packageManager }
114
115
single<String >(named(SELF_PACKAGE_NAME )) { androidContext().packageName }
@@ -126,11 +127,7 @@ val uiModule = module {
126
127
single { androidContext().contentResolver }
127
128
128
129
single { ChangelogRepository (get()) }
129
- single {
130
- PrivacyDisclaimerRepository (
131
- androidContext().getSharedPreferences(APP_PREFERENCES_NAME , Context .MODE_PRIVATE )
132
- )
133
- }
130
+ single { UserPreferencesRepository (get()) }
134
131
single { SettingsRepository (get()) }
135
132
single { MullvadProblemReport (get()) }
136
133
single { RelayOverridesRepository (get()) }
@@ -272,3 +269,10 @@ val uiModule = module {
272
269
const val SELF_PACKAGE_NAME = " SELF_PACKAGE_NAME"
273
270
const val APP_PREFERENCES_NAME = " ${BuildConfig .APPLICATION_ID } .app_preferences"
274
271
const val BOOT_COMPLETED_RECEIVER_COMPONENT_NAME = " BOOT_COMPLETED_RECEIVER_COMPONENT_NAME"
272
+
273
+ private val Context .userPreferencesStore: DataStore <UserPreferences > by
274
+ dataStore(
275
+ fileName = APP_PREFERENCES_NAME ,
276
+ serializer = UserPreferencesSerializer ,
277
+ produceMigrations = UserPreferencesMigration ::migrations,
278
+ )
0 commit comments