Improved chat message long press popup
This commit is contained in:
parent
64f3808c9d
commit
a0f02dbb08
7 changed files with 167 additions and 82 deletions
|
@ -22,12 +22,10 @@ package org.linphone.activities.main.chat.adapters
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuInflater
|
|
||||||
import android.view.MenuItem
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.view.menu.MenuBuilder
|
import android.widget.PopupWindow
|
||||||
import androidx.appcompat.view.menu.MenuPopupHelper
|
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
@ -46,6 +44,8 @@ import org.linphone.core.Content
|
||||||
import org.linphone.core.EventLog
|
import org.linphone.core.EventLog
|
||||||
import org.linphone.databinding.ChatEventListCellBinding
|
import org.linphone.databinding.ChatEventListCellBinding
|
||||||
import org.linphone.databinding.ChatMessageListCellBinding
|
import org.linphone.databinding.ChatMessageListCellBinding
|
||||||
|
import org.linphone.databinding.ChatMessageLongPressMenuBindingImpl
|
||||||
|
import org.linphone.utils.AppUtils
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
|
||||||
class ChatMessagesListAdapter(
|
class ChatMessagesListAdapter(
|
||||||
|
@ -194,60 +194,69 @@ class ChatMessagesListAdapter(
|
||||||
if (contextMenuDisabled) return
|
if (contextMenuDisabled) return
|
||||||
|
|
||||||
setContextMenuClickListener {
|
setContextMenuClickListener {
|
||||||
val builder = MenuBuilder(root.context)
|
val popupView: ChatMessageLongPressMenuBindingImpl = DataBindingUtil.inflate(
|
||||||
val popupMenu = MenuPopupHelper(root.context, builder, background)
|
LayoutInflater.from(root.context),
|
||||||
popupMenu.setForceShowIcon(true)
|
R.layout.chat_message_long_press_menu, null, false
|
||||||
MenuInflater(root.context).inflate(R.menu.chat_message_menu, builder)
|
)
|
||||||
|
|
||||||
|
val itemSize = AppUtils.getDimension(R.dimen.chat_message_popup_item_height).toInt()
|
||||||
|
var totalSize = itemSize * 6
|
||||||
if (chatMessage.chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) ||
|
if (chatMessage.chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) ||
|
||||||
chatMessage.state == ChatMessage.State.NotDelivered) { // No message id
|
chatMessage.state == ChatMessage.State.NotDelivered) { // No message id
|
||||||
builder.removeItem(R.id.chat_message_menu_imdn_infos)
|
popupView.imdnHidden = true
|
||||||
|
totalSize -= itemSize
|
||||||
}
|
}
|
||||||
if (chatMessage.state != ChatMessage.State.NotDelivered) {
|
if (chatMessage.state != ChatMessage.State.NotDelivered) {
|
||||||
builder.removeItem(R.id.chat_message_menu_resend)
|
popupView.resendHidden = true
|
||||||
|
totalSize -= itemSize
|
||||||
}
|
}
|
||||||
if (chatMessage.contents.find { content -> content.isText } == null) {
|
if (chatMessage.contents.find { content -> content.isText } == null) {
|
||||||
builder.removeItem(R.id.chat_message_menu_copy_text)
|
popupView.copyTextHidden = true
|
||||||
|
totalSize -= itemSize
|
||||||
}
|
}
|
||||||
if (chatMessage.isOutgoing || chatMessageViewModel.contact.value != null) {
|
if (chatMessage.isOutgoing || chatMessageViewModel.contact.value != null) {
|
||||||
builder.removeItem(R.id.chat_message_menu_add_to_contacts)
|
popupView.addToContactsHidden = true
|
||||||
|
totalSize -= itemSize
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setCallback(object : MenuBuilder.Callback {
|
// When using WRAP_CONTENT instead of real size, fails to place the
|
||||||
override fun onMenuModeChange(menu: MenuBuilder) {}
|
// popup window above if not enough space is available below
|
||||||
|
val popupWindow = PopupWindow(popupView.root,
|
||||||
override fun onMenuItemSelected(menu: MenuBuilder, item: MenuItem): Boolean {
|
AppUtils.getDimension(R.dimen.chat_message_popup_width).toInt(),
|
||||||
return when (item.itemId) {
|
totalSize,
|
||||||
R.id.chat_message_menu_imdn_infos -> {
|
|
||||||
showImdnDeliveryFragment()
|
|
||||||
true
|
true
|
||||||
}
|
)
|
||||||
R.id.chat_message_menu_resend -> {
|
// Elevation is for showing a shadow around the popup
|
||||||
|
popupWindow.elevation = 20f
|
||||||
|
|
||||||
|
popupView.setResendClickListener {
|
||||||
resendMessage()
|
resendMessage()
|
||||||
true
|
popupWindow.dismiss()
|
||||||
}
|
}
|
||||||
R.id.chat_message_menu_copy_text -> {
|
popupView.setCopyTextClickListener {
|
||||||
copyTextToClipboard()
|
copyTextToClipboard()
|
||||||
true
|
popupWindow.dismiss()
|
||||||
}
|
}
|
||||||
R.id.chat_message_forward_message -> {
|
popupView.setForwardClickListener {
|
||||||
forwardMessage()
|
forwardMessage()
|
||||||
true
|
popupWindow.dismiss()
|
||||||
}
|
}
|
||||||
R.id.chat_message_menu_delete_message -> {
|
popupView.setImdnClickListener {
|
||||||
deleteMessage()
|
showImdnDeliveryFragment()
|
||||||
true
|
popupWindow.dismiss()
|
||||||
}
|
}
|
||||||
R.id.chat_message_menu_add_to_contacts -> {
|
popupView.setAddToContactsClickListener {
|
||||||
addSenderToContacts()
|
addSenderToContacts()
|
||||||
true
|
popupWindow.dismiss()
|
||||||
}
|
}
|
||||||
else -> false
|
popupView.setDeleteClickListener {
|
||||||
|
deleteMessage()
|
||||||
|
popupWindow.dismiss()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
popupMenu.show()
|
val gravity = if (chatMessage.isOutgoing) Gravity.END else Gravity.START
|
||||||
|
popupWindow.showAsDropDown(background, 0, 0, gravity or Gravity.TOP)
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.linphone.core.tools.Log
|
||||||
|
|
||||||
class AudioRouteUtils {
|
class AudioRouteUtils {
|
||||||
companion object {
|
companion object {
|
||||||
private fun routeAudioTo(types : List<AudioDevice.Type>, call: Call? = null) {
|
private fun routeAudioTo(types: List<AudioDevice.Type>, call: Call? = null) {
|
||||||
val listSize = types.size
|
val listSize = types.size
|
||||||
val stringBuilder = StringBuilder()
|
val stringBuilder = StringBuilder()
|
||||||
var index = 0
|
var index = 0
|
||||||
|
|
BIN
app/src/main/res/drawable-xhdpi/menu_delete.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/menu_delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
100
app/src/main/res/layout/chat_message_long_press_menu.xml
Normal file
100
app/src/main/res/layout/chat_message_long_press_menu.xml
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<import type="android.view.View" />
|
||||||
|
<variable
|
||||||
|
name="resendClickListener"
|
||||||
|
type="View.OnClickListener" />
|
||||||
|
<variable
|
||||||
|
name="copyTextClickListener"
|
||||||
|
type="View.OnClickListener" />
|
||||||
|
<variable
|
||||||
|
name="forwardClickListener"
|
||||||
|
type="View.OnClickListener" />
|
||||||
|
<variable
|
||||||
|
name="imdnClickListener"
|
||||||
|
type="View.OnClickListener" />
|
||||||
|
<variable
|
||||||
|
name="addToContactsClickListener"
|
||||||
|
type="View.OnClickListener" />
|
||||||
|
<variable
|
||||||
|
name="deleteClickListener"
|
||||||
|
type="View.OnClickListener" />
|
||||||
|
<variable
|
||||||
|
name="resendHidden"
|
||||||
|
type="Boolean" />
|
||||||
|
<variable
|
||||||
|
name="imdnHidden"
|
||||||
|
type="Boolean" />
|
||||||
|
<variable
|
||||||
|
name="copyTextHidden"
|
||||||
|
type="Boolean" />
|
||||||
|
<variable
|
||||||
|
name="addToContactsHidden"
|
||||||
|
type="Boolean" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="@dimen/chat_message_popup_width"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="?attr/backgroundColor">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||||
|
android:visibility="@{resendHidden ? View.GONE : View.VISIBLE}"
|
||||||
|
android:onClick="@{resendClickListener}"
|
||||||
|
android:drawableRight="@drawable/chat_send_message"
|
||||||
|
style="@style/popup_item_font"
|
||||||
|
android:text="@string/chat_message_context_menu_resend" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||||
|
android:visibility="@{copyTextHidden ? View.GONE : View.VISIBLE}"
|
||||||
|
android:onClick="@{copyTextClickListener}"
|
||||||
|
android:drawableRight="@drawable/menu_copy_text"
|
||||||
|
style="@style/popup_item_font"
|
||||||
|
android:text="@string/chat_message_context_menu_copy_text" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||||
|
android:onClick="@{forwardClickListener}"
|
||||||
|
android:drawableRight="@drawable/menu_forward"
|
||||||
|
style="@style/popup_item_font"
|
||||||
|
android:text="@string/chat_message_context_menu_forward" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||||
|
android:visibility="@{imdnHidden ? View.GONE : View.VISIBLE}"
|
||||||
|
android:onClick="@{imdnClickListener}"
|
||||||
|
android:drawableRight="@drawable/menu_imdn_info"
|
||||||
|
style="@style/popup_item_font"
|
||||||
|
android:text="@string/chat_message_context_menu_imdn_info" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||||
|
android:visibility="@{addToContactsHidden ? View.GONE : View.VISIBLE}"
|
||||||
|
android:onClick="@{addToContactsClickListener}"
|
||||||
|
android:drawableRight="@drawable/menu_add_contact"
|
||||||
|
style="@style/popup_item_font"
|
||||||
|
android:text="@string/chat_message_context_menu_add_to_contacts" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||||
|
android:onClick="@{deleteClickListener}"
|
||||||
|
android:drawableRight="@drawable/menu_delete"
|
||||||
|
android:drawableTint="@color/red_color"
|
||||||
|
style="@style/popup_item_font"
|
||||||
|
android:textColor="@color/red_color"
|
||||||
|
android:text="@string/chat_message_context_menu_delete" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</layout>
|
|
@ -1,34 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/chat_message_menu_resend"
|
|
||||||
android:icon="@drawable/chat_send_message"
|
|
||||||
android:title="@string/chat_message_context_menu_resend" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/chat_message_menu_copy_text"
|
|
||||||
android:icon="@drawable/menu_copy_text"
|
|
||||||
android:title="@string/chat_message_context_menu_copy_text" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/chat_message_forward_message"
|
|
||||||
android:icon="@drawable/menu_forward"
|
|
||||||
android:title="@string/chat_message_context_menu_forward" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/chat_message_menu_imdn_infos"
|
|
||||||
android:icon="@drawable/menu_imdn_info"
|
|
||||||
android:title="@string/chat_message_context_menu_imdn_info" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/chat_message_menu_delete_message"
|
|
||||||
android:icon="@drawable/menu_delete"
|
|
||||||
android:title="@string/chat_message_context_menu_delete" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/chat_message_menu_add_to_contacts"
|
|
||||||
android:icon="@drawable/menu_add_contact"
|
|
||||||
android:title="@string/chat_message_context_menu_add_to_contacts" />
|
|
||||||
|
|
||||||
</menu>
|
|
|
@ -11,7 +11,7 @@
|
||||||
<dimen name="chat_message_bubble_file_icon_size">30dp</dimen>
|
<dimen name="chat_message_bubble_file_icon_size">30dp</dimen>
|
||||||
<dimen name="chat_message_bubble_desired_height">600dp</dimen>
|
<dimen name="chat_message_bubble_desired_height">600dp</dimen>
|
||||||
<dimen name="video_preview_max_size">200dp</dimen>
|
<dimen name="video_preview_max_size">200dp</dimen>
|
||||||
<dimen name="video_preview_pip_max_size">50dp</dimen>
|
<dimen name="video_preview_pip_max_size">45dp</dimen>
|
||||||
<dimen name="main_activity_tabs_fragment_size">60dp</dimen>
|
<dimen name="main_activity_tabs_fragment_size">60dp</dimen>
|
||||||
<dimen name="main_activity_top_bar_size">60dp</dimen>
|
<dimen name="main_activity_top_bar_size">60dp</dimen>
|
||||||
<dimen name="status_fragment_size">40dp</dimen>
|
<dimen name="status_fragment_size">40dp</dimen>
|
||||||
|
@ -24,4 +24,6 @@
|
||||||
<dimen name="field_button_size">20dp</dimen>
|
<dimen name="field_button_size">20dp</dimen>
|
||||||
<dimen name="field_shape_margin">3dp</dimen>
|
<dimen name="field_shape_margin">3dp</dimen>
|
||||||
<dimen name="call_overlay_size">60dp</dimen>
|
<dimen name="call_overlay_size">60dp</dimen>
|
||||||
|
<dimen name="chat_message_popup_width">250dp</dimen>
|
||||||
|
<dimen name="chat_message_popup_item_height">50dp</dimen>
|
||||||
</resources>
|
</resources>
|
|
@ -169,6 +169,14 @@
|
||||||
<item name="android:lineSpacingExtra">8.3sp</item>
|
<item name="android:lineSpacingExtra">8.3sp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="popup_item_font" parent="@android:style/TextAppearance.Medium">
|
||||||
|
<item name="android:textColor">?attr/primaryTextColor</item>
|
||||||
|
<item name="android:textSize">16sp</item>
|
||||||
|
<item name="android:gravity">center_vertical</item>
|
||||||
|
<item name="android:paddingLeft">20dp</item>
|
||||||
|
<item name="android:paddingRight">20dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
|
|
||||||
<style name="settings_category_font" parent="@android:style/TextAppearance.Medium">
|
<style name="settings_category_font" parent="@android:style/TextAppearance.Medium">
|
||||||
|
|
Loading…
Reference in a new issue