Fix crash & add documentation

This commit is contained in:
Niels Andriesse 2021-06-25 09:19:21 +10:00
parent 2132e53fb0
commit ec9df3adb2
10 changed files with 24 additions and 8 deletions

View File

@ -53,6 +53,10 @@ import org.thoughtcrime.securesms.util.DateUtils
import java.util.* import java.util.*
import kotlin.math.* 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, class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDelegate,
InputBarRecordingViewDelegate, ConversationRecyclerViewDelegate { InputBarRecordingViewDelegate, ConversationRecyclerViewDelegate {
private val scrollButtonFullVisibilityThreshold by lazy { toPx(120.0f, resources) } private val scrollButtonFullVisibilityThreshold by lazy { toPx(120.0f, resources) }
@ -225,8 +229,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (previewState == null) return@observe if (previewState == null) return@observe
if (previewState.isLoading) { if (previewState.isLoading) {
inputBar.draftLinkPreview() inputBar.draftLinkPreview()
} else { } else if (previewState.linkPreview.isPresent) {
inputBar.updateLinkPreviewDraft(glide, previewState.linkPreview.get()) inputBar.updateLinkPreviewDraft(glide, previewState.linkPreview.get())
} else {
inputBar.cancelLinkPreviewDraft()
} }
}) })
} }

View File

@ -8,41 +8,40 @@ import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.view_link_preview_draft.view.* import kotlinx.android.synthetic.main.view_link_preview_draft.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview 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.GlideRequests
import org.thoughtcrime.securesms.mms.ImageSlide import org.thoughtcrime.securesms.mms.ImageSlide
class LinkPreviewDraftView : LinearLayout { class LinkPreviewDraftView : LinearLayout {
var delegate: LinkPreviewDraftViewDelegate? = null var delegate: LinkPreviewDraftViewDelegate? = null
// region Lifecycle
constructor(context: Context) : super(context) { initialize() } constructor(context: Context) : super(context) { initialize() }
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() } constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() } constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
private fun 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) LayoutInflater.from(context).inflate(R.layout.view_link_preview_draft, this)
linkPreviewDraftContainer.isVisible = false linkPreviewDraftContainer.isVisible = false
thumbnailImageView.clipToOutline = true thumbnailImageView.clipToOutline = true
linkPreviewDraftCancelButton.setOnClickListener { cancel() } linkPreviewDraftCancelButton.setOnClickListener { cancel() }
} }
// endregion
// region Updating
fun update(glide: GlideRequests, linkPreview: LinkPreview) { fun update(glide: GlideRequests, linkPreview: LinkPreview) {
// Hide the loader and show the content view
linkPreviewDraftContainer.isVisible = true linkPreviewDraftContainer.isVisible = true
linkPreviewDraftLoader.isVisible = false linkPreviewDraftLoader.isVisible = false
thumbnailImageView.radius = toPx(4, resources)
if (linkPreview.getThumbnail().isPresent) { if (linkPreview.getThumbnail().isPresent) {
// This internally fetches the thumbnail
thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false) thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false)
} }
linkPreviewDraftTitleTextView.text = linkPreview.title linkPreviewDraftTitleTextView.text = linkPreview.title
} }
// endregion
// region Interaction
private fun cancel() { private fun cancel() {
delegate?.cancelLinkPreviewDraft() delegate?.cancelLinkPreviewDraft()
} }
// endregion
} }
interface LinkPreviewDraftViewDelegate { interface LinkPreviewDraftViewDelegate {

View File

@ -14,6 +14,7 @@ import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
/** Shown upon sending a message to a user that's blocked. */
class BlockedDialog(private val recipient: Recipient) : BaseDialog() { class BlockedDialog(private val recipient: Recipient) : BaseDialog() {
override fun setContentView(builder: AlertDialog.Builder) { override fun setContentView(builder: AlertDialog.Builder) {

View File

@ -13,6 +13,8 @@ import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
import org.thoughtcrime.securesms.database.DatabaseFactory 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() { class DownloadDialog(private val recipient: Recipient) : BaseDialog() {
override fun setContentView(builder: AlertDialog.Builder) { override fun setContentView(builder: AlertDialog.Builder) {

View File

@ -11,6 +11,7 @@ import network.loki.messenger.R
import org.session.libsession.messaging.open_groups.OpenGroupV2 import org.session.libsession.messaging.open_groups.OpenGroupV2
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
/** Shown upon tapping an open group invitation. */
class JoinOpenGroupDialog(private val openGroup: OpenGroupV2) : BaseDialog() { class JoinOpenGroupDialog(private val openGroup: OpenGroupV2) : BaseDialog() {
override fun setContentView(builder: AlertDialog.Builder) { override fun setContentView(builder: AlertDialog.Builder) {

View File

@ -6,6 +6,8 @@ import kotlinx.android.synthetic.main.dialog_link_preview.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog 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() { class LinkPreviewDialog() : BaseDialog() {
override fun setContentView(builder: AlertDialog.Builder) { override fun setContentView(builder: AlertDialog.Builder) {

View File

@ -10,6 +10,7 @@ import kotlinx.android.synthetic.main.dialog_open_url.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
/** Shown upon tapping a URL. */
class OpenURLDialog(private val url: String) : BaseDialog() { class OpenURLDialog(private val url: String) : BaseDialog() {
override fun setContentView(builder: AlertDialog.Builder) { override fun setContentView(builder: AlertDialog.Builder) {

View File

@ -96,6 +96,9 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
delegate?.showVoiceMessageUI() 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) { fun draftQuote(message: MessageRecord) {
linkPreviewDraftView = null linkPreviewDraftView = null
inputBarAdditionalContentContainer.removeAllViews() inputBarAdditionalContentContainer.removeAllViews()

View File

@ -34,6 +34,7 @@ class LinkPreviewView : LinearLayout {
// Thumbnail // Thumbnail
val linkPreview = message.linkPreviews.first() val linkPreview = message.linkPreviews.first()
if (linkPreview.getThumbnail().isPresent) { if (linkPreview.getThumbnail().isPresent) {
// This internally fetches the thumbnail
thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false) thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false)
} }
// Title // Title

View File

@ -70,7 +70,7 @@ public class ThumbnailView extends FrameLayout {
private SlidesClickedListener downloadClickListener = null; private SlidesClickedListener downloadClickListener = null;
private Slide slide = null; private Slide slide = null;
private int radius; public int radius;
public ThumbnailView(Context context) { public ThumbnailView(Context context) {
this(context, null); this(context, null);