mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Fix crash
This commit is contained in:
parent
169a7e609e
commit
b27dfdf6ce
@ -146,6 +146,7 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<org.thoughtcrime.securesms.loki.FriendRequestView
|
<org.thoughtcrime.securesms.loki.FriendRequestView
|
||||||
|
android:id="@+id/friend_request_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
|||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.Quote;
|
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.AttachmentDownloadJob;
|
||||||
import org.thoughtcrime.securesms.jobs.MmsDownloadJob;
|
import org.thoughtcrime.securesms.jobs.MmsDownloadJob;
|
||||||
import org.thoughtcrime.securesms.jobs.MmsSendJob;
|
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.LinkPreview;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
import org.thoughtcrime.securesms.loki.FriendRequestView;
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||||
import org.thoughtcrime.securesms.mms.ImageSlide;
|
import org.thoughtcrime.securesms.mms.ImageSlide;
|
||||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
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.mms.TextSlide;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||||
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||||
import org.thoughtcrime.securesms.util.DateUtils;
|
import org.thoughtcrime.securesms.util.DateUtils;
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
import org.thoughtcrime.securesms.util.LongClickCopySpan;
|
import org.thoughtcrime.securesms.util.LongClickCopySpan;
|
||||||
@ -146,6 +149,7 @@ public class ConversationItem extends LinearLayout
|
|||||||
private ViewGroup contactPhotoHolder;
|
private ViewGroup contactPhotoHolder;
|
||||||
private AlertView alertView;
|
private AlertView alertView;
|
||||||
private ViewGroup container;
|
private ViewGroup container;
|
||||||
|
private FriendRequestView friendRequestView;
|
||||||
|
|
||||||
private @NonNull Set<MessageRecord> batchSelected = new HashSet<>();
|
private @NonNull Set<MessageRecord> batchSelected = new HashSet<>();
|
||||||
private @NonNull Recipient conversationRecipient;
|
private @NonNull Recipient conversationRecipient;
|
||||||
@ -204,6 +208,7 @@ public class ConversationItem extends LinearLayout
|
|||||||
this.groupSenderHolder = findViewById(R.id.group_sender_holder);
|
this.groupSenderHolder = findViewById(R.id.group_sender_holder);
|
||||||
this.quoteView = findViewById(R.id.quote_view);
|
this.quoteView = findViewById(R.id.quote_view);
|
||||||
this.container = findViewById(R.id.container);
|
this.container = findViewById(R.id.container);
|
||||||
|
this.friendRequestView = findViewById(R.id.friend_request_view);
|
||||||
|
|
||||||
setOnClickListener(new ClickListener(null));
|
setOnClickListener(new ClickListener(null));
|
||||||
|
|
||||||
@ -248,6 +253,7 @@ public class ConversationItem extends LinearLayout
|
|||||||
setQuote(messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
setQuote(messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
||||||
setMessageSpacing(context, messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
setMessageSpacing(context, messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
||||||
setFooter(messageRecord, nextMessageRecord, locale, groupThread);
|
setFooter(messageRecord, nextMessageRecord, locale, groupThread);
|
||||||
|
setFriendRequestView(messageRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) {
|
||||||
if (hasSharedContact(messageRecord)) {
|
if (hasSharedContact(messageRecord)) {
|
||||||
return sharedContactStub.get().getFooter();
|
return sharedContactStub.get().getFooter();
|
||||||
|
@ -15,8 +15,8 @@ import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestS
|
|||||||
|
|
||||||
class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
||||||
private var isUISetUp = false
|
private var isUISetUp = false
|
||||||
var message: Any? = null
|
private var message: Any? = null
|
||||||
set(newValue) { field = newValue; handleMessageChanged() }
|
private var messageID: Long? = null
|
||||||
var delegate: FriendRequestViewDelegate? = null
|
var delegate: FriendRequestViewDelegate? = null
|
||||||
|
|
||||||
// region Components
|
// region Components
|
||||||
@ -46,7 +46,9 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
private fun handleMessageChanged() {
|
fun update(message: Any, messageID: Long) {
|
||||||
|
this.message = message
|
||||||
|
this.messageID = messageID
|
||||||
setUpUIIfNeeded()
|
setUpUIIfNeeded()
|
||||||
updateUI()
|
updateUI()
|
||||||
}
|
}
|
||||||
@ -90,7 +92,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
|||||||
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
||||||
if (message is IncomingTextMessage) {
|
if (message is IncomingTextMessage) {
|
||||||
val message = this.message as 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
|
buttonLinearLayout.visibility = if (friendRequestStatus != LokiMessageFriendRequestStatus.REQUEST_PENDING) View.GONE else View.VISIBLE
|
||||||
val formatID = when (friendRequestStatus) {
|
val formatID = when (friendRequestStatus) {
|
||||||
LokiMessageFriendRequestStatus.NONE, LokiMessageFriendRequestStatus.REQUEST_SENDING_OR_FAILED -> throw IllegalStateException()
|
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)
|
label.text = resources.getString(formatID, contactID)
|
||||||
} else {
|
} else {
|
||||||
val message = this.message as OutgoingTextMessage
|
val message = this.message as OutgoingTextMessage
|
||||||
val friendRequestStatus = database.getFriendRequestStatus(0) // TODO: Message ID
|
val friendRequestStatus = database.getFriendRequestStatus(messageID!!)
|
||||||
buttonLinearLayout.visibility = View.GONE
|
buttonLinearLayout.visibility = View.GONE
|
||||||
val formatID = when (friendRequestStatus) {
|
val formatID = when (friendRequestStatus) {
|
||||||
LokiMessageFriendRequestStatus.NONE -> throw IllegalStateException()
|
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
|
LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_outgoing_expired_message
|
||||||
}
|
}
|
||||||
if (formatID != null) {
|
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()
|
val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID)!!.address.toString()
|
||||||
label.text = resources.getString(formatID, contactID)
|
label.text = resources.getString(formatID, contactID)
|
||||||
}
|
}
|
||||||
@ -128,14 +130,14 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
|||||||
private fun accept() {
|
private fun accept() {
|
||||||
val message = this.message as IncomingTextMessage
|
val message = this.message as IncomingTextMessage
|
||||||
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
||||||
database.setFriendRequestStatus(0, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED)
|
database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED)
|
||||||
delegate?.acceptFriendRequest(message)
|
delegate?.acceptFriendRequest(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reject() {
|
private fun reject() {
|
||||||
val message = this.message as IncomingTextMessage
|
val message = this.message as IncomingTextMessage
|
||||||
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
||||||
database.setFriendRequestStatus(0, LokiMessageFriendRequestStatus.REQUEST_REJECTED)
|
database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_REJECTED)
|
||||||
delegate?.rejectFriendRequest(message)
|
delegate?.rejectFriendRequest(message)
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user