show sender and display correct encryption icon

This commit is contained in:
Daniel Gultsch 2023-03-24 16:11:55 +01:00
parent 75a4008aee
commit 405eeadd95
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
5 changed files with 97 additions and 1 deletions

View file

@ -149,4 +149,26 @@ public class MessageWithContentReactions implements IndividualName {
public BareJid individualAddress() { public BareJid individualAddress() {
return sender; return sender;
} }
public String getSender() {
return this.fromResource == null ? null : fromResource.toString();
}
public boolean isGroupChat() {
return Arrays.asList(ChatType.MUC, ChatType.MULTICAST).contains(this.chatType);
}
public EncryptionTuple getEncryption() {
return new EncryptionTuple(this.encryption, this.trust);
}
public static class EncryptionTuple {
public final Encryption encryption;
public final Trust trust;
public EncryptionTuple(Encryption encryption, Trust trust) {
this.encryption = encryption;
this.trust = trust;
}
}
} }

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter; import androidx.databinding.BindingAdapter;
@ -13,6 +14,9 @@ import com.google.android.material.textfield.TextInputLayout;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import im.conversations.android.R; import im.conversations.android.R;
import im.conversations.android.database.model.ChatOverviewItem; import im.conversations.android.database.model.ChatOverviewItem;
import im.conversations.android.database.model.Encryption;
import im.conversations.android.database.model.MessageWithContentReactions;
import im.conversations.android.database.model.Trust;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -113,4 +117,31 @@ public class BindingAdapters {
textView.setVisibility(View.VISIBLE); textView.setVisibility(View.VISIBLE);
} }
} }
@BindingAdapter("encryption")
public static void setEncryption(
final ImageView imageView,
final MessageWithContentReactions.EncryptionTuple encryptionTuple) {
if (encryptionTuple == null) {
imageView.setVisibility(View.GONE);
return;
}
final var encryption = encryptionTuple.encryption;
final var trust = encryptionTuple.trust;
if (encryption == null || encryption == Encryption.CLEARTEXT) {
imageView.setVisibility(View.GONE);
} else if (encryption == Encryption.OMEMO || encryption == Encryption.PGP) {
if (trust == Trust.VERIFIED || trust == Trust.VERIFIED_X509) {
imageView.setImageResource(R.drawable.ic_verified_user_24dp);
} else {
imageView.setImageResource(R.drawable.ic_lock_outline_24dp);
}
imageView.setVisibility(View.VISIBLE);
} else if (encryption == Encryption.FAILURE) {
imageView.setImageResource(R.drawable.ic_encryption_errorred_24dp);
imageView.setVisibility(View.VISIBLE);
} else {
throw new IllegalArgumentException(String.format("Unknown encryption %s", encryption));
}
}
} }

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1s3.1,1.39 3.1,3.1v2h-4.27L20,17.17V10c0,-1.1 -0.9,-2 -2,-2h-1V6c0,-2.76 -2.24,-5 -5,-5C9.79,1 7.93,2.45 7.27,4.44L8.9,6.07V6zM2.1,2.1L0.69,3.51L5.3,8.13C4.55,8.42 4,9.15 4,10v10c0,1.1 0.9,2 2,2h12c0.34,0 0.65,-0.09 0.93,-0.24l1.56,1.56l1.41,-1.41L2.1,2.1zM12,17c-1.1,0 -2,-0.9 -2,-2c0,-0.59 0.27,-1.12 0.68,-1.49l2.81,2.81C13.12,16.73 12.59,17 12,17z" />
</vector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="?colorControlNormal" />
</shape>

View file

@ -66,10 +66,38 @@
android:layout_marginStart="4sp" android:layout_marginStart="4sp"
android:src="@drawable/ic_lock_outline_24dp" android:src="@drawable/ic_lock_outline_24dp"
android:visibility="visible" android:visibility="visible"
app:encryption="@{message.getEncryption()}"
app:layout_constraintBottom_toBottomOf="@+id/time"
app:layout_constraintStart_toEndOf="@+id/sender"
app:layout_constraintTop_toTopOf="@+id/time"
app:tint="?colorOnSurface" />
<ImageView
android:id="@+id/senderSeparator"
android:layout_width="3sp"
android:layout_height="3sp"
android:layout_marginStart="4sp"
android:src="@drawable/ic_middle_dot_24dp"
android:textAppearance="?textAppearanceTitleLarge"
android:visibility="@{message.isGroupChat() ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="@+id/time" app:layout_constraintBottom_toBottomOf="@+id/time"
app:layout_constraintStart_toEndOf="@+id/time" app:layout_constraintStart_toEndOf="@+id/time"
app:layout_constraintTop_toTopOf="@+id/time" app:layout_constraintTop_toTopOf="@+id/time"
app:tint="?colorOnSurface" /> app:tint="?colorOnSurface"
tools:ignore="SmallSp" />
<TextView
android:id="@+id/sender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4sp"
android:text="@{message.sender}"
android:textAppearance="?textAppearanceLabelSmall"
android:textColor="?colorOnSurface"
android:visibility="@{message.isGroupChat() ? View.VISIBLE : View.GONE}"
app:layout_constraintBaseline_toBaselineOf="@+id/time"
app:layout_constraintStart_toEndOf="@+id/senderSeparator"
tools:text="Juliet" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>