mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Replace overflow menu with user profile or group settings icon
This commit is contained in:
parent
2816377e34
commit
b529d6d341
@ -5,7 +5,6 @@ import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.DimenRes
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
@ -18,14 +17,11 @@ import network.loki.messenger.databinding.ViewConversationSettingBinding
|
||||
import org.session.libsession.messaging.open_groups.OpenGroup
|
||||
import org.session.libsession.utilities.ExpirationUtil
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilities
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase
|
||||
import org.thoughtcrime.securesms.database.LokiAPIDatabase
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import org.thoughtcrime.securesms.util.DateUtils
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ConversationActionBarView : LinearLayout {
|
||||
@ -54,26 +50,12 @@ class ConversationActionBarView : LinearLayout {
|
||||
mediator.attach()
|
||||
}
|
||||
|
||||
fun bind(threadId: Long, recipient: Recipient, glide: GlideRequests, delegate: ConversationActionBarDelegate) {
|
||||
fun bind(recipient: Recipient, delegate: ConversationActionBarDelegate) {
|
||||
this.delegate = delegate
|
||||
binding.conversationTitleView.text = when {
|
||||
recipient.isLocalNumber -> context.getString(R.string.note_to_self)
|
||||
else -> recipient.toShortString()
|
||||
}
|
||||
@DimenRes val sizeID: Int = if (recipient.isClosedGroupRecipient) {
|
||||
R.dimen.medium_profile_picture_size
|
||||
} else {
|
||||
R.dimen.small_profile_picture_size
|
||||
}
|
||||
val size = resources.getDimension(sizeID).roundToInt()
|
||||
binding.profilePictureView.root.layoutParams = LayoutParams(size, size)
|
||||
binding.profilePictureView.root.glide = glide
|
||||
MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(threadId, context)
|
||||
binding.profilePictureView.root.update(recipient)
|
||||
update(recipient)
|
||||
}
|
||||
|
||||
fun update(recipient: Recipient) {
|
||||
binding.profilePictureView.root.update(recipient)
|
||||
binding.conversationTitleView.text = when {
|
||||
recipient.isLocalNumber -> context.getString(R.string.note_to_self)
|
||||
else -> recipient.toShortString()
|
||||
|
@ -84,6 +84,7 @@ import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.attachments.ScreenshotObserver
|
||||
import org.thoughtcrime.securesms.audio.AudioRecorder
|
||||
import org.thoughtcrime.securesms.components.ProfilePictureView
|
||||
import org.thoughtcrime.securesms.contacts.SelectContactsActivity.Companion.selectedContactsKey
|
||||
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher
|
||||
import org.thoughtcrime.securesms.conversation.ConversationActionBarDelegate
|
||||
@ -106,6 +107,7 @@ import org.thoughtcrime.securesms.conversation.v2.search.SearchBottomBar
|
||||
import org.thoughtcrime.securesms.conversation.v2.search.SearchViewModel
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.AttachmentManager
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilities
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.ResendMessageUtilities
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
@ -173,6 +175,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
ConversationMenuHelper.ConversationMenuListener {
|
||||
|
||||
private var binding: ActivityConversationV2Binding? = null
|
||||
private var overflowMenuItem: MenuItem? = null
|
||||
|
||||
@Inject lateinit var textSecurePreferences: TextSecurePreferences
|
||||
@Inject lateinit var threadDb: ThreadDatabase
|
||||
@ -357,7 +360,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
updateUnreadCountIndicator()
|
||||
setUpTypingObserver()
|
||||
setUpRecipientObserver()
|
||||
binding?.toolbarContent?.updateSubtitle(viewModel.recipient!!)
|
||||
getLatestOpenGroupInfoIfNeeded()
|
||||
setUpBlockedBanner()
|
||||
binding!!.searchBottomBar.setEventListener(this)
|
||||
@ -454,7 +456,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
actionBar.title = ""
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
actionBar.setHomeButtonEnabled(true)
|
||||
binding!!.toolbarContent.bind(viewModel.threadId, recipient, glide, this)
|
||||
binding!!.toolbarContent.bind(recipient, this)
|
||||
maybeUpdateToolbar(recipient)
|
||||
}
|
||||
|
||||
// called from onCreate
|
||||
@ -547,6 +550,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
viewModel.openGroup?.let { openGroup ->
|
||||
OpenGroupApi.getMemberCount(openGroup.room, openGroup.server).successUi {
|
||||
binding?.toolbarContent?.updateSubtitle(viewModel.recipient!!, openGroup)
|
||||
maybeUpdateToolbar(viewModel.recipient!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -612,8 +616,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
menuInflater,
|
||||
recipient,
|
||||
this
|
||||
)
|
||||
) { onOptionsItemSelected(it) }
|
||||
}
|
||||
overflowMenuItem = menu.findItem(R.id.menu_overflow)
|
||||
viewModel.recipient?.let { maybeUpdateToolbar(it) }
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
return true
|
||||
}
|
||||
@ -623,7 +629,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
tearDownRecipientObserver()
|
||||
super.onDestroy()
|
||||
binding = null
|
||||
// actionBarBinding = null
|
||||
}
|
||||
// endregion
|
||||
|
||||
@ -637,10 +642,18 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
setUpMessageRequestsBar()
|
||||
invalidateOptionsMenu()
|
||||
showOrHideInputIfNeeded()
|
||||
binding?.toolbarContent?.update(threadRecipient)
|
||||
maybeUpdateToolbar(threadRecipient)
|
||||
}
|
||||
}
|
||||
|
||||
private fun maybeUpdateToolbar(recipient: Recipient) {
|
||||
binding?.toolbarContent?.update(recipient)
|
||||
val profilePictureView = overflowMenuItem?.actionView?.findViewById<ProfilePictureView>(R.id.profilePictureView)
|
||||
profilePictureView?.glide = glide
|
||||
MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(viewModel.threadId, this)
|
||||
profilePictureView?.update(recipient)
|
||||
}
|
||||
|
||||
private fun showOrHideInputIfNeeded() {
|
||||
val recipient = viewModel.recipient
|
||||
if (recipient != null && recipient.isClosedGroupRecipient) {
|
||||
@ -909,6 +922,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
if (item.itemId == android.R.id.home) {
|
||||
return false
|
||||
}
|
||||
else if (item.itemId == R.id.menu_overflow) {
|
||||
binding?.toolbar?.showOverflowMenu()
|
||||
return false
|
||||
}
|
||||
return viewModel.recipient?.let { recipient ->
|
||||
ConversationMenuHelper.onOptionItemSelected(this, item, recipient)
|
||||
} ?: false
|
||||
|
@ -43,16 +43,25 @@ import java.io.IOException
|
||||
object ConversationMenuHelper {
|
||||
|
||||
fun onPrepareOptionsMenu(
|
||||
menu: Menu,
|
||||
mainMenu: Menu,
|
||||
inflater: MenuInflater,
|
||||
thread: Recipient,
|
||||
context: Context
|
||||
context: Context,
|
||||
onOptionsItemSelected: (MenuItem) -> Unit
|
||||
) {
|
||||
// Prepare
|
||||
menu.clear()
|
||||
mainMenu.clear()
|
||||
val isOpenGroup = thread.isOpenGroupRecipient
|
||||
// Base menu (options that should always be present)
|
||||
inflater.inflate(R.menu.menu_conversation, menu)
|
||||
inflater.inflate(R.menu.menu_conversation, mainMenu)
|
||||
val item = mainMenu.findItem(R.id.menu_overflow)
|
||||
if (thread.isGroupRecipient) {
|
||||
item.setIcon(R.drawable.ic_outline_settings_24)
|
||||
} else {
|
||||
item.setActionView(R.layout.view_profile_overflow)
|
||||
item.actionView.setOnClickListener { onOptionsItemSelected(item) }
|
||||
}
|
||||
val menu = item.subMenu
|
||||
// One-on-one chat menu (options that should only be present for one-on-one chats)
|
||||
if (thread.isContactRecipient) {
|
||||
if (thread.isBlocked) {
|
||||
|
10
app/src/main/res/drawable/ic_outline_settings_24.xml
Normal file
10
app/src/main/res/drawable/ic_outline_settings_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98 0,-0.34 -0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.09,-0.16 -0.26,-0.25 -0.44,-0.25 -0.06,0 -0.12,0.01 -0.17,0.03l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.06,-0.02 -0.12,-0.03 -0.18,-0.03 -0.17,0 -0.34,0.09 -0.43,0.25l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98 0,0.33 0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.09,0.16 0.26,0.25 0.44,0.25 0.06,0 0.12,-0.01 0.17,-0.03l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.06,0.02 0.12,0.03 0.18,0.03 0.17,0 0.34,-0.09 0.43,-0.25l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM17.45,11.27c0.04,0.31 0.05,0.52 0.05,0.73 0,0.21 -0.02,0.43 -0.05,0.73l-0.14,1.13 0.89,0.7 1.08,0.84 -0.7,1.21 -1.27,-0.51 -1.04,-0.42 -0.9,0.68c-0.43,0.32 -0.84,0.56 -1.25,0.73l-1.06,0.43 -0.16,1.13 -0.2,1.35h-1.4l-0.19,-1.35 -0.16,-1.13 -1.06,-0.43c-0.43,-0.18 -0.83,-0.41 -1.23,-0.71l-0.91,-0.7 -1.06,0.43 -1.27,0.51 -0.7,-1.21 1.08,-0.84 0.89,-0.7 -0.14,-1.13c-0.03,-0.31 -0.05,-0.54 -0.05,-0.74s0.02,-0.43 0.05,-0.73l0.14,-1.13 -0.89,-0.7 -1.08,-0.84 0.7,-1.21 1.27,0.51 1.04,0.42 0.9,-0.68c0.43,-0.32 0.84,-0.56 1.25,-0.73l1.06,-0.43 0.16,-1.13 0.2,-1.35h1.39l0.19,1.35 0.16,1.13 1.06,0.43c0.43,0.18 0.83,0.41 1.23,0.71l0.91,0.7 1.06,-0.43 1.27,-0.51 0.7,1.21 -1.07,0.85 -0.89,0.7 0.14,1.13zM12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z" />
|
||||
</vector>
|
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="?android:attr/actionButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/menu_badge_icon"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_timer"
|
||||
android:background="@color/transparent"
|
||||
android:scaleType="fitCenter"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/expiration_badge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:paddingBottom="3dp"
|
||||
android:paddingTop="1dp"
|
||||
android:background="@color/transparent"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="10sp" />
|
||||
|
||||
</FrameLayout>
|
@ -4,48 +4,34 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
<TextView
|
||||
android:id="@+id/conversationTitleView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
tools:text="@tools:sample/full_names"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
android:textSize="@dimen/large_font_size"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/conversationTitleView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="@tools:sample/full_names"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
android:textSize="@dimen/large_font_size"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end" />
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/settings_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/very_small_spacing"/>
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/settings_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/very_small_spacing"/>
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/settings_tab_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/very_small_spacing"
|
||||
app:tabBackground="@drawable/tab_indicator_dot"
|
||||
app:tabGravity="center"
|
||||
app:tabIndicator="@null"
|
||||
app:tabPaddingStart="@dimen/very_small_spacing"
|
||||
app:tabPaddingEnd="@dimen/very_small_spacing"/>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/settings_tab_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/very_small_spacing"
|
||||
app:tabBackground="@drawable/tab_indicator_dot"
|
||||
app:tabGravity="center"
|
||||
app:tabIndicator="@null"
|
||||
app:tabPaddingStart="@dimen/very_small_spacing"
|
||||
app:tabPaddingEnd="@dimen/very_small_spacing"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/view_profile_picture"
|
||||
android:id="@+id/profilePictureView"
|
||||
android:layout_width="@dimen/medium_profile_picture_size"
|
||||
android:layout_height="@dimen/medium_profile_picture_size" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
18
app/src/main/res/layout/view_profile_overflow.xml
Normal file
18
app/src/main/res/layout/view_profile_overflow.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="?android:attr/actionBarSize"
|
||||
android:layout_height="?android:attr/actionBarSize">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="@dimen/small_profile_picture_size"
|
||||
android:layout_height="@dimen/small_profile_picture_size"
|
||||
android:layout_gravity="center"
|
||||
android:background="?attr/selectableItemBackgroundBorderless">
|
||||
|
||||
<include
|
||||
android:id="@+id/profilePictureView"
|
||||
layout="@layout/view_profile_picture" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -4,17 +4,29 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:title="@string/conversation__menu_view_all_media"
|
||||
android:id="@+id/menu_view_all_media" />
|
||||
android:id="@+id/menu_overflow"
|
||||
android:icon="@drawable/ic_outline_settings_24"
|
||||
android:title="@string/conversation_context__menu_call"
|
||||
app:showAsAction="always">
|
||||
|
||||
<item
|
||||
android:title="@string/SearchToolbar_search"
|
||||
android:id="@+id/menu_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView" />
|
||||
<menu>
|
||||
|
||||
<item
|
||||
android:title="@string/conversation__menu_add_shortcut"
|
||||
android:id="@+id/menu_add_shortcut" />
|
||||
<item
|
||||
android:title="@string/conversation__menu_view_all_media"
|
||||
android:id="@+id/menu_view_all_media" />
|
||||
|
||||
<item
|
||||
android:title="@string/SearchToolbar_search"
|
||||
android:id="@+id/menu_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView" />
|
||||
|
||||
<item
|
||||
android:title="@string/conversation__menu_add_shortcut"
|
||||
android:id="@+id/menu_add_shortcut" />
|
||||
|
||||
</menu>
|
||||
|
||||
</item>
|
||||
|
||||
</menu>
|
||||
|
Loading…
x
Reference in New Issue
Block a user