Use 1.x preference abstraction (#8020)

* Use 1.x preference abstraction

- Uses SharedPreferences compared to 1.x impl which uses DataStore but it breaks all settings screens currently
- Move PreferencesHelper to new PreferenceStore
  - PreferencesHelper should be split into smaller preference stores and be in core or domain
- Remove flow preferences as new PreferenceStore handles changes for us

Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com>

* Fix PreferenceMutableState not updating

* Fix changes not emitting on first subscription

Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com>
This commit is contained in:
Andreas
2022-09-17 17:48:24 +02:00
committed by GitHub
parent bc8c45832e
commit 0086743a53
64 changed files with 698 additions and 340 deletions
@@ -123,7 +123,7 @@ class ExtensionsPresenter(
presenterScope.launchIO { findAvailableExtensions() }
preferences.extensionUpdatesCount().asFlow()
preferences.extensionUpdatesCount().changes()
.onEach { state.updates = it }
.launchIn(presenterScope)
}
@@ -42,11 +42,11 @@ class MigrationSourcesPresenter(
}
}
preferences.migrationSortingDirection().asFlow()
preferences.migrationSortingDirection().changes()
.onEach { state.sortingDirection = it }
.launchIn(presenterScope)
preferences.migrationSortingMode().asFlow()
preferences.migrationSortingMode().changes()
.onEach { state.sortingMode = it }
.launchIn(presenterScope)
}
@@ -111,7 +111,7 @@ open class BrowseSourcePresenter(
val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
return produceState<GridCells>(initialValue = GridCells.Adaptive(128.dp), isLandscape) {
(if (isLandscape) preferences.landscapeColumns() else preferences.portraitColumns())
.asFlow()
.changes()
.collectLatest { columns ->
value = if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns)
}
@@ -257,7 +257,7 @@ open class BrowseSourcePresenter(
fun addFavorite(manga: DomainManga) {
presenterScope.launch {
val categories = getCategories()
val defaultCategoryId = preferences.defaultCategory()
val defaultCategoryId = preferences.defaultCategory().get()
val defaultCategory = categories.find { it.id == defaultCategoryId.toLong() }
when {
@@ -174,7 +174,7 @@ open class GlobalSearchController(
* @param searchResult result of search.
*/
fun setItems(searchResult: List<GlobalSearchItem>) {
if (searchResult.isEmpty() && preferences.searchPinnedSourcesOnly()) {
if (searchResult.isEmpty() && preferences.searchPinnedSourcesOnly().get()) {
binding.emptyView.show(R.string.no_pinned_sources)
} else {
binding.emptyView.hide()
@@ -123,7 +123,7 @@ open class GlobalSearchPresenter(
return filteredSources
}
val onlyPinnedSources = preferences.searchPinnedSourcesOnly()
val onlyPinnedSources = preferences.searchPinnedSourcesOnly().get()
val pinnedSourceIds = preferences.pinnedSources().get()
return enabledSources