From ec9df3adb23638287ddd1856e92600d14d26d12f Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 25 Jun 2021 09:19:21 +1000 Subject: [PATCH] Fix crash & add documentation --- .../conversation/v2/ConversationActivityV2.kt | 8 +++++++- .../v2/components/LinkPreviewDraftView.kt | 11 +++++------ .../conversation/v2/dialogs/BlockedDialog.kt | 1 + .../conversation/v2/dialogs/DownloadDialog.kt | 2 ++ .../conversation/v2/dialogs/JoinOpenGroupDialog.kt | 1 + .../conversation/v2/dialogs/LinkPreviewDialog.kt | 2 ++ .../conversation/v2/dialogs/OpenURLDialog.kt | 1 + .../securesms/conversation/v2/input_bar/InputBar.kt | 3 +++ .../conversation/v2/messages/LinkPreviewView.kt | 1 + .../conversation/v2/utilities/ThumbnailView.java | 2 +- 10 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 5412c0896d..7ee907dc3b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -53,6 +53,10 @@ import org.thoughtcrime.securesms.util.DateUtils import java.util.* import kotlin.math.* +// Some things that seemingly belong to the input bar (e.g. the voice message recording UI) are actually +// part of the conversation activity layout. This is just because it makes the layout a lot simpler. The +// price we pay is a bit of back and forth between the input bar and the conversation activity. + class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDelegate, InputBarRecordingViewDelegate, ConversationRecyclerViewDelegate { private val scrollButtonFullVisibilityThreshold by lazy { toPx(120.0f, resources) } @@ -225,8 +229,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe if (previewState == null) return@observe if (previewState.isLoading) { inputBar.draftLinkPreview() - } else { + } else if (previewState.linkPreview.isPresent) { inputBar.updateLinkPreviewDraft(glide, previewState.linkPreview.get()) + } else { + inputBar.cancelLinkPreviewDraft() } }) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt index a312b6fa9b..23c0add0ef 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt @@ -8,41 +8,40 @@ import androidx.core.view.isVisible import kotlinx.android.synthetic.main.view_link_preview_draft.view.* import network.loki.messenger.R import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview +import org.thoughtcrime.securesms.loki.utilities.toPx import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.mms.ImageSlide class LinkPreviewDraftView : LinearLayout { var delegate: LinkPreviewDraftViewDelegate? = null - // region Lifecycle constructor(context: Context) : super(context) { initialize() } constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() } constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() } private fun initialize() { + // Start out with the loader showing and the content view hidden LayoutInflater.from(context).inflate(R.layout.view_link_preview_draft, this) linkPreviewDraftContainer.isVisible = false thumbnailImageView.clipToOutline = true linkPreviewDraftCancelButton.setOnClickListener { cancel() } } - // endregion - // region Updating fun update(glide: GlideRequests, linkPreview: LinkPreview) { + // Hide the loader and show the content view linkPreviewDraftContainer.isVisible = true linkPreviewDraftLoader.isVisible = false + thumbnailImageView.radius = toPx(4, resources) if (linkPreview.getThumbnail().isPresent) { + // This internally fetches the thumbnail thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false) } linkPreviewDraftTitleTextView.text = linkPreview.title } - // endregion - // region Interaction private fun cancel() { delegate?.cancelLinkPreviewDraft() } - // endregion } interface LinkPreviewDraftViewDelegate { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt index 51c927fbba..d42e39d1fa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt @@ -14,6 +14,7 @@ import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog import org.thoughtcrime.securesms.database.DatabaseFactory +/** Shown upon sending a message to a user that's blocked. */ class BlockedDialog(private val recipient: Recipient) : BaseDialog() { override fun setContentView(builder: AlertDialog.Builder) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt index 74f835ec22..fe0423e2e2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt @@ -13,6 +13,8 @@ import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog import org.thoughtcrime.securesms.database.DatabaseFactory +/** Shown when receiving media from a contact for the first time, to confirm that + * they are to be trusted and files sent by them are to be downloaded. */ class DownloadDialog(private val recipient: Recipient) : BaseDialog() { override fun setContentView(builder: AlertDialog.Builder) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt index 22a896d34d..6be6d899a1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt @@ -11,6 +11,7 @@ import network.loki.messenger.R import org.session.libsession.messaging.open_groups.OpenGroupV2 import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog +/** Shown upon tapping an open group invitation. */ class JoinOpenGroupDialog(private val openGroup: OpenGroupV2) : BaseDialog() { override fun setContentView(builder: AlertDialog.Builder) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt index 04dd5fe03e..802eb79bfc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt @@ -6,6 +6,8 @@ import kotlinx.android.synthetic.main.dialog_link_preview.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog +/** Shown the first time the user inputs a URL that could generate a link preview, to + * let them know that Session offers the ability to send and receive link previews. */ class LinkPreviewDialog() : BaseDialog() { override fun setContentView(builder: AlertDialog.Builder) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt index eedd33731b..7dd056d524 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt @@ -10,6 +10,7 @@ import kotlinx.android.synthetic.main.dialog_open_url.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog +/** Shown upon tapping a URL. */ class OpenURLDialog(private val url: String) : BaseDialog() { override fun setContentView(builder: AlertDialog.Builder) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt index cb48804ec5..98ce5d630d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt @@ -96,6 +96,9 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li delegate?.showVoiceMessageUI() } + // Drafting quotes and drafting link previews is mutually exclusive, i.e. you can't draft + // a quote and a link preview at the same time. + fun draftQuote(message: MessageRecord) { linkPreviewDraftView = null inputBarAdditionalContentContainer.removeAllViews() diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt index 6219077dad..19943c70be 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt @@ -34,6 +34,7 @@ class LinkPreviewView : LinearLayout { // Thumbnail val linkPreview = message.linkPreviews.first() if (linkPreview.getThumbnail().isPresent) { + // This internally fetches the thumbnail thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false) } // Title diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.java index b2fe05b54a..d0d7c8a605 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.java @@ -70,7 +70,7 @@ public class ThumbnailView extends FrameLayout { private SlidesClickedListener downloadClickListener = null; private Slide slide = null; - private int radius; + public int radius; public ThumbnailView(Context context) { this(context, null);