Skip to content

Commit

Permalink
migrate remaining prefs to DataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambada10 committed Jul 15, 2024
1 parent 2ca6db8 commit 45e3afc
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions app/src/main/java/pl/lambada/songsync/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat.getString
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.documentfile.provider.DocumentFile
import androidx.navigation.NavHostController
import coil.compose.rememberAsyncImagePainter
Expand All @@ -139,9 +143,11 @@ import pl.lambada.songsync.ui.ScreenSearch
import pl.lambada.songsync.util.ext.BackPressHandler
import pl.lambada.songsync.ui.components.AnimatedText
import pl.lambada.songsync.ui.components.SwitchItem
import pl.lambada.songsync.util.dataStore
import pl.lambada.songsync.util.ext.getVersion
import pl.lambada.songsync.util.ext.lowercaseWithLocale
import pl.lambada.songsync.util.ext.toLrcFile
import pl.lambada.songsync.util.set
import java.io.FileNotFoundException
import kotlin.math.roundToInt

Expand Down Expand Up @@ -335,10 +341,7 @@ fun HomeScreen(
val selectedProvider = rememberSaveable { mutableStateOf(viewModel.provider) }
val providers = Providers.entries.toTypedArray()
val context = LocalContext.current
val sharedPreferences = context.getSharedPreferences(
"pl.lambada.songsync_preferences",
Context.MODE_PRIVATE
)
val dataStore = context.dataStore
DropdownMenu(
expanded = expandedProviders,
onDismissRequest = { expandedProviders = false }
Expand All @@ -363,9 +366,10 @@ fun HomeScreen(
onClick = {
selectedProvider.value = it
viewModel.provider = it
sharedPreferences.edit()
.putString("provider", it.displayName)
.apply()
dataStore.set(
stringPreferencesKey("provider"),
it.displayName
)
expandedProviders = false
}
)
Expand All @@ -374,9 +378,10 @@ fun HomeScreen(
onClick = {
selectedProvider.value = it
viewModel.provider = it
sharedPreferences.edit()
.putString("provider", it.displayName)
.apply()
dataStore.set(
stringPreferencesKey("provider"),
it.displayName
)
expandedProviders = false
}
)
Expand Down Expand Up @@ -683,9 +688,7 @@ fun FiltersDialog(
val folders = viewModel.getSongFolders(context)
var showFolders by rememberSaveable { mutableStateOf(false) }

val sharedPreferences = LocalContext.current.getSharedPreferences(
"pl.lambada.songsync_preferences", Context.MODE_PRIVATE
)
val dataStore = context.dataStore

BasicAlertDialog(onDismissRequest = { onDismiss() }) {
Surface(
Expand Down Expand Up @@ -715,10 +718,10 @@ fun FiltersDialog(
)
) {
viewModel.hideLyrics = !hideLyrics
sharedPreferences
.edit()
.putBoolean("hide_lyrics", !hideLyrics)
.apply()
dataStore.set(
booleanPreferencesKey("hide_lyrics"),
!hideLyrics
)
hideLyrics = !hideLyrics
onFilterChange()
}
Expand Down Expand Up @@ -786,13 +789,10 @@ fun FiltersDialog(
} else {
viewModel.blacklistedFolders.remove(folder)
}
sharedPreferences
.edit()
.putString(
"blacklist",
viewModel.blacklistedFolders.joinToString(",")
)
.apply()
dataStore.set(
stringPreferencesKey("blacklist"),
viewModel.blacklistedFolders.joinToString(",")
)
onFilterChange()
}
.padding(start = 22.dp, end = 16.dp),
Expand All @@ -815,10 +815,10 @@ fun FiltersDialog(
} else {
viewModel.blacklistedFolders.remove(folder)
}
sharedPreferences.edit().putString(
"blacklist",
dataStore.set(
stringPreferencesKey("blacklist"),
viewModel.blacklistedFolders.joinToString(",")
).apply()
)
onFilterChange()
}
)
Expand Down

0 comments on commit 45e3afc

Please sign in to comment.