diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt index 4c50f73d5..98be2923a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt @@ -51,8 +51,11 @@ class ChaptersPagesSheet : BaseAdaptiveSheet(), Actio disableFitToContents() val args = arguments ?: Bundle.EMPTY - val defaultTab = args.getInt(ARG_TAB, settings.defaultDetailsTab) - val adapter = ChaptersPagesAdapter(this, settings.isPagesTabEnabled || defaultTab == TAB_PAGES) + var defaultTab = args.getInt(ARG_TAB, settings.defaultDetailsTab) + val adapter = ChaptersPagesAdapter(this, settings.isPagesTabEnabled) + if (!adapter.isPagesTabEnabled) { + defaultTab = (defaultTab - 1).coerceAtLeast(TAB_CHAPTERS) + } binding.pager.offscreenPageLimit = adapter.itemCount binding.pager.adapter = adapter binding.pager.doOnPageChanged(::onPageChanged) @@ -134,9 +137,6 @@ class ChaptersPagesSheet : BaseAdaptiveSheet(), Actio const val TAB_PAGES = 1 const val TAB_BOOKMARKS = 2 private const val ARG_TAB = "tag" - - @Deprecated("") - private const val ARG_SHOW_PAGES = "pages" private const val TAG = "ChaptersPagesSheet" fun show(fm: FragmentManager) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt index f355f3793..072725323 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt @@ -26,7 +26,6 @@ import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback import org.koitharu.kotatsu.core.util.ext.dismissParentDialog import org.koitharu.kotatsu.core.util.ext.findAppCompatDelegate import org.koitharu.kotatsu.core.util.ext.findParentCallback -import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.databinding.FragmentChaptersBinding diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt index 531143550..92b7b98bb 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt @@ -146,6 +146,7 @@ class ReaderActivity : viewModel.isKeepScreenOnEnabled.observe(this, this::setKeepScreenOn) viewModel.isInfoBarEnabled.observe(this, ::onReaderBarChanged) viewModel.isBookmarkAdded.observe(this, MenuInvalidator(this)) + viewModel.isPagesSheetEnabled.observe(this, MenuInvalidator(viewBinding.toolbarBottom)) viewModel.onShowToast.observeEvent(this) { msgId -> Snackbar.make(viewBinding.container, msgId, Snackbar.LENGTH_SHORT) .setAnchorView(viewBinding.appbarBottom) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderBottomMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderBottomMenuProvider.kt index e2101196e..d69448ef5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderBottomMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderBottomMenuProvider.kt @@ -22,7 +22,12 @@ class ReaderBottomMenuProvider( override fun onPrepareMenu(menu: Menu) { val hasPages = viewModel.content.value.pages.isNotEmpty() - menu.findItem(R.id.action_pages_thumbs).isVisible = hasPages + menu.findItem(R.id.action_pages_thumbs).run { + isVisible = hasPages + if (hasPages) { + setIcon(if (viewModel.isPagesSheetEnabled.value) R.drawable.ic_grid else R.drawable.ic_list) + } + } } override fun onMenuItemSelected(menuItem: MenuItem): Boolean { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt index 5185b9bcb..b4dd6d818 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flatMapLatest @@ -48,6 +49,7 @@ import org.koitharu.kotatsu.core.util.ext.requireValue import org.koitharu.kotatsu.core.util.ext.sizeOrZero import org.koitharu.kotatsu.details.data.MangaDetails import org.koitharu.kotatsu.details.domain.DetailsLoadUseCase +import org.koitharu.kotatsu.details.ui.pager.ChaptersPagesSheet.Companion.TAB_PAGES import org.koitharu.kotatsu.history.data.HistoryRepository import org.koitharu.kotatsu.history.data.PROGRESS_NONE import org.koitharu.kotatsu.history.domain.HistoryUpdateUseCase @@ -106,6 +108,8 @@ class ReaderViewModel @Inject constructor( it != null && historyRepository.shouldSkip(it) }.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false) + val isPagesSheetEnabled = observeIsPagesSheetEnabled() + val content = MutableStateFlow(ReaderContent(emptyList(), null)) val manga: MangaDetails? get() = mangaData.value @@ -474,4 +478,9 @@ class ReaderViewModel @Inject constructor( key = AppSettings.KEY_READER_ZOOM_BUTTONS, valueProducer = { isReaderZoomButtonsEnabled }, ) + + private fun observeIsPagesSheetEnabled() = settings.observe() + .filter { it == AppSettings.KEY_PAGES_TAB || it == AppSettings.KEY_DETAILS_TAB || it == AppSettings.KEY_DETAILS_LAST_TAB } + .map { settings.defaultDetailsTab == TAB_PAGES } + .stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, settings.defaultDetailsTab == TAB_PAGES) }