Tweak how bottom action menu is configured

This commit is contained in:
arkon 2020-03-08 15:38:42 -04:00
parent 29a2d41331
commit 316211372c
4 changed files with 43 additions and 18 deletions

View File

@ -0,0 +1,8 @@
package eu.kanade.tachiyomi.ui.base.controller
import eu.kanade.tachiyomi.widget.BottomActionMenu
interface BottomActionMenuController {
fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu)
}

View File

@ -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 {

View File

@ -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<UpdatesPresenter>(),
class UpdatesController : NucleusController<UpdatesPresenter>(),
RootController,
NoToolbarElevationController,
BottomActionMenuController,
ActionMode.Callback,
FlexibleAdapter.OnItemClickListener,
FlexibleAdapter.OnItemLongClickListener,
@ -49,10 +50,6 @@ class UpdatesController() : NucleusController<UpdatesPresenter>(),
ConfirmDeleteChaptersDialog.Listener,
UpdatesAdapter.OnCoverClickListener {
constructor(bottomActionMenu: BottomActionMenu) : this() {
this.bottomActionMenu = bottomActionMenu
}
/**
* Action mode for multiple selection.
*/
@ -299,11 +296,7 @@ class UpdatesController() : NucleusController<UpdatesPresenter>(),
} 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<UpdatesPresenter>(),
adapter.selectAll()
actionMode?.invalidate()
}
override fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu) {
this.bottomActionMenu = bottomActionMenu
bottomActionMenu.configure(
R.menu.updates_chapter_selection
) { onActionItemClicked(actionMode!!, it!!) }
}
}

View File

@ -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()
}
}