Populate conversation menu

This commit is contained in:
nielsandriesse 2021-06-07 09:48:01 +10:00
parent 3a4ab06df4
commit d465fecf4c
12 changed files with 180 additions and 30 deletions

View File

@ -1,10 +1,16 @@
package org.thoughtcrime.securesms.conversation.v2
import android.database.Cursor
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Bundle
import android.util.Log
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
import androidx.recyclerview.widget.ItemTouchHelper
@ -12,8 +18,10 @@ import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_conversation_v2.*
import kotlinx.android.synthetic.main.activity_conversation_v2_action_bar.*
import network.loki.messenger.R
import org.session.libsession.utilities.ExpirationUtil
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
import org.thoughtcrime.securesms.mms.GlideApp
class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
@ -53,7 +61,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
layoutManager.reverseLayout = true
layoutManager.stackFromEnd = true
conversationRecyclerView.layoutManager = layoutManager
// Workaround for the fact that CursorRecyclerViewAdapter doesn't actually auto-update automatically (even though it says it will)
// Workaround for the fact that CursorRecyclerViewAdapter doesn't auto-update automatically (even though it says it will)
LoaderManager.getInstance(this).restartLoader(0, null, object : LoaderManager.LoaderCallbacks<Cursor> {
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<Cursor> {
@ -81,11 +89,55 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
profilePictureView.glide = glide
profilePictureView.update(thread, threadID)
}
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
// Prepare
menu.clear()
val isOpenGroup = thread.isOpenGroupRecipient
// Base menu (options that should always be present)
menuInflater.inflate(R.menu.menu_conversation, menu)
// Expiring messages
if (!isOpenGroup) {
if (thread.expireMessages > 0) {
menuInflater.inflate(R.menu.menu_conversation_expiration_on, menu)
val item = menu.findItem(R.id.menu_expiring_messages)
val actionView = item.actionView
val iconView = actionView.findViewById<ImageView>(R.id.menu_badge_icon)
val badgeView = actionView.findViewById<TextView>(R.id.expiration_badge)
@ColorInt val color = resources.getColorWithID(R.color.text, theme)
iconView.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY)
badgeView.text = ExpirationUtil.getExpirationAbbreviatedDisplayValue(this, thread.expireMessages)
actionView.setOnClickListener { onOptionsItemSelected(item) }
} else {
menuInflater.inflate(R.menu.menu_conversation_expiration_off, menu)
}
}
// One-on-one chat menu (options that should only be present for one-on-one chats)
if (thread.isContactRecipient) {
if (thread.isBlocked) {
menuInflater.inflate(R.menu.menu_conversation_unblock, menu)
} else {
menuInflater.inflate(R.menu.menu_conversation_block, menu)
}
menuInflater.inflate(R.menu.menu_conversation_copy_session_id, menu)
}
// Closed group menu (options that should only be present in closed groups)
if (thread.isClosedGroupRecipient) {
menuInflater.inflate(R.menu.menu_conversation_closed_group, menu)
}
// Open group menu
if (isOpenGroup) {
menuInflater.inflate(R.menu.menu_conversation_open_group, menu)
}
// Return
return true
}
// endregion
// region Interaction
private fun showConversationSettings() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// TODO: Implement
return super.onOptionsItemSelected(item)
}
private fun reply(messagePosition: Int) {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/actionButtonStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -9,23 +9,24 @@
android:gravity="center">
<ImageView
android:id="@+id/menu_badge_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="@drawable/ic_timer"
android:background="@color/transparent"
android:scaleType="fitCenter"/>
android:id="@+id/menu_badge_icon"
android:layout_width="20dp"
android:layout_height="20dp"
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="@color/text"
android:textSize="10sp" />
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="@color/text"
android:textSize="10sp" />
</FrameLayout>

View File

@ -11,9 +11,9 @@
<item android:title="@string/SearchToolbar_search"
android:id="@+id/menu_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView"/>
app:showAsAction="collapseActionView" />
<item android:title="@string/conversation__menu_add_shortcut"
android:id="@+id/menu_add_shortcut"/>
android:id="@+id/menu_add_shortcut" />
</menu>

View File

@ -0,0 +1,20 @@
<?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: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>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="@string/recipient_preferences__block"
android:id="@+id/menu_block" />
</menu>

View File

@ -0,0 +1,16 @@
<?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:id="@+id/menu_edit_group"
android:title="@string/conversation__menu_edit_group"
app:showAsAction="collapseActionView" />
<item
android:id="@+id/menu_leave_group"
android:title="@string/conversation__menu_leave_group"
app:showAsAction="collapseActionView"/>
</menu>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="@string/activity_conversation_menu_copy_session_id"
android:id="@+id/menu_copy_session_id"
android:icon="@drawable/ic_content_copy_white_24dp" />
</menu>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="@string/conversation_expiring_off__disappearing_messages"
android:id="@+id/menu_expiring_messages_off"
android:icon="@drawable/ic_baseline_timer_off_24" />
</menu>

View File

@ -0,0 +1,12 @@
<?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:id="@+id/menu_expiring_messages"
app:actionLayout="@layout/expiration_timer_menu"
app:showAsAction="always"
android:title="@string/menu_conversation_expiring_on__messages_expiring" />
</menu>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="@string/ConversationActivity_invite_to_open_group"
android:id="@+id/menu_invite_to_open_group" />
</menu>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="@string/ConversationActivity_unblock"
android:id="@+id/menu_unblock" />
</menu>

View File

@ -410,10 +410,19 @@ public class Recipient implements RecipientModifiedListener {
return address.isGroup();
}
public boolean isContactRecipient() {
return address.isContact();
}
public boolean isOpenGroupRecipient() {
return address.isOpenGroup();
}
public boolean isClosedGroupRecipient() {
return address.isClosedGroup();
}
@Deprecated
public boolean isPushGroupRecipient() {
return address.isGroup();
}
@ -455,13 +464,6 @@ public class Recipient implements RecipientModifiedListener {
return (new TransparentContactPhoto()).asDrawable(context, getColor().toAvatarColor(context), inverted);
}
// public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() {
// // TODO: I believe this is now completely unused
// if (isResolving()) return new TransparentContactPhoto();
// else if (isGroupRecipient()) return new GeneratedContactPhoto(name, R.drawable.ic_profile_default);
// else { return new TransparentContactPhoto(); }
// }
public synchronized @Nullable ContactPhoto getContactPhoto() {
if (isLocalNumber) return new ProfileContactPhoto(address, String.valueOf(TextSecurePreferences.getProfileAvatarId(context)));
else if (isGroupRecipient() && groupAvatarId != null) return new GroupRecordContactPhoto(address, groupAvatarId);