From 8cfd80ba846ee900ae03f388b4746a9f85c912b1 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 10 Apr 2020 14:23:27 -0400 Subject: [PATCH] Move catalogue filters to bottom sheet --- .../controller/SecondaryDrawerController.kt | 11 --- .../browse/BrowseCatalogueController.kt | 62 ++++++-------- .../catalogue/browse/CatalogueFilterSheet.kt | 59 +++++++++++++ .../browse/CatalogueNavigationView.kt | 38 --------- .../latest/LatestUpdatesController.kt | 9 -- .../kanade/tachiyomi/ui/main/MainActivity.kt | 82 ++++++++----------- .../widget/DrawerSwipeCloseListener.kt | 23 ------ app/src/main/res/layout/catalogue_drawer.xml | 8 -- app/src/main/res/layout/main_activity.xml | 5 +- 9 files changed, 117 insertions(+), 180 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/SecondaryDrawerController.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueFilterSheet.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/DrawerSwipeCloseListener.kt delete mode 100644 app/src/main/res/layout/catalogue_drawer.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/SecondaryDrawerController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/SecondaryDrawerController.kt deleted file mode 100644 index b21d6e5470..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/SecondaryDrawerController.kt +++ /dev/null @@ -1,11 +0,0 @@ -package eu.kanade.tachiyomi.ui.base.controller - -import android.view.ViewGroup -import androidx.drawerlayout.widget.DrawerLayout - -interface SecondaryDrawerController { - - fun createSecondaryDrawer(drawer: DrawerLayout): ViewGroup? - - fun cleanupSecondaryDrawer(drawer: DrawerLayout) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index fd6cb395cd..f813c8fc50 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -9,8 +9,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView -import androidx.core.view.GravityCompat -import androidx.drawerlayout.widget.DrawerLayout import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager @@ -30,7 +28,6 @@ import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController -import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.manga.MangaController @@ -44,7 +41,6 @@ import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.EmptyView import java.util.concurrent.TimeUnit -import kotlinx.android.synthetic.main.main_activity.drawer import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -56,7 +52,6 @@ import uy.kohesive.injekt.injectLazy */ open class BrowseCatalogueController(bundle: Bundle) : NucleusController(bundle), - SecondaryDrawerController, FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.EndlessScrollListener, @@ -79,9 +74,9 @@ open class BrowseCatalogueController(bundle: Bundle) : private var snack: Snackbar? = null /** - * Navigation view containing filter items. + * Sheet containing filter items. */ - private var navView: CatalogueNavigationView? = null + private var filterSheet: CatalogueFilterSheet? = null /** * Recycler view with the list of results. @@ -129,11 +124,31 @@ open class BrowseCatalogueController(bundle: Bundle) : adapter = FlexibleAdapter(null, this) setupRecycler(view) - navView?.setFilters(presenter.filterItems) + // Prepare filter sheet + initFilterSheet() binding.progress.visible() } + private fun initFilterSheet() { + filterSheet = CatalogueFilterSheet( + activity!!, + onSearchClicked = { + val allDefault = presenter.sourceFilters == presenter.source.getFilterList() + showProgressBar() + adapter?.clear() + presenter.setSourceFilter(if (allDefault) FilterList() else presenter.sourceFilters) + }, + onResetClicked = { + presenter.appliedFilters = FilterList() + val newFilters = presenter.source.getFilterList() + presenter.sourceFilters = newFilters + filterSheet?.setFilters(presenter.filterItems) + } + ) + filterSheet?.setFilters(presenter.filterItems) + } + override fun onDestroyView(view: View) { numColumnsSubscription?.unsubscribe() numColumnsSubscription = null @@ -145,35 +160,6 @@ open class BrowseCatalogueController(bundle: Bundle) : super.onDestroyView(view) } - override fun createSecondaryDrawer(drawer: DrawerLayout): ViewGroup? { - // Inflate and prepare drawer - val navView = drawer.inflate(R.layout.catalogue_drawer) as CatalogueNavigationView - this.navView = navView - navView.setFilters(presenter.filterItems) - - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END) - - navView.onSearchClicked = { - val allDefault = presenter.sourceFilters == presenter.source.getFilterList() - showProgressBar() - adapter?.clear() - drawer.closeDrawer(GravityCompat.END) - presenter.setSourceFilter(if (allDefault) FilterList() else presenter.sourceFilters) - } - - navView.onResetClicked = { - presenter.appliedFilters = FilterList() - val newFilters = presenter.source.getFilterList() - presenter.sourceFilters = newFilters - navView.setFilters(presenter.filterItems) - } - return navView - } - - override fun cleanupSecondaryDrawer(drawer: DrawerLayout) { - navView = null - } - private fun setupRecycler(view: View) { numColumnsSubscription?.unsubscribe() @@ -292,7 +278,7 @@ open class BrowseCatalogueController(bundle: Bundle) : when (item.itemId) { R.id.action_search -> expandActionViewFromInteraction = true R.id.action_display_mode -> swapDisplayMode() - R.id.action_set_filter -> navView?.let { activity?.drawer?.openDrawer(GravityCompat.END) } + R.id.action_set_filter -> filterSheet?.show() R.id.action_open_in_web_view -> openInWebView() } return super.onOptionsItemSelected(item) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueFilterSheet.kt new file mode 100644 index 0000000000..f459807a46 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueFilterSheet.kt @@ -0,0 +1,59 @@ +package eu.kanade.tachiyomi.ui.catalogue.browse + +import android.app.Activity +import android.content.Context +import android.util.AttributeSet +import android.view.ViewGroup +import com.google.android.material.bottomsheet.BottomSheetDialog +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.view.inflate +import eu.kanade.tachiyomi.widget.SimpleNavigationView +import kotlinx.android.synthetic.main.catalogue_drawer_content.view.reset_btn +import kotlinx.android.synthetic.main.catalogue_drawer_content.view.search_btn + +class CatalogueFilterSheet( + activity: Activity, + onSearchClicked: () -> Unit, + onResetClicked: () -> Unit +) : BottomSheetDialog(activity) { + + private var filterNavView: FilterNavigationView + + init { + filterNavView = FilterNavigationView(activity) + filterNavView.onSearchClicked = { + onSearchClicked() + this.dismiss() + } + filterNavView.onResetClicked = onResetClicked + + setContentView(filterNavView) + } + + fun setFilters(items: List>) { + filterNavView.adapter.updateDataSet(items) + } + + class FilterNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + SimpleNavigationView(context, attrs) { + + var onSearchClicked = {} + var onResetClicked = {} + + val adapter: FlexibleAdapter> = FlexibleAdapter>(null) + .setDisplayHeadersAtStartUp(true) + .setStickyHeaders(true) + + init { + recycler.adapter = adapter + recycler.setHasFixedSize(true) + val view = inflate(R.layout.catalogue_drawer_content) + ((view as ViewGroup).getChildAt(1) as ViewGroup).addView(recycler) + addView(view) + search_btn.setOnClickListener { onSearchClicked() } + reset_btn.setOnClickListener { onResetClicked() } + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt deleted file mode 100644 index 624d25b925..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueNavigationView.kt +++ /dev/null @@ -1,38 +0,0 @@ -package eu.kanade.tachiyomi.ui.catalogue.browse - -import android.content.Context -import android.util.AttributeSet -import android.view.ViewGroup -import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.flexibleadapter.items.IFlexible -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.util.view.inflate -import eu.kanade.tachiyomi.widget.SimpleNavigationView -import kotlinx.android.synthetic.main.catalogue_drawer_content.view.reset_btn -import kotlinx.android.synthetic.main.catalogue_drawer_content.view.search_btn - -class CatalogueNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - SimpleNavigationView(context, attrs) { - - val adapter: FlexibleAdapter> = FlexibleAdapter>(null) - .setDisplayHeadersAtStartUp(true) - .setStickyHeaders(true) - - var onSearchClicked = {} - - var onResetClicked = {} - - init { - recycler.adapter = adapter - recycler.setHasFixedSize(true) - val view = inflate(R.layout.catalogue_drawer_content) - ((view as ViewGroup).getChildAt(1) as ViewGroup).addView(recycler) - addView(view) - search_btn.setOnClickListener { onSearchClicked() } - reset_btn.setOnClickListener { onResetClicked() } - } - - fun setFilters(items: List>) { - adapter.updateDataSet(items) - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/latest/LatestUpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/latest/LatestUpdatesController.kt index 532e1c8356..12f4f9e93f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/latest/LatestUpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/latest/LatestUpdatesController.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.ui.catalogue.latest import android.os.Bundle import android.view.Menu -import android.view.ViewGroup -import androidx.drawerlayout.widget.DrawerLayout import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCatalogueController @@ -27,11 +25,4 @@ class LatestUpdatesController(bundle: Bundle) : BrowseCatalogueController(bundle menu.findItem(R.id.action_search).isVisible = false menu.findItem(R.id.action_set_filter).isVisible = false } - - override fun createSecondaryDrawer(drawer: DrawerLayout): ViewGroup? { - return null - } - - override fun cleanupSecondaryDrawer(drawer: DrawerLayout) { - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index f68bba7fa8..fab5a3c375 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -4,7 +4,6 @@ import android.app.SearchManager import android.content.Intent import android.os.Bundle import android.view.ViewGroup -import androidx.core.view.GravityCompat import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler @@ -14,12 +13,12 @@ import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.databinding.MainActivityBinding import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.RootController -import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.catalogue.CatalogueController @@ -33,7 +32,6 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import java.util.Date import java.util.concurrent.TimeUnit -import kotlinx.android.synthetic.main.main_activity.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -43,8 +41,6 @@ class MainActivity : BaseActivity() { private lateinit var router: Router - private var secondaryDrawer: ViewGroup? = null - private val startScreenId by lazy { when (preferences.startScreen()) { 2 -> R.id.nav_history @@ -58,6 +54,8 @@ class MainActivity : BaseActivity() { private var isHandlingShortcut: Boolean = false + private lateinit var binding: MainActivityBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -67,15 +65,16 @@ class MainActivity : BaseActivity() { return } - setContentView(R.layout.main_activity) + binding = MainActivityBinding.inflate(layoutInflater) + setContentView(binding.root) - setSupportActionBar(toolbar) + setSupportActionBar(binding.toolbar) - tabAnimator = ViewHeightAnimator(tabs) - bottomNavAnimator = ViewHeightAnimator(bottom_nav) + tabAnimator = ViewHeightAnimator(binding.tabs) + bottomNavAnimator = ViewHeightAnimator(binding.bottomNav) // Set behavior of bottom nav - bottom_nav.setOnNavigationItemSelectedListener { item -> + binding.bottomNav.setOnNavigationItemSelectedListener { item -> val id = item.itemId val currentRoot = router.backstack.firstOrNull() @@ -104,16 +103,12 @@ class MainActivity : BaseActivity() { if (!router.hasRootController()) { // Set start screen if (!handleIntentAction(intent)) { - setSelectedDrawerItem(startScreenId) + setSelectedNavItem(startScreenId) } } - toolbar.setNavigationOnClickListener { - if (router.backstackSize == 1) { - drawer.openDrawer(GravityCompat.START) - } else { - onBackPressed() - } + binding.toolbar.setNavigationOnClickListener { + onBackPressed() } router.addChangeListener(object : ControllerChangeHandler.ControllerChangeListener { @@ -165,9 +160,9 @@ class MainActivity : BaseActivity() { private fun setExtensionsBadge() { val updates = preferences.extensionUpdatesCount().getOrDefault() if (updates > 0) { - bottom_nav.getOrCreateBadge(R.id.nav_more).number = updates + binding.bottomNav.getOrCreateBadge(R.id.nav_more).number = updates } else { - bottom_nav.removeBadge(R.id.nav_more) + binding.bottomNav.removeBadge(R.id.nav_more) } } @@ -197,15 +192,15 @@ class MainActivity : BaseActivity() { isHandlingShortcut = true when (intent.action) { - SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_library) - SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_updates) - SHORTCUT_RECENTLY_READ -> setSelectedDrawerItem(R.id.nav_history) - SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_sources) + SHORTCUT_LIBRARY -> setSelectedNavItem(R.id.nav_library) + SHORTCUT_RECENTLY_UPDATED -> setSelectedNavItem(R.id.nav_updates) + SHORTCUT_RECENTLY_READ -> setSelectedNavItem(R.id.nav_history) + SHORTCUT_CATALOGUES -> setSelectedNavItem(R.id.nav_sources) SHORTCUT_EXTENSIONS -> { if (router.backstackSize > 1) { router.popToRoot() } - setSelectedDrawerItem(R.id.nav_more) + setSelectedNavItem(R.id.nav_more) router.pushController(ExtensionController().withFadeTransaction()) } SHORTCUT_MANGA -> { @@ -213,14 +208,14 @@ class MainActivity : BaseActivity() { if (router.backstackSize > 1) { router.popToRoot() } - setSelectedDrawerItem(R.id.nav_library) + setSelectedNavItem(R.id.nav_library) router.pushController(RouterTransaction.with(MangaController(extras))) } SHORTCUT_DOWNLOADS -> { if (router.backstackSize > 1) { router.popToRoot() } - setSelectedDrawerItem(R.id.nav_more) + setSelectedNavItem(R.id.nav_more) router.pushController(RouterTransaction.with(DownloadController())) } Intent.ACTION_SEARCH, "com.google.android.gms.actions.SEARCH_ACTION" -> { @@ -258,24 +253,22 @@ class MainActivity : BaseActivity() { override fun onDestroy() { super.onDestroy() - bottom_nav?.setOnNavigationItemSelectedListener(null) - toolbar?.setNavigationOnClickListener(null) + binding.bottomNav.setOnNavigationItemSelectedListener(null) + binding.toolbar.setNavigationOnClickListener(null) } override fun onBackPressed() { val backstackSize = router.backstackSize - if (drawer.isDrawerOpen(GravityCompat.START) || drawer.isDrawerOpen(GravityCompat.END)) { - drawer.closeDrawers() - } else if (backstackSize == 1 && router.getControllerWithTag("$startScreenId") == null) { - setSelectedDrawerItem(startScreenId) + if (backstackSize == 1 && router.getControllerWithTag("$startScreenId") == null) { + setSelectedNavItem(startScreenId) } else if (backstackSize == 1 || !router.handleBack()) { super.onBackPressed() } } - private fun setSelectedDrawerItem(itemId: Int) { + private fun setSelectedNavItem(itemId: Int) { if (!isFinishing) { - bottom_nav.selectedItemId = itemId + binding.bottomNav.selectedItemId = itemId } } @@ -298,31 +291,20 @@ class MainActivity : BaseActivity() { } if (from is TabbedController) { - from.cleanupTabs(tabs) + from.cleanupTabs(binding.tabs) } if (to is TabbedController) { tabAnimator.expand() - to.configureTabs(tabs) + to.configureTabs(binding.tabs) } else { tabAnimator.collapse() - tabs.setupWithViewPager(null) - } - - if (from is SecondaryDrawerController) { - if (secondaryDrawer != null) { - from.cleanupSecondaryDrawer(drawer) - drawer.removeView(secondaryDrawer) - secondaryDrawer = null - } - } - if (to is SecondaryDrawerController) { - secondaryDrawer = to.createSecondaryDrawer(drawer)?.also { drawer.addView(it) } + binding.tabs.setupWithViewPager(null) } if (to is NoToolbarElevationController) { - appbar.disableElevation() + binding.appbar.disableElevation() } else { - appbar.enableElevation() + binding.appbar.enableElevation() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/DrawerSwipeCloseListener.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/DrawerSwipeCloseListener.kt deleted file mode 100644 index 1e369f6222..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/DrawerSwipeCloseListener.kt +++ /dev/null @@ -1,23 +0,0 @@ -package eu.kanade.tachiyomi.widget - -import android.view.View -import android.view.ViewGroup -import androidx.drawerlayout.widget.DrawerLayout - -class DrawerSwipeCloseListener( - private val drawer: DrawerLayout, - private val navigationView: ViewGroup -) : DrawerLayout.SimpleDrawerListener() { - - override fun onDrawerOpened(drawerView: View) { - if (drawerView == navigationView) { - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, drawerView) - } - } - - override fun onDrawerClosed(drawerView: View) { - if (drawerView == navigationView) { - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, drawerView) - } - } -} diff --git a/app/src/main/res/layout/catalogue_drawer.xml b/app/src/main/res/layout/catalogue_drawer.xml deleted file mode 100644 index 62025d0642..0000000000 --- a/app/src/main/res/layout/catalogue_drawer.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 13ed818c95..593da2cf12 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -1,7 +1,6 @@ - @@ -55,4 +54,4 @@ - +