mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-24 05:38:01 +03:00
Convert source display mode preference to flow, remove RxPreferences
This commit is contained in:
parent
194897bf3c
commit
f05b99ec1f
6 changed files with 10 additions and 39 deletions
|
@ -185,7 +185,6 @@ dependencies {
|
||||||
implementation 'io.requery:sqlite-android:3.31.0'
|
implementation 'io.requery:sqlite-android:3.31.0'
|
||||||
|
|
||||||
// Preferences
|
// Preferences
|
||||||
implementation 'com.f2prateek.rx.preferences:rx-preferences:1.0.2'
|
|
||||||
implementation 'com.github.tfcporciuncula:flow-preferences:1.1.1'
|
implementation 'com.github.tfcporciuncula:flow-preferences:1.1.1'
|
||||||
|
|
||||||
// Model View Presenter
|
// Model View Presenter
|
||||||
|
|
|
@ -4,8 +4,6 @@ import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.f2prateek.rx.preferences.Preference as RxPreference
|
|
||||||
import com.f2prateek.rx.preferences.RxSharedPreferences
|
|
||||||
import com.tfcporciuncula.flow.FlowSharedPreferences
|
import com.tfcporciuncula.flow.FlowSharedPreferences
|
||||||
import com.tfcporciuncula.flow.Preference
|
import com.tfcporciuncula.flow.Preference
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
@ -21,8 +19,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
|
||||||
fun <T> RxPreference<T>.getOrDefault(): T = get() ?: defaultValue()!!
|
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
fun <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
fun <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
||||||
block(get())
|
block(get())
|
||||||
|
@ -34,7 +30,6 @@ fun <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
||||||
class PreferencesHelper(val context: Context) {
|
class PreferencesHelper(val context: Context) {
|
||||||
|
|
||||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
private val rxPrefs = RxSharedPreferences.create(prefs)
|
|
||||||
private val flowPrefs = FlowSharedPreferences(prefs)
|
private val flowPrefs = FlowSharedPreferences(prefs)
|
||||||
|
|
||||||
private val defaultDownloadsDir = Uri.fromFile(
|
private val defaultDownloadsDir = Uri.fromFile(
|
||||||
|
@ -143,7 +138,7 @@ class PreferencesHelper(val context: Context) {
|
||||||
|
|
||||||
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)
|
fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0)
|
||||||
|
|
||||||
fun catalogueAsList() = rxPrefs.getBoolean(Keys.catalogueAsList, false)
|
fun catalogueAsList() = flowPrefs.getBoolean(Keys.catalogueAsList, false)
|
||||||
|
|
||||||
fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language))
|
fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language))
|
||||||
|
|
||||||
|
|
|
@ -435,7 +435,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||||
/**
|
/**
|
||||||
* Swaps the current display mode.
|
* Swaps the current display mode.
|
||||||
*/
|
*/
|
||||||
fun swapDisplayMode() {
|
private fun swapDisplayMode() {
|
||||||
val view = view ?: return
|
val view = view ?: return
|
||||||
val adapter = adapter ?: return
|
val adapter = adapter ?: return
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.ui.browse.source.filter.TextSectionItem
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateItem
|
import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateItem
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateSectionItem
|
import eu.kanade.tachiyomi.ui.browse.source.filter.TriStateSectionItem
|
||||||
import eu.kanade.tachiyomi.util.removeCovers
|
import eu.kanade.tachiyomi.util.removeCovers
|
||||||
|
import kotlinx.coroutines.flow.subscribe
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
|
@ -118,11 +119,7 @@ open class BrowseSourcePresenter(
|
||||||
query = savedState.getString(::query.name, "")
|
query = savedState.getString(::query.name, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
add(
|
isListMode = prefs.catalogueAsList().get()
|
||||||
prefs.catalogueAsList().asObservable()
|
|
||||||
.subscribe { setDisplayMode(it) }
|
|
||||||
)
|
|
||||||
|
|
||||||
restartPager()
|
restartPager()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,16 +191,6 @@ open class BrowseSourcePresenter(
|
||||||
return pager.hasNextPage
|
return pager.hasNextPage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the display mode.
|
|
||||||
*
|
|
||||||
* @param asList whether the current mode is in list or not.
|
|
||||||
*/
|
|
||||||
private fun setDisplayMode(asList: Boolean) {
|
|
||||||
isListMode = asList
|
|
||||||
subscribeToMangaInitializer()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribes to the initializer of manga details and updates the view if needed.
|
* Subscribes to the initializer of manga details and updates the view if needed.
|
||||||
*/
|
*/
|
||||||
|
@ -289,7 +276,10 @@ open class BrowseSourcePresenter(
|
||||||
* Changes the active display mode.
|
* Changes the active display mode.
|
||||||
*/
|
*/
|
||||||
fun swapDisplayMode() {
|
fun swapDisplayMode() {
|
||||||
prefs.catalogueAsList().set(!isListMode)
|
val mode = !isListMode
|
||||||
|
prefs.catalogueAsList().set(mode)
|
||||||
|
isListMode = mode
|
||||||
|
subscribeToMangaInitializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,13 +5,12 @@ import android.view.View
|
||||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.f2prateek.rx.preferences.Preference
|
import com.tfcporciuncula.flow.Preference
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
|
||||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||||
import kotlinx.android.synthetic.main.source_grid_item.view.card
|
import kotlinx.android.synthetic.main.source_grid_item.view.card
|
||||||
import kotlinx.android.synthetic.main.source_grid_item.view.gradient
|
import kotlinx.android.synthetic.main.source_grid_item.view.gradient
|
||||||
|
@ -20,7 +19,7 @@ class SourceItem(val manga: Manga, private val catalogueAsList: Preference<Boole
|
||||||
AbstractFlexibleItem<SourceHolder>() {
|
AbstractFlexibleItem<SourceHolder>() {
|
||||||
|
|
||||||
override fun getLayoutRes(): Int {
|
override fun getLayoutRes(): Int {
|
||||||
return if (catalogueAsList.getOrDefault()) {
|
return if (catalogueAsList.get()) {
|
||||||
R.layout.source_list_item
|
R.layout.source_list_item
|
||||||
} else {
|
} else {
|
||||||
R.layout.source_grid_item
|
R.layout.source_grid_item
|
||||||
|
|
|
@ -6,12 +6,10 @@ import android.widget.CompoundButton
|
||||||
import android.widget.Spinner
|
import android.widget.Spinner
|
||||||
import androidx.annotation.ArrayRes
|
import androidx.annotation.ArrayRes
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import com.f2prateek.rx.preferences.Preference as RxPreference
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.tfcporciuncula.flow.Preference
|
import com.tfcporciuncula.flow.Preference
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer
|
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
|
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
|
||||||
import eu.kanade.tachiyomi.util.view.invisible
|
import eu.kanade.tachiyomi.util.view.invisible
|
||||||
|
@ -129,16 +127,6 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia
|
||||||
setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) }
|
setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds a spinner to an int preference with an optional offset for the value.
|
|
||||||
*/
|
|
||||||
private fun Spinner.bindToPreference(pref: RxPreference<Int>, offset: Int = 0) {
|
|
||||||
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
|
||||||
pref.set(position + offset)
|
|
||||||
}
|
|
||||||
setSelection(pref.getOrDefault() - offset, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds a spinner to an int preference with an optional offset for the value.
|
* Binds a spinner to an int preference with an optional offset for the value.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue