Files
arcanechat-android/src/org/thoughtcrime/securesms/BaseConversationItem.java
T
Hocuri 11a2cfbff7 Verified 1:1 chats, Android UI (#2560)
Depends on https://github.com/deltachat/deltachat-core-rust/pull/4315/.

Follow-up for https://github.com/deltachat/deltachat-android/pull/2541.

- Show a "verified" icon on protection changed update messages
- Add C API
- Show a dialog over the input bar not only for contact requests, but also when the protection is broken (using the new method `isHalfBlocked()`)
  - The positive button reads "OK" (as opposed to contact requests where it reads "Accept")
- Add SVG icons, remove PNG one
- Translations
- When tapping on the `DC_INFO_PROTECTION_{EN|DIS}ABLED` message, show more information (for now, it leads to the online preview of my FAQ PR)
- Block loading remote images in the "Full Msg View" not only for contact requests, also when the protection is broken (using the new method `isHalfBlocked()`)
- Show a big verified/crossed-out-verified symbol over the `DC_INFO_PROTECTION_{EN|DIS}ABLED` messages
- Fix a bug that was kind of present before (for contact requests) but only became really visible now:
  - Set a draft with an image (or other attachment)
  - Your chat partner breaks verification
  - Expected: Both the input bar and the draft image are hidden by the input-bar-dialog.
  - Bug behavior (before c31de5bcf): The input bar is hidden, but the draft image stays visible.
2023-07-14 12:05:05 +02:00

130 lines
4.2 KiB
Java

package org.thoughtcrime.securesms;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcMsg;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.recipients.Recipient;
import java.util.HashSet;
import java.util.Set;
public abstract class BaseConversationItem extends LinearLayout
implements BindableConversationItem
{
static long PULSE_HIGHLIGHT_MILLIS = 500;
protected DcMsg messageRecord;
protected DcChat dcChat;
protected TextView bodyText;
protected final Context context;
protected final DcContext dcContext;
protected Recipient conversationRecipient;
protected @NonNull Set<DcMsg> batchSelected = new HashSet<>();
protected final PassthroughClickListener passthroughClickListener = new PassthroughClickListener();
public BaseConversationItem(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
this.dcContext = DcHelper.getContext(context);
}
protected void bind(@NonNull DcMsg messageRecord,
@NonNull DcChat dcChat,
@NonNull Set<DcMsg> batchSelected,
boolean pulseHighlight,
@NonNull Recipient conversationRecipient)
{
this.messageRecord = messageRecord;
this.dcChat = dcChat;
this.batchSelected = batchSelected;
this.conversationRecipient = conversationRecipient;
setInteractionState(messageRecord, pulseHighlight);
}
protected void setInteractionState(DcMsg messageRecord, boolean pulseHighlight) {
if (batchSelected.contains(messageRecord)) {
setBackgroundResource(R.drawable.conversation_item_background);
setSelected(true);
} else if (pulseHighlight) {
setBackgroundResource(R.drawable.conversation_item_background_animated);
setSelected(true);
postDelayed(() -> setSelected(false), PULSE_HIGHLIGHT_MILLIS);
} else {
setSelected(false);
}
}
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(new ClickListener(l));
}
protected boolean shouldInterceptClicks(DcMsg messageRecord) {
return batchSelected.isEmpty()
&& (messageRecord.isFailed()
|| messageRecord.getInfoType() == DcMsg.DC_INFO_PROTECTION_DISABLED
|| messageRecord.getInfoType() == DcMsg.DC_INFO_PROTECTION_ENABLED);
}
protected class PassthroughClickListener implements View.OnLongClickListener, View.OnClickListener {
@Override
public boolean onLongClick(View v) {
if (bodyText.hasSelection()) {
return false;
}
performLongClick();
return true;
}
@Override
public void onClick(View v) {
performClick();
}
}
protected class ClickListener implements View.OnClickListener {
private OnClickListener parent;
ClickListener(@Nullable OnClickListener parent) {
this.parent = parent;
}
public void onClick(View v) {
if (!shouldInterceptClicks(messageRecord) && parent != null) {
parent.onClick(v);
} else if (messageRecord.isFailed()) {
View view = View.inflate(context, R.layout.message_details_view, null);
TextView detailsText = view.findViewById(R.id.details_text);
detailsText.setText(messageRecord.getError());
AlertDialog d = new AlertDialog.Builder(context)
.setView(view)
.setTitle(R.string.error)
.setPositiveButton(R.string.ok, null)
.create();
d.show();
} else if (messageRecord.getInfoType() == DcMsg.DC_INFO_PROTECTION_DISABLED) {
DcHelper.showVerificationBrokenDialog(context, conversationRecipient.getName());
} else if (messageRecord.getInfoType() == DcMsg.DC_INFO_PROTECTION_ENABLED) {
DcHelper.showProtectionEnabledDialog(context);
}
}
}
}