From b27dfdf6ceda7474a6ae55af04fe338fc905b0ca Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 25 Jun 2019 09:28:37 +1000 Subject: [PATCH] Fix crash --- res/layout/conversation_item_sent.xml | 1 + .../conversation/ConversationItem.java | 11 +++++++++++ .../securesms/loki/FriendRequestView.kt | 18 ++++++++++-------- .../securesms/loki/KeyPairActivity.kt | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/res/layout/conversation_item_sent.xml b/res/layout/conversation_item_sent.xml index e50069a6db..2e258953c7 100644 --- a/res/layout/conversation_item_sent.xml +++ b/res/layout/conversation_item_sent.xml @@ -146,6 +146,7 @@ diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index eb92e0362a..e9a5ed6be9 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -80,6 +80,7 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MmsMessageRecord; import org.thoughtcrime.securesms.database.model.Quote; +import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob; import org.thoughtcrime.securesms.jobs.MmsDownloadJob; import org.thoughtcrime.securesms.jobs.MmsSendJob; @@ -87,6 +88,7 @@ import org.thoughtcrime.securesms.jobs.SmsSendJob; import org.thoughtcrime.securesms.linkpreview.LinkPreview; import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil; import org.thoughtcrime.securesms.logging.Log; +import org.thoughtcrime.securesms.loki.FriendRequestView; import org.thoughtcrime.securesms.mms.GlideRequests; import org.thoughtcrime.securesms.mms.ImageSlide; import org.thoughtcrime.securesms.mms.PartAuthority; @@ -96,6 +98,7 @@ import org.thoughtcrime.securesms.mms.SlidesClickedListener; import org.thoughtcrime.securesms.mms.TextSlide; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientModifiedListener; +import org.thoughtcrime.securesms.sms.OutgoingTextMessage; import org.thoughtcrime.securesms.util.DateUtils; import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.LongClickCopySpan; @@ -146,6 +149,7 @@ public class ConversationItem extends LinearLayout private ViewGroup contactPhotoHolder; private AlertView alertView; private ViewGroup container; + private FriendRequestView friendRequestView; private @NonNull Set batchSelected = new HashSet<>(); private @NonNull Recipient conversationRecipient; @@ -204,6 +208,7 @@ public class ConversationItem extends LinearLayout this.groupSenderHolder = findViewById(R.id.group_sender_holder); this.quoteView = findViewById(R.id.quote_view); this.container = findViewById(R.id.container); + this.friendRequestView = findViewById(R.id.friend_request_view); setOnClickListener(new ClickListener(null)); @@ -248,6 +253,7 @@ public class ConversationItem extends LinearLayout setQuote(messageRecord, previousMessageRecord, nextMessageRecord, groupThread); setMessageSpacing(context, messageRecord, previousMessageRecord, nextMessageRecord, groupThread); setFooter(messageRecord, nextMessageRecord, locale, groupThread); + setFriendRequestView(messageRecord); } @Override @@ -783,6 +789,11 @@ public class ConversationItem extends LinearLayout } } + private void setFriendRequestView(@NonNull MessageRecord record) { + OutgoingTextMessage message = OutgoingTextMessage.from((SmsMessageRecord)record); + friendRequestView.update(message, record.id); + } + private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) { if (hasSharedContact(messageRecord)) { return sharedContactStub.get().getFooter(); diff --git a/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt b/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt index bb90b4ab98..abc716364b 100644 --- a/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt +++ b/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt @@ -15,8 +15,8 @@ import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestS class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) { private var isUISetUp = false - var message: Any? = null - set(newValue) { field = newValue; handleMessageChanged() } + private var message: Any? = null + private var messageID: Long? = null var delegate: FriendRequestViewDelegate? = null // region Components @@ -46,7 +46,9 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In // endregion // region Updating - private fun handleMessageChanged() { + fun update(message: Any, messageID: Long) { + this.message = message + this.messageID = messageID setUpUIIfNeeded() updateUI() } @@ -90,7 +92,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) if (message is IncomingTextMessage) { val message = this.message as IncomingTextMessage - val friendRequestStatus = database.getFriendRequestStatus(0) // TODO: Message ID + val friendRequestStatus = database.getFriendRequestStatus(messageID!!) buttonLinearLayout.visibility = if (friendRequestStatus != LokiMessageFriendRequestStatus.REQUEST_PENDING) View.GONE else View.VISIBLE val formatID = when (friendRequestStatus) { LokiMessageFriendRequestStatus.NONE, LokiMessageFriendRequestStatus.REQUEST_SENDING_OR_FAILED -> throw IllegalStateException() @@ -103,7 +105,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In label.text = resources.getString(formatID, contactID) } else { val message = this.message as OutgoingTextMessage - val friendRequestStatus = database.getFriendRequestStatus(0) // TODO: Message ID + val friendRequestStatus = database.getFriendRequestStatus(messageID!!) buttonLinearLayout.visibility = View.GONE val formatID = when (friendRequestStatus) { LokiMessageFriendRequestStatus.NONE -> throw IllegalStateException() @@ -114,7 +116,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_outgoing_expired_message } if (formatID != null) { - val threadID = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(0) + val threadID = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageID!!) val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID)!!.address.toString() label.text = resources.getString(formatID, contactID) } @@ -128,14 +130,14 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In private fun accept() { val message = this.message as IncomingTextMessage val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) - database.setFriendRequestStatus(0, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED) + database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED) delegate?.acceptFriendRequest(message) } private fun reject() { val message = this.message as IncomingTextMessage val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) - database.setFriendRequestStatus(0, LokiMessageFriendRequestStatus.REQUEST_REJECTED) + database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_REJECTED) delegate?.rejectFriendRequest(message) } // endregion diff --git a/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt b/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt index 3afc0a377d..2927687eec 100644 --- a/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt @@ -91,7 +91,7 @@ class KeyPairActivity : BaseActionBarActivity() { val publicKey = keyPair!!.publicKey val hexEncodedPublicKey = keyPair!!.hexEncodedPublicKey DatabaseFactory.getIdentityDatabase(this).saveIdentity(Address.fromSerialized(hexEncodedPublicKey), publicKey, - IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true) + IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true) TextSecurePreferences.setLocalNumber(this, hexEncodedPublicKey) TextSecurePreferences.setPromptedPushRegistration(this, true) val application = ApplicationContext.getInstance(this)