Tweak how bottom action menu is configured
This commit is contained in:
parent
29a2d41331
commit
316211372c
@ -0,0 +1,8 @@
|
|||||||
|
package eu.kanade.tachiyomi.ui.base.controller
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.widget.BottomActionMenu
|
||||||
|
|
||||||
|
interface BottomActionMenuController {
|
||||||
|
|
||||||
|
fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu)
|
||||||
|
}
|
@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.Migrations
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
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.DialogController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||||
@ -76,7 +77,7 @@ class MainActivity : BaseActivity() {
|
|||||||
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.nav_library -> setRoot(LibraryController(), 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_history -> setRoot(HistoryController(), id)
|
||||||
R.id.nav_catalogues -> setRoot(CatalogueController(), id)
|
R.id.nav_catalogues -> setRoot(CatalogueController(), id)
|
||||||
R.id.nav_more -> setRoot(MoreController(), id)
|
R.id.nav_more -> setRoot(MoreController(), id)
|
||||||
@ -258,6 +259,13 @@ class MainActivity : BaseActivity() {
|
|||||||
} else {
|
} else {
|
||||||
appbar.enableElevation()
|
appbar.enableElevation()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (from is BottomActionMenuController) {
|
||||||
|
bottom_action_menu.cleanup()
|
||||||
|
}
|
||||||
|
if (to is BottomActionMenuController) {
|
||||||
|
to.configureBottomActionMenu(bottom_action_menu)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -7,7 +7,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.view.ActionMode
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.appcompat.widget.ActionMenuView
|
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.jakewharton.rxbinding.support.v4.widget.refreshes
|
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.download.model.Download
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
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.NoToolbarElevationController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||||
@ -39,9 +39,10 @@ import timber.log.Timber
|
|||||||
* Uses [R.layout.updates_controller].
|
* Uses [R.layout.updates_controller].
|
||||||
* UI related actions should be called from here.
|
* UI related actions should be called from here.
|
||||||
*/
|
*/
|
||||||
class UpdatesController() : NucleusController<UpdatesPresenter>(),
|
class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||||
RootController,
|
RootController,
|
||||||
NoToolbarElevationController,
|
NoToolbarElevationController,
|
||||||
|
BottomActionMenuController,
|
||||||
ActionMode.Callback,
|
ActionMode.Callback,
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
FlexibleAdapter.OnItemLongClickListener,
|
FlexibleAdapter.OnItemLongClickListener,
|
||||||
@ -49,10 +50,6 @@ class UpdatesController() : NucleusController<UpdatesPresenter>(),
|
|||||||
ConfirmDeleteChaptersDialog.Listener,
|
ConfirmDeleteChaptersDialog.Listener,
|
||||||
UpdatesAdapter.OnCoverClickListener {
|
UpdatesAdapter.OnCoverClickListener {
|
||||||
|
|
||||||
constructor(bottomActionMenu: BottomActionMenu) : this() {
|
|
||||||
this.bottomActionMenu = bottomActionMenu
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action mode for multiple selection.
|
* Action mode for multiple selection.
|
||||||
*/
|
*/
|
||||||
@ -299,11 +296,7 @@ class UpdatesController() : NucleusController<UpdatesPresenter>(),
|
|||||||
} else {
|
} else {
|
||||||
mode.title = count.toString()
|
mode.title = count.toString()
|
||||||
|
|
||||||
bottomActionMenu?.show(
|
bottomActionMenu?.show(mode.menuInflater)
|
||||||
mode.menuInflater,
|
|
||||||
R.menu.updates_chapter_selection,
|
|
||||||
ActionMenuView.OnMenuItemClickListener { onActionItemClicked(actionMode!!, it) }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -343,4 +336,11 @@ class UpdatesController() : NucleusController<UpdatesPresenter>(),
|
|||||||
adapter.selectAll()
|
adapter.selectAll()
|
||||||
actionMode?.invalidate()
|
actionMode?.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu) {
|
||||||
|
this.bottomActionMenu = bottomActionMenu
|
||||||
|
bottomActionMenu.configure(
|
||||||
|
R.menu.updates_chapter_selection
|
||||||
|
) { onActionItemClicked(actionMode!!, it!!) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ package eu.kanade.tachiyomi.widget
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.annotation.MenuRes
|
import androidx.annotation.MenuRes
|
||||||
import androidx.appcompat.widget.ActionMenuView
|
|
||||||
import eu.kanade.tachiyomi.R
|
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
|
||||||
import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu_bar
|
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) :
|
class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
FrameLayout(context, attrs) {
|
FrameLayout(context, attrs) {
|
||||||
|
|
||||||
|
@MenuRes
|
||||||
|
private var menuRes: Int = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
inflate(context, R.layout.common_bottom_action_menu, this)
|
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
|
// Avoid re-inflating the menu
|
||||||
if (bottom_menu.menu.size() == 0) {
|
if (bottom_menu.menu.size() == 0) {
|
||||||
menuInflater.inflate(menuRes, bottom_menu.menu)
|
menuInflater.inflate(menuRes, bottom_menu.menu)
|
||||||
bottom_menu.setOnMenuItemClickListener(listener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bottom_menu_bar.visibility = View.VISIBLE
|
bottom_menu_bar.visibility = View.VISIBLE
|
||||||
@ -30,8 +42,5 @@ class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: Attrib
|
|||||||
|
|
||||||
fun hide() {
|
fun hide() {
|
||||||
bottom_menu_bar.visibility = View.GONE
|
bottom_menu_bar.visibility = View.GONE
|
||||||
|
|
||||||
bottom_menu.setOnMenuItemClickListener(null)
|
|
||||||
bottom_menu.menu.clear()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user