Merge pull request #586 from Naveen3Singh/add_floating_menu

Add "Remove" context menu option in favorites
This commit is contained in:
Tibor Kaputa 2022-05-27 22:51:40 +02:00 committed by GitHub
commit 5e8a1dc308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 10 deletions

View File

@ -1,10 +1,10 @@
package com.simplemobiletools.filemanager.pro.adapters package com.simplemobiletools.filemanager.pro.adapters
import android.view.Menu import android.view.*
import android.view.View import android.widget.PopupMenu
import android.view.ViewGroup
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.getPopupMenuTheme
import com.simplemobiletools.commons.extensions.getProperTextColor import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
@ -65,14 +65,50 @@ class ManageFavoritesAdapter(
} }
manage_favorite_holder?.isSelected = isSelected manage_favorite_holder?.isSelected = isSelected
overflow_menu_icon.drawable.apply {
mutate()
setTint(activity.getProperTextColor())
}
overflow_menu_icon.setOnClickListener {
showPopupMenu(overflow_menu_anchor, favorite)
}
} }
} }
private fun showPopupMenu(view: View, favorite: String) {
finishActMode()
val theme = activity.getPopupMenuTheme()
val contextTheme = ContextThemeWrapper(activity, theme)
PopupMenu(contextTheme, view, Gravity.END).apply {
inflate(getActionMenuId())
setOnMenuItemClickListener { item ->
val eventTypeId = favorite.hashCode()
when (item.itemId) {
R.id.cab_remove -> {
executeItemMenuOperation(eventTypeId) {
removeSelection()
}
}
}
true
}
show()
}
}
private fun executeItemMenuOperation(eventTypeId: Int, callback: () -> Unit) {
selectedKeys.clear()
selectedKeys.add(eventTypeId)
callback()
}
private fun removeSelection() { private fun removeSelection() {
val removeFavorites = ArrayList<String>(selectedKeys.size) val removeFavorites = ArrayList<String>(selectedKeys.size)
val positions = ArrayList<Int>() val positions = ArrayList<Int>()
selectedKeys.forEach { selectedKeys.forEach { key ->
val key = it
val position = favorites.indexOfFirst { it.hashCode() == key } val position = favorites.indexOfFirst { it.hashCode() == key }
if (position != -1) { if (position != -1) {
positions.add(position) positions.add(position)
@ -88,7 +124,7 @@ class ManageFavoritesAdapter(
positions.sortDescending() positions.sortDescending()
removeSelectedItems(positions) removeSelectedItems(positions)
favorites.removeAll(removeFavorites) favorites.removeAll(removeFavorites.toSet())
if (favorites.isEmpty()) { if (favorites.isEmpty()) {
listener?.refreshItems() listener?.refreshItems()
} }

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/manage_favorites_wrapper" android:id="@+id/manage_favorites_wrapper"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -10,7 +11,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clipToPadding="false" android:clipToPadding="false"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" /> app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"
tools:itemCount="4"
tools:listitem="@layout/item_manage_favorite" />
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/manage_favorites_placeholder" android:id="@+id/manage_favorites_placeholder"

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/manage_favorite_holder" android:id="@+id/manage_favorite_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -7,15 +8,33 @@
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:foreground="@drawable/selector" android:foreground="@drawable/selector"
android:padding="@dimen/activity_margin"> android:paddingStart="@dimen/activity_margin"
android:paddingEnd="0dp">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/manage_favorite_title" android:id="@+id/manage_favorite_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginStart="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin" android:layout_marginTop="@dimen/medium_margin"
android:layout_marginEnd="@dimen/medium_margin" /> android:layout_toStartOf="@+id/overflow_menu_icon"
tools:text="/Internal/DCIM" />
<ImageView
android:id="@+id/overflow_menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_three_dots_vector" />
<View
android:id="@+id/overflow_menu_anchor"
style="@style/OverflowMenuAnchorStyle"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true" />
</RelativeLayout> </RelativeLayout>