mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 21:18:56 +01:00
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:
@@ -27,12 +27,12 @@ object ChapterSettingsHelper {
|
||||
suspend fun applySettingDefaults(mangaId: Long) {
|
||||
setMangaChapterFlags.awaitSetAllFlags(
|
||||
mangaId = mangaId,
|
||||
unreadFilter = preferences.filterChapterByRead().toLong(),
|
||||
downloadedFilter = preferences.filterChapterByDownloaded().toLong(),
|
||||
bookmarkedFilter = preferences.filterChapterByBookmarked().toLong(),
|
||||
sortingMode = preferences.sortChapterBySourceOrNumber().toLong(),
|
||||
sortingDirection = preferences.sortChapterByAscendingOrDescending().toLong(),
|
||||
displayMode = preferences.displayChapterByNameOrNumber().toLong(),
|
||||
unreadFilter = preferences.filterChapterByRead().get().toLong(),
|
||||
downloadedFilter = preferences.filterChapterByDownloaded().get().toLong(),
|
||||
bookmarkedFilter = preferences.filterChapterByBookmarked().get().toLong(),
|
||||
sortingMode = preferences.sortChapterBySourceOrNumber().get().toLong(),
|
||||
sortingDirection = preferences.sortChapterByAscendingOrDescending().get().toLong(),
|
||||
displayMode = preferences.displayChapterByNameOrNumber().get().toLong(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -45,12 +45,12 @@ object ChapterSettingsHelper {
|
||||
.map { manga ->
|
||||
setMangaChapterFlags.awaitSetAllFlags(
|
||||
mangaId = manga.id,
|
||||
unreadFilter = preferences.filterChapterByRead().toLong(),
|
||||
downloadedFilter = preferences.filterChapterByDownloaded().toLong(),
|
||||
bookmarkedFilter = preferences.filterChapterByBookmarked().toLong(),
|
||||
sortingMode = preferences.sortChapterBySourceOrNumber().toLong(),
|
||||
sortingDirection = preferences.sortChapterByAscendingOrDescending().toLong(),
|
||||
displayMode = preferences.displayChapterByNameOrNumber().toLong(),
|
||||
unreadFilter = preferences.filterChapterByRead().get().toLong(),
|
||||
downloadedFilter = preferences.filterChapterByDownloaded().get().toLong(),
|
||||
bookmarkedFilter = preferences.filterChapterByBookmarked().get().toLong(),
|
||||
sortingMode = preferences.sortChapterBySourceOrNumber().get().toLong(),
|
||||
sortingDirection = preferences.sortChapterByAscendingOrDescending().get().toLong(),
|
||||
displayMode = preferences.displayChapterByNameOrNumber().get().toLong(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,15 +106,14 @@ inline fun <P : Preference> PreferenceGroup.addThenInit(p: P, block: P.() -> Uni
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> Preference.bindTo(preference: com.fredporciuncula.flow.preferences.Preference<T>) {
|
||||
key = preference.key
|
||||
defaultValue = preference.defaultValue
|
||||
inline fun <T> Preference.bindTo(preference: eu.kanade.tachiyomi.core.preference.Preference<T>) {
|
||||
key = preference.key()
|
||||
defaultValue = preference.defaultValue()
|
||||
}
|
||||
|
||||
inline fun <T> ListPreference.bindTo(preference: com.fredporciuncula.flow.preferences.Preference<T>) {
|
||||
key = preference.key
|
||||
// ListPreferences persist values as strings, even when we're using our IntListPreference
|
||||
defaultValue = preference.defaultValue.toString()
|
||||
inline fun <T> ListPreference.bindTo(preference: eu.kanade.tachiyomi.core.preference.Preference<T>) {
|
||||
key = preference.key()
|
||||
defaultValue = preference.defaultValue().toString()
|
||||
}
|
||||
|
||||
inline fun Preference.onClick(crossinline block: () -> Unit) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package eu.kanade.tachiyomi.util.preference
|
||||
|
||||
import android.widget.CompoundButton
|
||||
import com.fredporciuncula.flow.preferences.Preference
|
||||
import eu.kanade.tachiyomi.core.preference.Preference
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
@@ -15,7 +15,7 @@ fun CompoundButton.bindToPreference(pref: Preference<Boolean>) {
|
||||
|
||||
fun <T> Preference<T>.asHotFlow(block: (T) -> Unit): Flow<T> {
|
||||
block(get())
|
||||
return asFlow()
|
||||
return changes()
|
||||
.onEach { block(it) }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user