From a23cfbc11d290a41ed9dd635ed793c1005a7fdfb Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Tue, 1 Jun 2021 13:01:03 +1000 Subject: [PATCH] Implement parts of the visible message view --- .../v2/messages/ControlMessageView.kt | 8 ++- .../v2/messages/VisibleMessageView.kt | 27 ++++++- .../drawable/message_bubble_background.xml | 1 - ...ssage_bubble_background_received_alone.xml | 1 - ...message_bubble_background_received_end.xml | 1 - ...sage_bubble_background_received_middle.xml | 1 - ...ssage_bubble_background_received_start.xml | 1 - .../message_bubble_background_sent_alone.xml | 1 - .../message_bubble_background_sent_end.xml | 1 - .../message_bubble_background_sent_middle.xml | 1 - .../message_bubble_background_sent_start.xml | 1 - .../main/res/layout/view_control_message.xml | 7 +- .../main/res/layout/view_visible_message.xml | 71 ++++++++++++++++--- 13 files changed, 97 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt index f7e23bc19b..1de54f89f6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt @@ -4,7 +4,7 @@ import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater import android.widget.LinearLayout -import kotlinx.android.synthetic.main.view_visible_message.view.* +import kotlinx.android.synthetic.main.view_control_message.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.database.model.MessageRecord @@ -30,7 +30,11 @@ class ControlMessageView : LinearLayout { // region Updating fun bind(message: MessageRecord) { - testTextView.text = "Control message: ${message.body}" + // TODO: Localize strings, make the view look better, handle closed group control messages + if (message.isExpirationTimerUpdate) { textView.text = "Expiration timer update" } + else if (message.isScreenshotNotification) { textView.text = "Screenshot notification" } + else if (message.isMediaSavedNotification) { textView.text = "Media saved notification" } + else { textView.text = "Control message not yet handled" } } fun recycle() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index 684bb03f13..2b87668f93 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -3,9 +3,12 @@ package org.thoughtcrime.securesms.conversation.v2.messages import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater +import android.view.View import android.widget.LinearLayout import kotlinx.android.synthetic.main.view_visible_message.view.* import network.loki.messenger.R +import org.session.libsession.messaging.contacts.Contact.ContactContext +import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.model.MessageRecord class VisibleMessageView : LinearLayout { @@ -30,11 +33,31 @@ class VisibleMessageView : LinearLayout { // region Updating fun bind(message: MessageRecord) { - testTextView.text = "Visible message: ${message.body}" + val sender = message.individualRecipient + val senderSessionID = sender.address.serialize() + val threadID = message.threadId + val threadDB = DatabaseFactory.getThreadDatabase(context) + val thread = threadDB.getRecipientForThreadId(threadID) + val contactDB = DatabaseFactory.getSessionContactDatabase(context) + val isGroupThread = (thread?.isGroupRecipient == true) + // Show profile picture and sender name if this is a group thread + if (isGroupThread) { + profilePictureContainer.visibility = View.VISIBLE + profilePictureView.publicKey = senderSessionID + // TODO: Set glide on the profile picture view and update it + // TODO: Show crown if this is an open group and the user is a moderator; otherwise hide it + senderNameTextView.visibility = View.VISIBLE + val context = if (thread?.isOpenGroupRecipient == true) ContactContext.OPEN_GROUP else ContactContext.REGULAR + senderNameTextView.text = contactDB.getContactWithSessionID(senderSessionID)?.displayName(context) ?: senderSessionID + } else { + profilePictureContainer.visibility = View.GONE + senderNameTextView.visibility = View.GONE + } + // TODO: Populate content view } fun recycle() { - // TODO: Implement + profilePictureView.recycle() } // endregion } \ No newline at end of file diff --git a/app/src/main/res/drawable/message_bubble_background.xml b/app/src/main/res/drawable/message_bubble_background.xml index cda641b1da..9c4347ae6e 100644 --- a/app/src/main/res/drawable/message_bubble_background.xml +++ b/app/src/main/res/drawable/message_bubble_background.xml @@ -4,7 +4,6 @@ - diff --git a/app/src/main/res/drawable/message_bubble_background_received_alone.xml b/app/src/main/res/drawable/message_bubble_background_received_alone.xml index cda641b1da..9c4347ae6e 100644 --- a/app/src/main/res/drawable/message_bubble_background_received_alone.xml +++ b/app/src/main/res/drawable/message_bubble_background_received_alone.xml @@ -4,7 +4,6 @@ - diff --git a/app/src/main/res/drawable/message_bubble_background_received_end.xml b/app/src/main/res/drawable/message_bubble_background_received_end.xml index 3e4e2c0562..c31ca989d0 100644 --- a/app/src/main/res/drawable/message_bubble_background_received_end.xml +++ b/app/src/main/res/drawable/message_bubble_background_received_end.xml @@ -4,7 +4,6 @@ - - - - diff --git a/app/src/main/res/drawable/message_bubble_background_sent_end.xml b/app/src/main/res/drawable/message_bubble_background_sent_end.xml index 5bc4597c03..33fac83ec3 100644 --- a/app/src/main/res/drawable/message_bubble_background_sent_end.xml +++ b/app/src/main/res/drawable/message_bubble_background_sent_end.xml @@ -4,7 +4,6 @@ - - - + android:orientation="horizontal" + android:gravity="center"> + android:orientation="horizontal" + android:gravity="bottom"> - + + + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file