mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 17:27:45 +00:00
Implement basic action mode menu
This commit is contained in:
parent
36ba931402
commit
3a4ab06df4
@ -0,0 +1,27 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2
|
||||
|
||||
import android.view.ActionMode
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import network.loki.messenger.R
|
||||
|
||||
class ConversationActionModeCallback : ActionMode.Callback {
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
val inflater = mode.menuInflater
|
||||
inflater.inflate(R.menu.conversation_item_action_menu, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode) {
|
||||
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.conversation.v2
|
||||
import android.database.Cursor
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.ActionMode
|
||||
import android.view.Menu
|
||||
import androidx.loader.app.LoaderManager
|
||||
import androidx.loader.content.Loader
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
@ -19,7 +21,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
|
||||
|
||||
private val adapter by lazy {
|
||||
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
|
||||
val adapter = ConversationAdapter(this, cursor)
|
||||
val adapter = ConversationAdapter(this, cursor) { handleLongPress(it) }
|
||||
adapter.setHasStableIds(true)
|
||||
adapter
|
||||
}
|
||||
@ -89,5 +91,14 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
|
||||
private fun reply(messagePosition: Int) {
|
||||
Log.d("Loki", "Reply to message at position: $messagePosition.")
|
||||
}
|
||||
|
||||
private fun handleLongPress(messagePosition: Int) {
|
||||
val actionModeCallback = ConversationActionModeCallback()
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
startActionMode(actionModeCallback, ActionMode.TYPE_PRIMARY)
|
||||
} else {
|
||||
startActionMode(actionModeCallback)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
}
|
@ -11,7 +11,8 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class ConversationAdapter(context: Context, cursor: Cursor) : CursorRecyclerViewAdapter<ViewHolder>(context, cursor) {
|
||||
class ConversationAdapter(context: Context, cursor: Cursor, private val onItemLongPress: (Int) -> Unit)
|
||||
: CursorRecyclerViewAdapter<ViewHolder>(context, cursor) {
|
||||
private val messageDB = DatabaseFactory.getMmsSmsDatabase(context)
|
||||
|
||||
sealed class ViewType(val rawValue: Int) {
|
||||
@ -55,7 +56,14 @@ class ConversationAdapter(context: Context, cursor: Cursor) : CursorRecyclerView
|
||||
override fun onBindItemViewHolder(viewHolder: ViewHolder, cursor: Cursor) {
|
||||
val message = getMessage(cursor)!!
|
||||
when (viewHolder) {
|
||||
is VisibleMessageViewHolder -> viewHolder.view.bind(message)
|
||||
is VisibleMessageViewHolder -> {
|
||||
val view = viewHolder.view
|
||||
view.bind(message)
|
||||
view.setOnLongClickListener {
|
||||
onItemLongPress(viewHolder.adapterPosition)
|
||||
true
|
||||
}
|
||||
}
|
||||
is ControlMessageViewHolder -> viewHolder.view.bind(message)
|
||||
}
|
||||
}
|
||||
|
21
app/src/main/res/menu/conversation_item_action_menu.xml
Normal file
21
app/src/main/res/menu/conversation_item_action_menu.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:icon="@drawable/ic_baseline_delete_24"
|
||||
android:title="Title"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:icon="@drawable/ic_baseline_delete_24"
|
||||
android:title="Title"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:icon="@drawable/ic_baseline_delete_24"
|
||||
android:title="Title"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
Loading…
x
Reference in New Issue
Block a user