Revert from using the bottom action menu

This commit is contained in:
darthpaul 2022-02-05 06:39:17 +00:00
parent 8f22f91a00
commit 17aeffe6d7
5 changed files with 32 additions and 51 deletions

View file

@ -1,13 +1,13 @@
package com.simplemobiletools.commons.adapters
import android.util.TypedValue
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.getTextSize
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuView
import kotlinx.android.synthetic.main.filepicker_favorite.view.*
class FilepickerFavoritesAdapter(
@ -35,7 +35,7 @@ class FilepickerFavoritesAdapter(
override fun getItemCount() = paths.size
override fun onBottomActionMenuCreated(view: BottomActionMenuView) {}
override fun prepareActionMode(menu: Menu) {}
override fun actionItemPressed(id: Int) {}

View file

@ -3,6 +3,7 @@ package com.simplemobiletools.commons.adapters
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
@ -18,7 +19,6 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.getFilePlaceholderDrawables
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuView
import kotlinx.android.synthetic.main.item_filepicker_list.view.*
import java.util.*
@ -55,7 +55,7 @@ class FilepickerItemsAdapter(
override fun getItemCount() = fileDirItems.size
override fun onBottomActionMenuCreated(view: BottomActionMenuView) {}
override fun prepareActionMode(menu: Menu) {}
override fun actionItemPressed(id: Int) {}

View file

@ -1,5 +1,6 @@
package com.simplemobiletools.commons.adapters
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.commons.R
@ -9,7 +10,6 @@ import com.simplemobiletools.commons.extensions.deleteBlockedNumber
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.models.BlockedNumber
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuView
import kotlinx.android.synthetic.main.item_manage_blocked_number.view.*
import java.util.*
@ -23,8 +23,10 @@ class ManageBlockedNumbersAdapter(
override fun getActionMenuId() = R.menu.cab_blocked_numbers
override fun onBottomActionMenuCreated(view: BottomActionMenuView) {
view.toggleItemVisibility(R.id.cab_copy_number, isOneItemSelected())
override fun prepareActionMode(menu: Menu) {
menu.apply {
findItem(R.id.cab_copy_number).isVisible = isOneItemSelected()
}
}
override fun actionItemPressed(id: Int) {

View file

@ -16,10 +16,6 @@ import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getContrastColor
import com.simplemobiletools.commons.interfaces.MyActionModeCallback
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuCallback
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuItem
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuPopup
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuView
import java.util.*
abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyclerView: MyRecyclerView, val itemClick: (Any) -> Unit) :
@ -36,15 +32,13 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
protected var selectedKeys = LinkedHashSet<Int>()
protected var positionOffset = 0
protected var actMode: ActionMode? = null
protected var contextCallback: BottomActionMenuCallback? = null
protected var contextPopup: BottomActionMenuPopup? = null
private var actBarTextView: TextView? = null
private var lastLongPressedItem = -1
abstract fun getActionMenuId(): Int
abstract fun onBottomActionMenuCreated(view: BottomActionMenuView)
abstract fun prepareActionMode(menu: Menu)
abstract fun actionItemPressed(id: Int)
@ -63,22 +57,17 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
protected fun isOneItemSelected() = selectedKeys.size == 1
init {
contextCallback = object : BottomActionMenuCallback {
override fun onViewCreated(view: BottomActionMenuView) {
onBottomActionMenuCreated(view)
}
override fun onItemClicked(item: BottomActionMenuItem) {
actionItemPressed(item.id)
}
}
actModeCallback = object : MyActionModeCallback() {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
return false
actionItemPressed(item.itemId)
return true
}
override fun onCreateActionMode(actionMode: ActionMode, menu: Menu?): Boolean {
if (getActionMenuId() == 0) {
return true
}
isSelectable = true
actMode = actionMode
actBarTextView = layoutInflater.inflate(R.layout.actionbar_title, null) as TextView
@ -91,17 +80,18 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
selectAll()
}
}
activity.menuInflater.inflate(getActionMenuId(), menu)
onActionModeCreated()
return true
}
override fun onPrepareActionMode(actionMode: ActionMode, menu: Menu): Boolean {
return false
prepareActionMode(menu)
return true
}
override fun onDestroyActionMode(actionMode: ActionMode) {
isSelectable = false
contextPopup?.dismiss()
(selectedKeys.clone() as HashSet<Int>).forEach {
val position = getItemKeyPosition(it)
if (position != -1) {
@ -153,7 +143,6 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
if (oldTitle != newTitle) {
actBarTextView?.text = newTitle
actMode?.invalidate()
contextPopup?.invalidate()
}
}
@ -340,7 +329,6 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
val currentPosition = adapterPosition - positionOffset
if (!actModeCallback.isSelectable) {
activity.startSupportActionMode(actModeCallback)
contextPopup = BottomActionMenuPopup(activity, getActionMenuId()).also { it.show(contextCallback, recyclerView) }
}
toggleItemSelection(true, currentPosition, true)

View file

@ -18,10 +18,6 @@ import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getContrastColor
import com.simplemobiletools.commons.interfaces.MyActionModeCallback
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuCallback
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuItem
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuPopup
import com.simplemobiletools.commons.views.bottomactionmenu.BottomActionMenuView
import java.util.*
abstract class MyRecyclerViewListAdapter<T>(
@ -43,15 +39,13 @@ abstract class MyRecyclerViewListAdapter<T>(
protected var selectedKeys = LinkedHashSet<Int>()
protected var positionOffset = 0
protected var actMode: ActionMode? = null
protected var contextCallback: BottomActionMenuCallback? = null
protected var contextPopup: BottomActionMenuPopup? = null
private var actBarTextView: TextView? = null
private var lastLongPressedItem = -1
abstract fun getActionMenuId(): Int
abstract fun onBottomActionMenuCreated(view: BottomActionMenuView)
abstract fun prepareActionMode(menu: Menu)
abstract fun actionItemPressed(id: Int)
@ -63,27 +57,24 @@ abstract class MyRecyclerViewListAdapter<T>(
abstract fun getItemKeyPosition(key: Int): Int
abstract fun onActionModeCreated()
abstract fun onActionModeDestroyed()
protected fun isOneItemSelected() = selectedKeys.size == 1
init {
contextCallback = object : BottomActionMenuCallback {
override fun onViewCreated(view: BottomActionMenuView) {
onBottomActionMenuCreated(view)
}
override fun onItemClicked(item: BottomActionMenuItem) {
actionItemPressed(item.id)
}
}
actModeCallback = object : MyActionModeCallback() {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
return false
actionItemPressed(item.itemId)
return true
}
override fun onCreateActionMode(actionMode: ActionMode, menu: Menu?): Boolean {
if (getActionMenuId() == 0) {
return true
}
isSelectable = true
actMode = actionMode
actBarTextView = layoutInflater.inflate(R.layout.actionbar_title, null) as TextView
@ -96,16 +87,18 @@ abstract class MyRecyclerViewListAdapter<T>(
selectAll()
}
}
activity.menuInflater.inflate(getActionMenuId(), menu)
onActionModeCreated()
return true
}
override fun onPrepareActionMode(actionMode: ActionMode, menu: Menu): Boolean {
return false
prepareActionMode(menu)
return true
}
override fun onDestroyActionMode(actionMode: ActionMode) {
isSelectable = false
contextPopup?.dismiss()
(selectedKeys.clone() as HashSet<Int>).forEach {
val position = getItemKeyPosition(it)
if (position != -1) {
@ -157,7 +150,6 @@ abstract class MyRecyclerViewListAdapter<T>(
if (oldTitle != newTitle) {
actBarTextView?.text = newTitle
actMode?.invalidate()
contextPopup?.invalidate()
}
}
@ -344,7 +336,6 @@ abstract class MyRecyclerViewListAdapter<T>(
val currentPosition = adapterPosition - positionOffset
if (!actModeCallback.isSelectable) {
activity.startSupportActionMode(actModeCallback)
contextPopup = BottomActionMenuPopup(activity, getActionMenuId()).also { it.show(contextCallback, recyclerView) }
}
toggleItemSelection(true, currentPosition, true)