mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-13 16:17:30 +01:00
Abstract bottom action menu code to main activity
This commit is contained in:
parent
af05c34da3
commit
9f8046324d
6 changed files with 86 additions and 34 deletions
|
@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.ui.more.MoreController
|
||||||
import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
||||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
||||||
import kotlinx.android.synthetic.main.main_activity.appbar
|
import kotlinx.android.synthetic.main.main_activity.appbar
|
||||||
|
import kotlinx.android.synthetic.main.main_activity.bottom_action_menu
|
||||||
import kotlinx.android.synthetic.main.main_activity.bottom_nav
|
import kotlinx.android.synthetic.main.main_activity.bottom_nav
|
||||||
import kotlinx.android.synthetic.main.main_activity.drawer
|
import kotlinx.android.synthetic.main.main_activity.drawer
|
||||||
import kotlinx.android.synthetic.main.main_activity.tabs
|
import kotlinx.android.synthetic.main.main_activity.tabs
|
||||||
|
@ -49,7 +50,7 @@ class MainActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var tabAnimator: ViewHeightAnimator
|
lateinit var tabAnimator: ViewHeightAnimator
|
||||||
lateinit var bottomNavAnimator: ViewHeightAnimator
|
private lateinit var bottomNavAnimator: ViewHeightAnimator
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -75,7 +76,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(), id)
|
R.id.nav_updates -> setRoot(UpdatesController(bottom_action_menu), 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)
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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
|
||||||
|
@ -27,8 +28,7 @@ import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import kotlinx.android.synthetic.main.updates_controller.bottom_menu
|
import eu.kanade.tachiyomi.widget.BottomActionMenu
|
||||||
import kotlinx.android.synthetic.main.updates_controller.bottom_menu_bar
|
|
||||||
import kotlinx.android.synthetic.main.updates_controller.empty_view
|
import kotlinx.android.synthetic.main.updates_controller.empty_view
|
||||||
import kotlinx.android.synthetic.main.updates_controller.recycler
|
import kotlinx.android.synthetic.main.updates_controller.recycler
|
||||||
import kotlinx.android.synthetic.main.updates_controller.swipe_refresh
|
import kotlinx.android.synthetic.main.updates_controller.swipe_refresh
|
||||||
|
@ -39,7 +39,7 @@ 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,
|
||||||
ActionMode.Callback,
|
ActionMode.Callback,
|
||||||
|
@ -49,10 +49,15 @@ 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.
|
||||||
*/
|
*/
|
||||||
private var actionMode: ActionMode? = null
|
private var actionMode: ActionMode? = null
|
||||||
|
private var bottomActionMenu: BottomActionMenu? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter containing the recent chapters.
|
* Adapter containing the recent chapters.
|
||||||
|
@ -102,14 +107,11 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||||
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
bottom_menu.setOnMenuItemClickListener { onActionItemClicked(actionMode!!, it) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
adapter = null
|
adapter = null
|
||||||
actionMode = null
|
actionMode = null
|
||||||
bottom_menu.setOnMenuItemClickListener(null)
|
|
||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +147,9 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||||
* @param position position of clicked item
|
* @param position position of clicked item
|
||||||
*/
|
*/
|
||||||
override fun onItemLongClick(position: Int) {
|
override fun onItemLongClick(position: Int) {
|
||||||
if (actionMode == null)
|
if (actionMode == null) {
|
||||||
actionMode = (activity as AppCompatActivity).startSupportActionMode(this)
|
actionMode = (activity as AppCompatActivity).startSupportActionMode(this)
|
||||||
|
}
|
||||||
|
|
||||||
toggleSelection(position)
|
toggleSelection(position)
|
||||||
}
|
}
|
||||||
|
@ -285,11 +288,6 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||||
mode.menuInflater.inflate(R.menu.generic_selection, menu)
|
mode.menuInflater.inflate(R.menu.generic_selection, menu)
|
||||||
adapter?.mode = SelectableAdapter.Mode.MULTI
|
adapter?.mode = SelectableAdapter.Mode.MULTI
|
||||||
|
|
||||||
// Avoid reinflating the menu multiple times
|
|
||||||
if (bottom_menu.menu.size() == 0) {
|
|
||||||
mode.menuInflater.inflate(R.menu.updates_chapter_selection, bottom_menu.menu)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +299,11 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||||
} else {
|
} else {
|
||||||
mode.title = count.toString()
|
mode.title = count.toString()
|
||||||
|
|
||||||
bottom_menu_bar.visibility = View.VISIBLE
|
bottomActionMenu?.show(
|
||||||
|
mode.menuInflater,
|
||||||
|
R.menu.updates_chapter_selection,
|
||||||
|
ActionMenuView.OnMenuItemClickListener { onActionItemClicked(actionMode!!, it) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -330,7 +332,7 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
||||||
* @param mode the ActionMode object
|
* @param mode the ActionMode object
|
||||||
*/
|
*/
|
||||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||||
bottom_menu_bar.visibility = View.GONE
|
bottomActionMenu?.hide()
|
||||||
adapter?.mode = SelectableAdapter.Mode.IDLE
|
adapter?.mode = SelectableAdapter.Mode.IDLE
|
||||||
adapter?.clearSelection()
|
adapter?.clearSelection()
|
||||||
actionMode = null
|
actionMode = null
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package eu.kanade.tachiyomi.widget
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.MenuInflater
|
||||||
|
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
|
||||||
|
|
||||||
|
class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
|
FrameLayout(context, attrs) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
inflate(context, R.layout.common_bottom_action_menu, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun show(menuInflater: MenuInflater, @MenuRes menuRes: Int, listener: ActionMenuView.OnMenuItemClickListener) {
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hide() {
|
||||||
|
bottom_menu_bar.visibility = View.GONE
|
||||||
|
|
||||||
|
bottom_menu.setOnMenuItemClickListener(null)
|
||||||
|
bottom_menu.menu.clear()
|
||||||
|
}
|
||||||
|
}
|
25
app/src/main/res/layout/common_bottom_action_menu.xml
Normal file
25
app/src/main/res/layout/common_bottom_action_menu.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/bottom_menu_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
android:theme="?attr/actionBarTheme"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:contentInsetStart="8dp"
|
||||||
|
app:contentInsetEnd="8dp">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.ActionMenuView
|
||||||
|
android:id="@+id/bottom_menu"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -42,6 +42,11 @@
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
|
<eu.kanade.tachiyomi.widget.BottomActionMenu
|
||||||
|
android:id="@+id/bottom_action_menu"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
android:id="@+id/bottom_nav"
|
android:id="@+id/bottom_nav"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -24,24 +24,6 @@
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/bottom_menu_bar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:background="?attr/colorPrimary"
|
|
||||||
android:theme="?attr/actionBarTheme"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:contentInsetStart="8dp"
|
|
||||||
app:contentInsetEnd="8dp">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.ActionMenuView
|
|
||||||
android:id="@+id/bottom_menu"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
|
|
||||||
</androidx.appcompat.widget.Toolbar>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
Loading…
Reference in a new issue