From 5d2a0feb5fa42f4dd322481224f50d2f79119067 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 16 Apr 2021 15:03:24 -0400 Subject: [PATCH] Open Library display options in main library settings Also converting more rxprefs to flow prefs --- .../data/preference/PreferencesHelper.kt | 10 ++-- .../tachiyomi/ui/library/LibraryController.kt | 57 ++++++++++++------- .../tachiyomi/ui/library/LibraryItem.kt | 4 +- .../tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../ui/library/display/LibraryBadgesView.kt | 8 +-- .../ui/library/display/LibraryCategoryView.kt | 14 ++--- .../ui/library/display/LibraryDisplayView.kt | 12 +--- .../display/TabbedLibraryDisplaySheet.kt | 31 ++++++---- .../ui/setting/SettingsLibraryController.kt | 13 +++++ .../source/browse/BrowseSourceController.kt | 3 +- .../ui/source/browse/BrowseSourceItem.kt | 9 ++- .../ui/source/browse/BrowseSourcePresenter.kt | 20 +++++-- .../tachiyomi/util/PreferenceExtensions.kt | 12 ++++ .../tachiyomi/widget/BaseTabbedScrollView.kt | 5 +- app/src/main/res/values/strings.xml | 1 + 15 files changed, 129 insertions(+), 72 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 2152c35818..ff18bb112f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -192,7 +192,7 @@ class PreferencesHelper(val context: Context) { fun lastVersionCode() = rxPrefs.getInteger("last_version_code", 0) - fun browseAsList() = rxPrefs.getBoolean(Keys.catalogueAsList, false) + fun browseAsList() = flowPrefs.getBoolean(Keys.catalogueAsList, false) fun enabledLanguages() = flowPrefs.getStringSet(Keys.enabledLanguages, setOf("en", Locale.getDefault().language)) @@ -240,11 +240,11 @@ class PreferencesHelper(val context: Context) { fun libraryUpdatePrioritization() = rxPrefs.getInteger(Keys.libraryUpdatePrioritization, 0) - fun libraryLayout() = rxPrefs.getInteger(Keys.libraryLayout, 2) + fun libraryLayout() = flowPrefs.getInt(Keys.libraryLayout, 2) - fun gridSize() = rxPrefs.getInteger(Keys.gridSize, 2) + fun gridSize() = flowPrefs.getInt(Keys.gridSize, 2) - fun uniformGrid() = rxPrefs.getBoolean(Keys.uniformGrid, true) + fun uniformGrid() = flowPrefs.getBoolean(Keys.uniformGrid, true) fun chaptersDescAsDefault() = rxPrefs.getBoolean("chapters_desc_as_default", true) @@ -329,7 +329,7 @@ class PreferencesHelper(val context: Context) { fun lastAppCheck() = flowPrefs.getLong("last_app_check", 0) - fun unreadBadgeType() = rxPrefs.getInteger("unread_badge_type", 2) + fun unreadBadgeType() = flowPrefs.getInt("unread_badge_type", 2) fun hideStartReadingButton() = rxPrefs.getBoolean("hide_reading_button", false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 5fcb9fe22e..bb4e374b39 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -104,6 +104,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.cancel import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import kotlin.math.abs @@ -143,7 +146,7 @@ class LibraryController( */ private var actionMode: ActionMode? = null - private var libraryLayout: Int = preferences.libraryLayout().getOrDefault() + private var libraryLayout: Int = preferences.libraryLayout().get() var singleCategory: Boolean = false private set @@ -469,6 +472,7 @@ class LibraryController( } setupFilterSheet() setUpHopper() + setPreferenceFlows() elevateAppBar = scrollViewWith( @@ -497,8 +501,24 @@ class LibraryController( updateHopperY() } } - binding.swipeRefresh.setOnRefreshListener { - binding.swipeRefresh.isRefreshing = false + setSwipeRefresh() + + if (selectedMangas.isNotEmpty()) { + createActionModeIfNeeded() + } + + presenter.onRestore() + if (presenter.libraryItems.isNotEmpty()) { + presenter.restoreLibrary() + } else { + binding.recyclerLayout.alpha = 0f + presenter.getLibrary() + } + } + + private fun setSwipeRefresh() = with(binding.swipeRefresh) { + setOnRefreshListener { + isRefreshing = false if (!LibraryUpdateService.isRunning()) { when { !presenter.showAllCategories && presenter.groupType == BY_DEFAULT -> { @@ -514,11 +534,11 @@ class LibraryController( .negativeButton(android.R.string.cancel) .listItemsSingleChoice( items = listOf( - view.context.getString( + context.getString( R.string.top_category, presenter.allCategories.first().name ), - view.context.getString( + context.getString( R.string.categories_in_global_update ) ), @@ -540,18 +560,6 @@ class LibraryController( } } } - - if (selectedMangas.isNotEmpty()) { - createActionModeIfNeeded() - } - - presenter.onRestore() - if (presenter.libraryItems.isNotEmpty()) { - presenter.restoreLibrary() - } else { - binding.recyclerLayout.alpha = 0f - presenter.getLibrary() - } } private fun setupFilterSheet() { @@ -786,7 +794,7 @@ class LibraryController( end = 0 ) } else { - binding.libraryGridRecycler.recycler.columnWidth = when (preferences.gridSize().getOrDefault()) { + binding.libraryGridRecycler.recycler.columnWidth = when (preferences.gridSize().get()) { 1 -> 1f 2 -> 1.25f 3 -> 1.66f @@ -800,6 +808,17 @@ class LibraryController( } } + private fun setPreferenceFlows() { + listOf(preferences.libraryLayout(), preferences.uniformGrid(), preferences.gridSize(), preferences.unreadBadgeType()).forEach { + it.asFlow() + .drop(1) + .onEach { + reattachAdapter() + } + .launchIn(scope) + } + } + override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { @@ -1049,7 +1068,7 @@ class LibraryController( } fun reattachAdapter() { - libraryLayout = preferences.libraryLayout().getOrDefault() + libraryLayout = preferences.libraryLayout().get() setRecyclerLayout() val position = (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 9f388b48bd..bbf5bf4922 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -37,10 +37,10 @@ class LibraryItem( var unreadType = 2 private val uniformSize: Boolean - get() = preferences.uniformGrid().getOrDefault() + get() = preferences.uniformGrid().get() private val libraryLayout: Int - get() = preferences.libraryLayout().getOrDefault() + get() = preferences.libraryLayout().get() val hideReadingButton: Boolean get() = preferences.hideStartReadingButton().getOrDefault() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 4d712ac348..54b25f2783 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -325,7 +325,7 @@ class LibraryPresenter( } private fun setUnreadBadge(itemList: List) { - val unreadType = preferences.unreadBadgeType().getOrDefault() + val unreadType = preferences.unreadBadgeType().get() for (item in itemList) { item.unreadType = unreadType } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt index 058dbd8d7e..8c6cc5ccf1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryBadgesView.kt @@ -12,13 +12,11 @@ class LibraryBadgesView @JvmOverloads constructor(context: Context, attrs: Attri override fun inflateBinding() = LibraryBadgesLayoutBinding.bind(this) override fun initGeneralPreferences() { binding.unreadBadgeGroup.bindToPreference(preferences.unreadBadgeType()) { - controller.presenter.requestUnreadBadgesUpdate() - } - binding.hideReading.bindToPreference(preferences.hideStartReadingButton()) { - controller.reattachAdapter() + controller?.presenter?.requestUnreadBadgesUpdate() } + binding.hideReading.bindToPreference(preferences.hideStartReadingButton()) binding.downloadBadge.bindToPreference(preferences.downloadBadge()) { - controller.presenter.requestDownloadBadgesUpdate() + controller?.presenter?.requestDownloadBadgesUpdate() } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt index 5949e563ab..c26544c690 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryCategoryView.kt @@ -26,12 +26,12 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att override fun initGeneralPreferences() { with(binding) { showAll.bindToPreference(preferences.showAllCategories()) { - controller.presenter.getLibrary() + controller?.presenter?.getLibrary() binding.categoryShow.isEnabled = it } categoryShow.isEnabled = showAll.isChecked categoryShow.bindToPreference(preferences.showCategoryInTitle()) { - controller.showMiniBar() + controller?.showMiniBar() } val hideHopper = min( 2, @@ -42,15 +42,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att hideHopperSpinner.onItemSelectedListener = { preferences.hideHopper().set(it == 2) preferences.autohideHopper().set(it == 1) - controller.hideHopper(it == 2) - controller.resetHopperY() + controller?.hideHopper(it == 2) + controller?.resetHopperY() } addCategoriesButton.setOnClickListener { - controller.showCategoriesController() + controller?.showCategoriesController() } expandCollapseCategories.setOnClickListener { - controller.binding.filterBottomSheet.root - .onGroupClicked(FilterBottomSheet.ACTION_EXPAND_COLLAPSE_ALL) + controller?.binding?.filterBottomSheet?.root + ?.onGroupClicked?.invoke(FilterBottomSheet.ACTION_EXPAND_COLLAPSE_ALL) } hopperLongPress.bindToPreference(preferences.hopperLongPressAction()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt index f2dfd6650b..6dea5d8242 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/LibraryDisplayView.kt @@ -11,14 +11,8 @@ class LibraryDisplayView @JvmOverloads constructor(context: Context, attrs: Attr override fun inflateBinding() = LibraryDisplayLayoutBinding.bind(this) override fun initGeneralPreferences() { - binding.displayGroup.bindToPreference(preferences.libraryLayout()) { - controller.reattachAdapter() - } - binding.uniformGrid.bindToPreference(preferences.uniformGrid()) { - controller.reattachAdapter() - } - binding.gridSizeToggleGroup.bindToPreference(preferences.gridSize()) { - controller.reattachAdapter() - } + binding.displayGroup.bindToPreference(preferences.libraryLayout()) + binding.uniformGrid.bindToPreference(preferences.uniformGrid()) + binding.gridSizeToggleGroup.bindToPreference(preferences.gridSize()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt index 295e602267..e40426b101 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/display/TabbedLibraryDisplaySheet.kt @@ -3,6 +3,8 @@ package eu.kanade.tachiyomi.ui.library.display import android.view.View import android.view.View.inflate import androidx.core.content.ContextCompat +import androidx.core.view.isVisible +import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault @@ -15,7 +17,7 @@ import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -open class TabbedLibraryDisplaySheet(val controller: LibraryController) : +open class TabbedLibraryDisplaySheet(val controller: Controller) : TabbedBottomSheetDialog(controller.activity!!) { private val displayView: LibraryDisplayView = inflate(controller.activity!!, R.layout.library_display_layout, null) as LibraryDisplayView @@ -23,10 +25,12 @@ open class TabbedLibraryDisplaySheet(val controller: LibraryController) : private val categoryView: LibraryCategoryView = inflate(controller.activity!!, R.layout.library_category_layout, null) as LibraryCategoryView init { - displayView.controller = controller - badgesView.controller = controller - categoryView.controller = controller - binding.menu.visible() + (controller as? LibraryController)?.let { libraryController -> + displayView.controller = libraryController + badgesView.controller = libraryController + categoryView.controller = libraryController + } + binding.menu.isVisible = controller !is SettingsLibraryController binding.menu.compatToolTipText = context.getString(R.string.more_library_settings) binding.menu.setImageDrawable( ContextCompat.getDrawable( @@ -39,11 +43,16 @@ open class TabbedLibraryDisplaySheet(val controller: LibraryController) : dismiss() } - setExpandText( - !controller.singleCategory && controller.presenter.showAllCategories, - Injekt.get().collapsedCategories().getOrDefault().isNotEmpty(), - false - ) + if (controller is LibraryController) { + setExpandText( + !controller.singleCategory && controller.presenter.showAllCategories, + Injekt.get().collapsedCategories().getOrDefault().isNotEmpty(), + false + ) + } else { + setExpandText(showExpanded = false, allExpanded = false) + categoryView.binding.addCategoriesButton.isVisible = false + } } fun setExpandText(showExpanded: Boolean, allExpanded: Boolean, animated: Boolean = true) { @@ -53,7 +62,7 @@ open class TabbedLibraryDisplaySheet(val controller: LibraryController) : override fun dismiss() { super.dismiss() - controller.displaySheet = null + (controller as? LibraryController)?.displaySheet = null } override fun getTabViews(): List = listOf( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index c7d042fa23..85ac0fd42d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.ui.category.CategoryController +import eu.kanade.tachiyomi.ui.library.display.TabbedLibraryDisplaySheet import eu.kanade.tachiyomi.util.view.withFadeTransaction import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -26,6 +27,17 @@ class SettingsLibraryController : SettingsController() { summaryRes = R.string.when_sorting_ignore_articles defaultValue = false } + + preference { + key = "library_display_options" + isPersistent = false + titleRes = R.string.display_options + summaryRes = R.string.can_be_found_in_library_filters + + onClick { + TabbedLibraryDisplaySheet(this@SettingsLibraryController).show() + } + } } val dbCategories = db.getCategories().executeAsBlocking() @@ -34,6 +46,7 @@ class SettingsLibraryController : SettingsController() { titleRes = R.string.categories preference { key = "edit_categories" + isPersistent = false val catCount = db.getCategories().executeAsBlocking().size titleRes = if (catCount > 0) R.string.edit_categories else R.string.add_categories if (catCount > 0) summary = context.resources.getQuantityString(R.plurals.category_plural, catCount, catCount) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt index 134cfb6823..8d0ba18453 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt @@ -18,7 +18,6 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.databinding.BrowseSourceControllerBinding import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.LocalSource @@ -168,7 +167,7 @@ open class BrowseSourceController(bundle: Bundle) : } } else { (binding.catalogueView.inflate(R.layout.manga_recycler_autofit) as AutofitRecyclerView).apply { - columnWidth = when (preferences.gridSize().getOrDefault()) { + columnWidth = when (preferences.gridSize().get()) { 1 -> 1f 2 -> 1.25f 3 -> 1.66f diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt index 132cc5b17f..599f43851d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt @@ -8,13 +8,12 @@ import android.widget.ImageView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat 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.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.databinding.MangaGridItemBinding import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.updateLayoutParams @@ -28,7 +27,7 @@ class BrowseSourceItem( AbstractFlexibleItem() { override fun getLayoutRes(): Int { - return if (catalogueAsList.getOrDefault()) { + return if (catalogueAsList.get()) { R.layout.manga_list_item } else { R.layout.manga_grid_item @@ -37,8 +36,8 @@ class BrowseSourceItem( override fun createViewHolder(view: View, adapter: FlexibleAdapter>): BrowseSourceHolder { val parent = adapter.recyclerView - return if (parent is AutofitRecyclerView && !catalogueAsList.getOrDefault()) { - val listType = catalogueListType.getOrDefault() + return if (parent is AutofitRecyclerView && !catalogueAsList.get()) { + val listType = catalogueListType.get() view.apply { val binding = MangaGridItemBinding.bind(this) val coverHeight = (parent.itemWidth / 3 * 4f).toInt() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt index 21eb641a1d..e5d4ab3546 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourcePresenter.kt @@ -28,6 +28,12 @@ import eu.kanade.tachiyomi.ui.source.filter.TextItem import eu.kanade.tachiyomi.ui.source.filter.TextSectionItem import eu.kanade.tachiyomi.ui.source.filter.TriStateItem import eu.kanade.tachiyomi.ui.source.filter.TriStateSectionItem +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.cancel +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -109,6 +115,8 @@ open class BrowseSourcePresenter( */ private var initializerSubscription: Subscription? = null + private var scope = CoroutineScope(Job() + Dispatchers.IO) + override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) @@ -118,14 +126,18 @@ open class BrowseSourcePresenter( query = savedState.getString(::query.name, "") } - add( - prefs.browseAsList().asObservable() - .subscribe { setDisplayMode(it) } - ) + prefs.browseAsList().asFlow() + .onEach { setDisplayMode(it) } + .launchIn(scope) restartPager() } + override fun onDestroy() { + super.onDestroy() + scope.cancel() + } + override fun onSave(state: Bundle) { state.putString(::query.name, query) super.onSave(state) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/PreferenceExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/PreferenceExtensions.kt index 7e6dff75ab..55aa6902e8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/PreferenceExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/PreferenceExtensions.kt @@ -87,6 +87,18 @@ fun RadioGroup.bindToPreference(pref: Preference, block: (() -> Unit)? = nu } } +/** + * Binds a radio group with a int preference. + */ +fun RadioGroup.bindToPreference(pref: com.tfcporciuncula.flow.Preference, block: (() -> Unit)? = null) { + (getChildAt(pref.get()) as RadioButton).isChecked = true + setOnCheckedChangeListener { _, checkedId -> + val index = indexOfChild(findViewById(checkedId)) + pref.set(index) + block?.invoke() + } +} + /** * Binds a spinner to an int preference with an optional offset for the value. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt index 05cfc5ee69..5a88c294af 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/BaseTabbedScrollView.kt @@ -13,7 +13,8 @@ import uy.kohesive.injekt.injectLazy abstract class BaseTabbedScrollView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : NestedScrollView(context, attrs) { - protected lateinit var binding: VB + lateinit var binding: VB + private set init { clipToPadding = false } @@ -32,7 +33,7 @@ abstract class BaseTabbedScrollView @JvmOverloads constructor( abstract class BaseLibraryDisplayView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : BaseTabbedScrollView(context, attrs) { - lateinit var controller: LibraryController + var controller: LibraryController? = null } abstract class BaseReaderSettingsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7b68fa218f..49b8eefb29 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -146,6 +146,7 @@ Display options + Can also be found by expanding library filters List Comfortable Grid Compact Grid