mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
fix click interception logic to handle failures
Closes #4111 // FREEBIE
This commit is contained in:
parent
92593d459b
commit
469c3298cc
@ -25,6 +25,7 @@ import android.graphics.Color;
|
|||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@ -108,7 +109,6 @@ public class ConversationItem extends LinearLayout
|
|||||||
|
|
||||||
private final MmsDownloadClickListener mmsDownloadClickListener = new MmsDownloadClickListener();
|
private final MmsDownloadClickListener mmsDownloadClickListener = new MmsDownloadClickListener();
|
||||||
private final MmsPreferencesClickListener mmsPreferencesClickListener = new MmsPreferencesClickListener();
|
private final MmsPreferencesClickListener mmsPreferencesClickListener = new MmsPreferencesClickListener();
|
||||||
private final ClickListener clickListener = new ClickListener();
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
public ConversationItem(Context context) {
|
public ConversationItem(Context context) {
|
||||||
@ -120,6 +120,11 @@ public class ConversationItem extends LinearLayout
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOnClickListener(OnClickListener l) {
|
||||||
|
super.setOnClickListener(new ClickListener(l));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
super.onFinishInflate();
|
super.onFinishInflate();
|
||||||
@ -150,7 +155,7 @@ public class ConversationItem extends LinearLayout
|
|||||||
this.mediaThumbnail = (ThumbnailView) findViewById(R.id.image_view);
|
this.mediaThumbnail = (ThumbnailView) findViewById(R.id.image_view);
|
||||||
this.statusManager = new StatusManager(pendingIndicator, sentIndicator, deliveredIndicator, failedIndicator, pendingApprovalIndicator);
|
this.statusManager = new StatusManager(pendingIndicator, sentIndicator, deliveredIndicator, failedIndicator, pendingApprovalIndicator);
|
||||||
|
|
||||||
setOnClickListener(clickListener);
|
setOnClickListener(new ClickListener(null));
|
||||||
PassthroughClickListener passthroughClickListener = new PassthroughClickListener();
|
PassthroughClickListener passthroughClickListener = new PassthroughClickListener();
|
||||||
if (mmsDownloadButton != null) mmsDownloadButton.setOnClickListener(mmsDownloadClickListener);
|
if (mmsDownloadButton != null) mmsDownloadButton.setOnClickListener(mmsDownloadClickListener);
|
||||||
mediaThumbnail.setThumbnailClickListener(new ThumbnailClickListener());
|
mediaThumbnail.setThumbnailClickListener(new ThumbnailClickListener());
|
||||||
@ -177,13 +182,12 @@ public class ConversationItem extends LinearLayout
|
|||||||
|
|
||||||
this.recipient.addListener(this);
|
this.recipient.addListener(this);
|
||||||
|
|
||||||
setSelectionState(messageRecord);
|
setInteractionState(messageRecord);
|
||||||
setBodyText(messageRecord);
|
setBodyText(messageRecord);
|
||||||
setBubbleState(messageRecord, recipient);
|
setBubbleState(messageRecord, recipient);
|
||||||
setStatusIcons(messageRecord);
|
setStatusIcons(messageRecord);
|
||||||
setContactPhoto(recipient);
|
setContactPhoto(recipient);
|
||||||
setGroupMessageStatus(messageRecord, recipient);
|
setGroupMessageStatus(messageRecord, recipient);
|
||||||
setEvents(messageRecord);
|
|
||||||
setMinimumWidth();
|
setMinimumWidth();
|
||||||
setMediaAttributes(messageRecord);
|
setMediaAttributes(messageRecord);
|
||||||
}
|
}
|
||||||
@ -222,9 +226,9 @@ public class ConversationItem extends LinearLayout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSelectionState(MessageRecord messageRecord) {
|
private void setInteractionState(MessageRecord messageRecord) {
|
||||||
setSelected(batchSelected.contains(messageRecord));
|
setSelected(batchSelected.contains(messageRecord));
|
||||||
mediaThumbnail.setClickable(batchSelected.isEmpty());
|
mediaThumbnail.setClickable(!shouldInterceptClicks(messageRecord));
|
||||||
mediaThumbnail.setLongClickable(batchSelected.isEmpty());
|
mediaThumbnail.setLongClickable(batchSelected.isEmpty());
|
||||||
bodyText.setAutoLinkMask(batchSelected.isEmpty() ? Linkify.ALL : 0);
|
bodyText.setAutoLinkMask(batchSelected.isEmpty() ? Linkify.ALL : 0);
|
||||||
}
|
}
|
||||||
@ -321,11 +325,11 @@ public class ConversationItem extends LinearLayout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEvents(MessageRecord messageRecord) {
|
private boolean shouldInterceptClicks(MessageRecord messageRecord) {
|
||||||
setClickable(batchSelected.isEmpty() &&
|
return batchSelected.isEmpty() &&
|
||||||
(messageRecord.isFailed() ||
|
(messageRecord.isFailed() ||
|
||||||
messageRecord.isPendingInsecureSmsFallback() ||
|
messageRecord.isPendingInsecureSmsFallback() ||
|
||||||
messageRecord.isBundleKeyExchange()));
|
messageRecord.isBundleKeyExchange());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) {
|
private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) {
|
||||||
@ -480,10 +484,16 @@ public class ConversationItem extends LinearLayout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class ClickListener implements View.OnClickListener {
|
private class ClickListener implements View.OnClickListener {
|
||||||
public void onClick(View v) {
|
private OnClickListener parent;
|
||||||
if (!batchSelected.isEmpty()) return;
|
|
||||||
|
|
||||||
if (messageRecord.isFailed()) {
|
public ClickListener(@Nullable OnClickListener parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (!shouldInterceptClicks(messageRecord) && parent != null) {
|
||||||
|
parent.onClick(v);
|
||||||
|
} else if (messageRecord.isFailed()) {
|
||||||
Intent intent = new Intent(context, MessageDetailsActivity.class);
|
Intent intent = new Intent(context, MessageDetailsActivity.class);
|
||||||
intent.putExtra(MessageDetailsActivity.MASTER_SECRET_EXTRA, masterSecret);
|
intent.putExtra(MessageDetailsActivity.MASTER_SECRET_EXTRA, masterSecret);
|
||||||
intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, messageRecord.getId());
|
intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, messageRecord.getId());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user