|
|
|
|
@ -7,19 +7,24 @@ import androidx.appcompat.view.ActionMode
|
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
|
|
import androidx.lifecycle.Lifecycle
|
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver
|
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
|
import org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet
|
|
|
|
|
import org.koitharu.kotatsu.core.ui.util.ActionModeListener
|
|
|
|
|
import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.menuView
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.setTabsEnabled
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.withArgs
|
|
|
|
|
import org.koitharu.kotatsu.databinding.SheetChaptersPagesBinding
|
|
|
|
|
import org.koitharu.kotatsu.details.ui.DetailsViewModel
|
|
|
|
|
import org.koitharu.kotatsu.download.ui.worker.DownloadStartedObserver
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
@AndroidEntryPoint
|
|
|
|
|
@ -39,13 +44,14 @@ class ChaptersPagesSheet : BaseAdaptiveSheet<SheetChaptersPagesBinding>(), Actio
|
|
|
|
|
disableFitToContents()
|
|
|
|
|
|
|
|
|
|
val args = arguments ?: Bundle.EMPTY
|
|
|
|
|
val adapter = ChaptersPagesAdapter(this, args.getBoolean(ARG_SHOW_PAGES, settings.isPagesTabEnabled))
|
|
|
|
|
val defaultTab = args.getInt(ARG_TAB, settings.defaultDetailsTab)
|
|
|
|
|
val adapter = ChaptersPagesAdapter(this, settings.isPagesTabEnabled || defaultTab == TAB_PAGES)
|
|
|
|
|
binding.pager.recyclerView?.isNestedScrollingEnabled = false
|
|
|
|
|
binding.pager.offscreenPageLimit = adapter.itemCount
|
|
|
|
|
binding.pager.adapter = adapter
|
|
|
|
|
binding.pager.doOnPageChanged(::onPageChanged)
|
|
|
|
|
TabLayoutMediator(binding.tabs, binding.pager, adapter).attach()
|
|
|
|
|
binding.pager.setCurrentItem(args.getInt(ARG_TAB, settings.defaultDetailsTab), false)
|
|
|
|
|
binding.pager.setCurrentItem(defaultTab, false)
|
|
|
|
|
binding.tabs.isVisible = adapter.itemCount > 1
|
|
|
|
|
|
|
|
|
|
val menuProvider = ChapterPagesMenuProvider(viewModel, this, binding.pager, settings)
|
|
|
|
|
@ -53,16 +59,20 @@ class ChaptersPagesSheet : BaseAdaptiveSheet<SheetChaptersPagesBinding>(), Actio
|
|
|
|
|
binding.toolbar.addMenuProvider(menuProvider)
|
|
|
|
|
|
|
|
|
|
actionModeDelegate.addListener(this, viewLifecycleOwner)
|
|
|
|
|
|
|
|
|
|
viewModel.onError.observeEvent(viewLifecycleOwner, SnackbarErrorObserver(binding.pager, this))
|
|
|
|
|
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ReversibleActionObserver(binding.pager, null))
|
|
|
|
|
viewModel.onDownloadStarted.observeEvent(viewLifecycleOwner, DownloadStartedObserver(binding.pager))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onActionModeStarted(mode: ActionMode) {
|
|
|
|
|
expandAndLock()
|
|
|
|
|
viewBinding?.toolbar?.menuView?.isEnabled = false
|
|
|
|
|
viewBinding?.toolbar?.menuView?.isVisible = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onActionModeFinished(mode: ActionMode) {
|
|
|
|
|
unlock()
|
|
|
|
|
viewBinding?.toolbar?.menuView?.isEnabled = true
|
|
|
|
|
viewBinding?.toolbar?.menuView?.isVisible = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun expandAndLock() {
|
|
|
|
|
@ -93,6 +103,8 @@ class ChaptersPagesSheet : BaseAdaptiveSheet<SheetChaptersPagesBinding>(), 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"
|
|
|
|
|
|
|
|
|
|
@ -100,17 +112,15 @@ class ChaptersPagesSheet : BaseAdaptiveSheet<SheetChaptersPagesBinding>(), Actio
|
|
|
|
|
ChaptersPagesSheet().showDistinct(fm, TAG)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun show(fm: FragmentManager, showPagesTab: Boolean) {
|
|
|
|
|
fun show(fm: FragmentManager, defaultTab: Int) {
|
|
|
|
|
ChaptersPagesSheet().withArgs(1) {
|
|
|
|
|
putBoolean(ARG_SHOW_PAGES, showPagesTab)
|
|
|
|
|
putInt(ARG_TAB, defaultTab)
|
|
|
|
|
}.showDistinct(fm, TAG)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun show(fm: FragmentManager, showPagesTab: Boolean, defaultTab: Int) {
|
|
|
|
|
ChaptersPagesSheet().withArgs(2) {
|
|
|
|
|
putBoolean(ARG_SHOW_PAGES, showPagesTab)
|
|
|
|
|
putInt(ARG_TAB, defaultTab)
|
|
|
|
|
}.showDistinct(fm, TAG)
|
|
|
|
|
fun isShown(fm: FragmentManager): Boolean {
|
|
|
|
|
val sheet = fm.findFragmentByTag(TAG) as? ChaptersPagesSheet
|
|
|
|
|
return sheet != null && sheet.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|