add floating contextual menu at some setting screens

This commit is contained in:
tibbi 2022-05-09 22:18:21 +02:00
parent 6dd16cfe16
commit 50f6bb5871
2 changed files with 63 additions and 7 deletions

View file

@ -1,10 +1,10 @@
package com.simplemobiletools.gallery.pro.adapters
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.view.*
import android.widget.PopupMenu
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.getPopupMenuTheme
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.MyRecyclerView
@ -66,9 +66,46 @@ class ManageFoldersAdapter(
text = folder
setTextColor(context.getProperTextColor())
}
overflow_menu_icon.drawable.apply {
mutate()
setTint(activity.getProperTextColor())
}
overflow_menu_icon.setOnClickListener {
showPopupMenu(overflow_menu_anchor, folder)
}
}
}
private fun showPopupMenu(view: View, folder: String) {
finishActMode()
val theme = activity.getPopupMenuTheme()
val contextTheme = ContextThemeWrapper(activity, theme)
PopupMenu(contextTheme, view, Gravity.END).apply {
inflate(getActionMenuId())
setOnMenuItemClickListener { item ->
val eventTypeId = folder.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() {
val removeFolders = ArrayList<String>(selectedKeys.size)
val positions = getSelectedItemPositions()

View file

@ -1,6 +1,6 @@
<?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_folder_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -8,13 +8,32 @@
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector"
android:padding="@dimen/activity_margin">
android:paddingStart="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/manage_folder_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/medium_margin"/>
android:layout_marginTop="@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>