From 316211372c2465ab3e8ad5b6ba154898c46ca54b Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Mar 2020 15:38:42 -0400 Subject: [PATCH] Tweak how bottom action menu is configured --- .../controller/BottomActionMenuController.kt | 8 +++++++ .../kanade/tachiyomi/ui/main/MainActivity.kt | 10 ++++++++- .../ui/recent/updates/UpdatesController.kt | 22 +++++++++---------- .../tachiyomi/widget/BottomActionMenu.kt | 21 +++++++++++++----- 4 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BottomActionMenuController.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BottomActionMenuController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BottomActionMenuController.kt new file mode 100644 index 0000000000..9e19ff41bb --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BottomActionMenuController.kt @@ -0,0 +1,8 @@ +package eu.kanade.tachiyomi.ui.base.controller + +import eu.kanade.tachiyomi.widget.BottomActionMenu + +interface BottomActionMenuController { + + fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu) +} 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 2e97ad1545..63ead3fe6b 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 @@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.ui.base.activity.BaseActivity +import eu.kanade.tachiyomi.ui.base.controller.BottomActionMenuController import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.RootController @@ -76,7 +77,7 @@ class MainActivity : BaseActivity() { if (currentRoot?.tag()?.toIntOrNull() != id) { when (id) { R.id.nav_library -> setRoot(LibraryController(), id) - R.id.nav_updates -> setRoot(UpdatesController(bottom_action_menu), id) + R.id.nav_updates -> setRoot(UpdatesController(), id) R.id.nav_history -> setRoot(HistoryController(), id) R.id.nav_catalogues -> setRoot(CatalogueController(), id) R.id.nav_more -> setRoot(MoreController(), id) @@ -258,6 +259,13 @@ class MainActivity : BaseActivity() { } else { appbar.enableElevation() } + + if (from is BottomActionMenuController) { + bottom_action_menu.cleanup() + } + if (to is BottomActionMenuController) { + to.configureBottomActionMenu(bottom_action_menu) + } } companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index ad70d64e2f..675f311af1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -7,7 +7,6 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode -import androidx.appcompat.widget.ActionMenuView import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.jakewharton.rxbinding.support.v4.widget.refreshes @@ -19,6 +18,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.notification.Notifications +import eu.kanade.tachiyomi.ui.base.controller.BottomActionMenuController import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.RootController @@ -39,9 +39,10 @@ import timber.log.Timber * Uses [R.layout.updates_controller]. * UI related actions should be called from here. */ -class UpdatesController() : NucleusController(), +class UpdatesController : NucleusController(), RootController, NoToolbarElevationController, + BottomActionMenuController, ActionMode.Callback, FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, @@ -49,10 +50,6 @@ class UpdatesController() : NucleusController(), ConfirmDeleteChaptersDialog.Listener, UpdatesAdapter.OnCoverClickListener { - constructor(bottomActionMenu: BottomActionMenu) : this() { - this.bottomActionMenu = bottomActionMenu - } - /** * Action mode for multiple selection. */ @@ -299,11 +296,7 @@ class UpdatesController() : NucleusController(), } else { mode.title = count.toString() - bottomActionMenu?.show( - mode.menuInflater, - R.menu.updates_chapter_selection, - ActionMenuView.OnMenuItemClickListener { onActionItemClicked(actionMode!!, it) } - ) + bottomActionMenu?.show(mode.menuInflater) } return false @@ -343,4 +336,11 @@ class UpdatesController() : NucleusController(), adapter.selectAll() actionMode?.invalidate() } + + override fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu) { + this.bottomActionMenu = bottomActionMenu + bottomActionMenu.configure( + R.menu.updates_chapter_selection + ) { onActionItemClicked(actionMode!!, it!!) } + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt index 635bbd31aa..8ff64c63a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt @@ -3,10 +3,10 @@ package eu.kanade.tachiyomi.widget import android.content.Context import android.util.AttributeSet import android.view.MenuInflater +import android.view.MenuItem import android.view.View import android.widget.FrameLayout import androidx.annotation.MenuRes -import androidx.appcompat.widget.ActionMenuView import eu.kanade.tachiyomi.R import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu_bar @@ -14,15 +14,27 @@ import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) { + @MenuRes + private var menuRes: Int = 0 + init { inflate(context, R.layout.common_bottom_action_menu, this) } - fun show(menuInflater: MenuInflater, @MenuRes menuRes: Int, listener: ActionMenuView.OnMenuItemClickListener) { + fun configure(@MenuRes menuRes: Int, listener: (item: MenuItem?) -> Boolean) { + this.menuRes = menuRes + bottom_menu.setOnMenuItemClickListener { listener(it) } + } + + fun cleanup() { + bottom_menu.menu.clear() + bottom_menu.setOnMenuItemClickListener(null) + } + + fun show(menuInflater: MenuInflater) { // Avoid re-inflating the menu if (bottom_menu.menu.size() == 0) { menuInflater.inflate(menuRes, bottom_menu.menu) - bottom_menu.setOnMenuItemClickListener(listener) } bottom_menu_bar.visibility = View.VISIBLE @@ -30,8 +42,5 @@ class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: Attrib fun hide() { bottom_menu_bar.visibility = View.GONE - - bottom_menu.setOnMenuItemClickListener(null) - bottom_menu.menu.clear() } }