Make controllers responsible for showing/hiding FAB
This commit is contained in:
parent
5452e29840
commit
8ef548032f
5 changed files with 38 additions and 46 deletions
|
@ -47,6 +47,7 @@ import eu.kanade.tachiyomi.util.view.snack
|
|||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import eu.kanade.tachiyomi.widget.EmptyView
|
||||
import kotlinx.android.synthetic.main.main_activity.root_fab
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.filter
|
||||
|
@ -86,7 +87,6 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||
*/
|
||||
private var adapter: FlexibleAdapter<IFlexible<*>>? = null
|
||||
|
||||
private var actionFab: ExtendedFloatingActionButton? = null
|
||||
private var actionFabScrollListener: RecyclerView.OnScrollListener? = null
|
||||
|
||||
/**
|
||||
|
@ -167,27 +167,21 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||
filterSheet?.setFilters(presenter.filterItems)
|
||||
|
||||
// TODO: [ExtendedFloatingActionButton] hide/show methods don't work properly
|
||||
filterSheet?.setOnShowListener { actionFab?.gone() }
|
||||
filterSheet?.setOnDismissListener { actionFab?.visible() }
|
||||
filterSheet?.setOnShowListener { activity!!.root_fab.gone() }
|
||||
filterSheet?.setOnDismissListener { activity!!.root_fab.visible() }
|
||||
|
||||
actionFab?.setOnClickListener { filterSheet?.show() }
|
||||
activity!!.root_fab.setOnClickListener { filterSheet?.show() }
|
||||
|
||||
actionFab?.visible()
|
||||
activity!!.root_fab.visible()
|
||||
}
|
||||
|
||||
override fun configureFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFab = fab
|
||||
|
||||
// Controlled by initFilterSheet()
|
||||
fab.gone()
|
||||
|
||||
fab.setText(R.string.action_filter)
|
||||
fab.setIconResource(R.drawable.ic_filter_list_24dp)
|
||||
}
|
||||
|
||||
override fun cleanupFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFabScrollListener?.let { recycler?.removeOnScrollListener(it) }
|
||||
actionFab = null
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
|
@ -196,6 +190,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||
adapter = null
|
||||
snack = null
|
||||
recycler = null
|
||||
activity!!.root_fab.gone()
|
||||
super.onDestroyView(view)
|
||||
}
|
||||
|
||||
|
@ -247,7 +242,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||
)
|
||||
recycler.clipToPadding = false
|
||||
|
||||
actionFab?.shrinkOnScroll(recycler)
|
||||
activity!!.root_fab.shrinkOnScroll(recycler)
|
||||
}
|
||||
|
||||
recycler.setHasFixedSize(true)
|
||||
|
|
|
@ -20,8 +20,11 @@ import eu.kanade.tachiyomi.databinding.CategoriesControllerBinding
|
|||
import eu.kanade.tachiyomi.ui.base.controller.FabController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.shrinkOnScroll
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.android.synthetic.main.main_activity.root_coordinator
|
||||
import kotlinx.android.synthetic.main.main_activity.root_fab
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
@ -50,7 +53,6 @@ class CategoryController :
|
|||
*/
|
||||
private var adapter: CategoryAdapter? = null
|
||||
|
||||
private var actionFab: ExtendedFloatingActionButton? = null
|
||||
private var actionFabScrollListener: RecyclerView.OnScrollListener? = null
|
||||
|
||||
/**
|
||||
|
@ -96,11 +98,11 @@ class CategoryController :
|
|||
adapter?.isHandleDragEnabled = true
|
||||
adapter?.isPermanentDelete = false
|
||||
|
||||
actionFabScrollListener = actionFab?.shrinkOnScroll(binding.recycler)
|
||||
activity!!.root_fab.visible()
|
||||
actionFabScrollListener = activity!!.root_fab.shrinkOnScroll(binding.recycler)
|
||||
}
|
||||
|
||||
override fun configureFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFab = fab
|
||||
fab.setText(R.string.action_add)
|
||||
fab.setIconResource(R.drawable.ic_add_24dp)
|
||||
fab.clicks()
|
||||
|
@ -112,7 +114,6 @@ class CategoryController :
|
|||
|
||||
override fun cleanupFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFabScrollListener?.let { binding.recycler.removeOnScrollListener(it) }
|
||||
actionFab = null
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,6 +127,7 @@ class CategoryController :
|
|||
undoHelper = null
|
||||
actionMode = null
|
||||
adapter = null
|
||||
activity!!.root_fab.gone()
|
||||
super.onDestroyView(view)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.util.view.gone
|
|||
import eu.kanade.tachiyomi.util.view.shrinkOnScroll
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlinx.android.synthetic.main.main_activity.root_fab
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
@ -41,7 +42,6 @@ class DownloadController :
|
|||
*/
|
||||
private var adapter: DownloadAdapter? = null
|
||||
|
||||
private var actionFab: ExtendedFloatingActionButton? = null
|
||||
private var actionFabScrollListener: RecyclerView.OnScrollListener? = null
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,8 @@ class DownloadController :
|
|||
binding.recycler.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recycler.setHasFixedSize(true)
|
||||
|
||||
actionFabScrollListener = actionFab?.shrinkOnScroll(binding.recycler)
|
||||
activity!!.root_fab.visible()
|
||||
actionFabScrollListener = activity!!.root_fab.shrinkOnScroll(binding.recycler)
|
||||
|
||||
// Subscribe to changes
|
||||
DownloadService.runningRelay
|
||||
|
@ -104,7 +105,6 @@ class DownloadController :
|
|||
}
|
||||
|
||||
override fun configureFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFab = fab
|
||||
fab.clicks()
|
||||
.onEach {
|
||||
val context = applicationContext ?: return@onEach
|
||||
|
@ -123,7 +123,6 @@ class DownloadController :
|
|||
|
||||
override fun cleanupFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFabScrollListener?.let { binding.recycler.removeOnScrollListener(it) }
|
||||
actionFab = null
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
|
@ -131,6 +130,7 @@ class DownloadController :
|
|||
subscription.unsubscribe()
|
||||
}
|
||||
progressSubscriptions.clear()
|
||||
activity!!.root_fab.gone()
|
||||
adapter = null
|
||||
super.onDestroyView(view)
|
||||
}
|
||||
|
@ -284,10 +284,10 @@ class DownloadController :
|
|||
private fun setInformationView() {
|
||||
if (presenter.downloadQueue.isEmpty()) {
|
||||
binding.emptyView.show(R.string.information_no_downloads)
|
||||
actionFab?.gone()
|
||||
activity!!.root_fab.gone()
|
||||
} else {
|
||||
binding.emptyView.hide()
|
||||
actionFab?.apply {
|
||||
activity!!.root_fab.apply {
|
||||
visible()
|
||||
|
||||
setText(
|
||||
|
|
|
@ -43,7 +43,6 @@ import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
|||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.gone
|
||||
import eu.kanade.tachiyomi.util.view.snack
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import java.util.Date
|
||||
|
@ -349,11 +348,9 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||
}
|
||||
|
||||
if (from is FabController) {
|
||||
binding.rootFab.gone()
|
||||
from.cleanupFab(binding.rootFab)
|
||||
}
|
||||
if (to is FabController) {
|
||||
binding.rootFab.visible()
|
||||
to.configureFab(binding.rootFab)
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ import eu.kanade.tachiyomi.util.view.shrinkOnScroll
|
|||
import eu.kanade.tachiyomi.util.view.snack
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.android.synthetic.main.main_activity.root_coordinator
|
||||
import kotlinx.android.synthetic.main.main_activity.root_fab
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
@ -123,7 +124,6 @@ class MangaController :
|
|||
private var chaptersHeaderAdapter: MangaChaptersHeaderAdapter? = null
|
||||
private var chaptersAdapter: ChaptersAdapter? = null
|
||||
|
||||
private var actionFab: ExtendedFloatingActionButton? = null
|
||||
private var actionFabScrollListener: RecyclerView.OnScrollListener? = null
|
||||
|
||||
/**
|
||||
|
@ -187,7 +187,8 @@ class MangaController :
|
|||
binding.recycler.setHasFixedSize(true)
|
||||
chaptersAdapter?.fastScroller = binding.fastScroller
|
||||
|
||||
actionFabScrollListener = actionFab?.shrinkOnScroll(binding.recycler)
|
||||
activity!!.root_fab.visible()
|
||||
actionFabScrollListener = activity!!.root_fab.shrinkOnScroll(binding.recycler)
|
||||
|
||||
// Skips directly to chapters list if navigated to from the library
|
||||
binding.recycler.post {
|
||||
|
@ -207,7 +208,6 @@ class MangaController :
|
|||
}
|
||||
|
||||
override fun configureFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFab = fab
|
||||
fab.setText(R.string.action_start)
|
||||
fab.setIconResource(R.drawable.ic_play_arrow_24dp)
|
||||
fab.clicks()
|
||||
|
@ -222,7 +222,7 @@ class MangaController :
|
|||
}
|
||||
|
||||
// Get coordinates and start animation
|
||||
actionFab?.getCoordinates()?.let { coordinates ->
|
||||
val coordinates = fab.getCoordinates()
|
||||
if (!binding.revealView.showRevealEffect(
|
||||
coordinates.x,
|
||||
coordinates.y,
|
||||
|
@ -231,7 +231,6 @@ class MangaController :
|
|||
) {
|
||||
openChapter(item.chapter)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view?.context?.toast(R.string.no_next_chapter)
|
||||
}
|
||||
|
@ -241,12 +240,12 @@ class MangaController :
|
|||
|
||||
override fun cleanupFab(fab: ExtendedFloatingActionButton) {
|
||||
actionFabScrollListener?.let { binding.recycler.removeOnScrollListener(it) }
|
||||
actionFab = null
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
destroyActionModeIfNeeded()
|
||||
binding.actionToolbar.destroy()
|
||||
activity!!.root_fab.gone()
|
||||
mangaInfoAdapter = null
|
||||
chaptersHeaderAdapter = null
|
||||
chaptersAdapter = null
|
||||
|
@ -259,10 +258,9 @@ class MangaController :
|
|||
// Check if animation view is visible
|
||||
if (binding.revealView.visibility == View.VISIBLE) {
|
||||
// Show the unreveal effect
|
||||
actionFab?.getCoordinates()?.let { coordinates ->
|
||||
val coordinates = activity.root_fab.getCoordinates()
|
||||
binding.revealView.hideRevealEffect(coordinates.x, coordinates.y, 1920)
|
||||
}
|
||||
}
|
||||
|
||||
super.onActivityResumed(activity)
|
||||
}
|
||||
|
@ -690,7 +688,7 @@ class MangaController :
|
|||
|
||||
val context = view?.context
|
||||
if (context != null && chapters.any { it.read }) {
|
||||
actionFab?.text = context.getString(R.string.action_resume)
|
||||
activity!!.root_fab.text = context.getString(R.string.action_resume)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -826,8 +824,8 @@ class MangaController :
|
|||
binding.actionToolbar.findItem(R.id.action_mark_as_unread)?.isVisible = chapters.all { it.chapter.read }
|
||||
|
||||
// Hide FAB to avoid interfering with the bottom action toolbar
|
||||
// actionFab?.hide()
|
||||
actionFab?.gone()
|
||||
// activity!!.root_fab.hide()
|
||||
activity!!.root_fab.gone()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -861,8 +859,8 @@ class MangaController :
|
|||
|
||||
// TODO: there seems to be a bug in MaterialComponents where the [ExtendedFloatingActionButton]
|
||||
// fails to show up properly
|
||||
// actionFab?.show()
|
||||
actionFab?.visible()
|
||||
// activity!!.root_fab.show()
|
||||
activity!!.root_fab.visible()
|
||||
}
|
||||
|
||||
override fun onDetach(view: View) {
|
||||
|
|
Reference in a new issue