add floating contextual menu at files
This commit is contained in:
parent
6ea4330c66
commit
d7b8a109fd
2 changed files with 76 additions and 7 deletions
|
@ -2,9 +2,8 @@ package com.simplemobiletools.voicerecorder.adapters
|
|||
|
||||
import android.provider.MediaStore
|
||||
import android.provider.MediaStore.Audio.Media
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.*
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
|
@ -22,7 +21,6 @@ import com.simplemobiletools.voicerecorder.interfaces.RefreshRecordingsListener
|
|||
import com.simplemobiletools.voicerecorder.models.Recording
|
||||
import kotlinx.android.synthetic.main.item_recording.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class RecordingsAdapter(
|
||||
activity: SimpleActivity,
|
||||
|
@ -207,8 +205,61 @@ class RecordingsAdapter(
|
|||
recording_date.text = recording.timestamp.formatDate(context)
|
||||
recording_duration.text = recording.duration.getFormattedDuration()
|
||||
recording_size.text = recording.size.formatSize()
|
||||
|
||||
overflow_menu_icon.drawable.apply {
|
||||
mutate()
|
||||
setTint(activity.getProperTextColor())
|
||||
}
|
||||
|
||||
overflow_menu_icon.setOnClickListener {
|
||||
showPopupMenu(overflow_menu_anchor, recording)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onChange(position: Int) = recordings.getOrNull(position)?.title ?: ""
|
||||
|
||||
private fun showPopupMenu(view: View, recording: Recording) {
|
||||
finishActMode()
|
||||
val theme = activity.getPopupMenuTheme()
|
||||
val contextTheme = ContextThemeWrapper(activity, theme)
|
||||
|
||||
PopupMenu(contextTheme, view, Gravity.END).apply {
|
||||
inflate(R.menu.cab_recordings)
|
||||
setOnMenuItemClickListener { item ->
|
||||
val recordingId = recording.id
|
||||
when (item.itemId) {
|
||||
R.id.cab_rename -> {
|
||||
executeItemMenuOperation(recordingId) {
|
||||
renameRecording()
|
||||
}
|
||||
}
|
||||
R.id.cab_share -> {
|
||||
executeItemMenuOperation(recordingId) {
|
||||
shareRecordings()
|
||||
}
|
||||
}
|
||||
R.id.cab_open_with -> {
|
||||
executeItemMenuOperation(recordingId) {
|
||||
openRecordingWith()
|
||||
}
|
||||
}
|
||||
R.id.cab_delete -> {
|
||||
executeItemMenuOperation(recordingId) {
|
||||
deleteMediaStoreRecordings()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun executeItemMenuOperation(callId: Int, callback: () -> Unit) {
|
||||
selectedKeys.add(callId)
|
||||
callback()
|
||||
selectedKeys.remove(callId)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
android:id="@+id/item_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin">
|
||||
android:paddingTop="15dp"
|
||||
android:paddingBottom="15dp"
|
||||
android:paddingStart="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recording_title"
|
||||
|
@ -45,7 +47,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/recording_title"
|
||||
android:layout_alignBottom="@+id/recording_title"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_toStartOf="@+id/overflow_menu_icon"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
|
@ -58,7 +60,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/recording_date"
|
||||
android:layout_alignBottom="@+id/recording_date"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_toStartOf="@+id/overflow_menu_icon"
|
||||
android:alpha="0.6"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
|
@ -66,5 +68,21 @@
|
|||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text="3 MB" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/overflow_menu_icon"
|
||||
style="@style/OverflowMenuIconStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:visibility="visible" />
|
||||
|
||||
<View
|
||||
android:id="@+id/overflow_menu_anchor"
|
||||
style="@style/OverflowMenuAnchorStyle"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in a new issue