Fix crash

This commit is contained in:
Niels Andriesse 2019-06-25 09:28:37 +10:00
parent 169a7e609e
commit b27dfdf6ce
4 changed files with 23 additions and 9 deletions

View File

@ -146,6 +146,7 @@
</LinearLayout>
<org.thoughtcrime.securesms.loki.FriendRequestView
android:id="@+id/friend_request_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@ -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<MessageRecord> 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();

View File

@ -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