From c35d854776a9fe37660615d78b6eae1ea372611a Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 10 Apr 2020 17:42:34 +0200 Subject: [PATCH 1/3] Add shield in composer --- CHANGES.md | 1 + .../home/room/detail/RoomDetailFragment.kt | 2 +- .../room/detail/composer/TextComposerView.kt | 30 ++++++++++++++----- ...constraint_set_composer_layout_compact.xml | 25 ++++++++++++---- ...onstraint_set_composer_layout_expanded.xml | 21 +++++++++++-- .../main/res/layout/merge_composer_layout.xml | 7 +++++ vector/src/main/res/values/strings.xml | 4 +-- 7 files changed, 71 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e7f920d788..c1c0a62105 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ Improvements 🙌: - Cross-Signing | Restore history after recover from passphrase (#1214) - Cross-Sign | QR code scan confirmation screens design update (#1187) - Emoji Verification | It's not the same butterfly! (#1220) + - Cross-Signing | Composer decoration: shields (#1077) Bugfix 🐛: - Missing avatar/displayname after verification request message (#841) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 8c45090c91..86f4847ff7 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -700,7 +700,7 @@ class RoomDetailFragment @Inject constructor( val isRoomEncrypted = summary?.isEncrypted ?: false if (state.tombstoneEvent == null) { composerLayout.visibility = View.VISIBLE - composerLayout.setRoomEncrypted(isRoomEncrypted) + composerLayout.setRoomEncrypted(isRoomEncrypted, state.asyncRoomSummary.invoke()?.roomEncryptionTrustLevel) notificationAreaView.render(NotificationAreaView.State.Hidden) } else { composerLayout.visibility = View.GONE diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt index 593ce1a8f6..b494c901a6 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt @@ -26,12 +26,15 @@ import android.widget.ImageView import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet +import androidx.core.content.ContextCompat import androidx.core.text.toSpannable +import androidx.core.view.isVisible import androidx.transition.AutoTransition import androidx.transition.Transition import androidx.transition.TransitionManager import butterknife.BindView import butterknife.ButterKnife +import im.vector.matrix.android.api.crypto.RoomEncryptionTrustLevel import im.vector.riotx.R import kotlinx.android.synthetic.main.merge_composer_layout.view.* @@ -64,6 +67,8 @@ class TextComposerView @JvmOverloads constructor(context: Context, attrs: Attrib lateinit var composerEditText: ComposerEditText @BindView(R.id.composer_avatar_view) lateinit var composerAvatarImageView: ImageView + @BindView(R.id.composer_shield) + lateinit var composerShieldImageView: ImageView private var currentConstraintSetId: Int = -1 @@ -158,12 +163,23 @@ class TextComposerView @JvmOverloads constructor(context: Context, attrs: Attrib } } - fun setRoomEncrypted(isEncrypted: Boolean) { - composerEditText.setHint( - if (isEncrypted) { - R.string.room_message_placeholder_encrypted - } else { - R.string.room_message_placeholder_not_encrypted - }) + fun setRoomEncrypted(isEncrypted: Boolean, roomEncryptionTrustLevel: RoomEncryptionTrustLevel?) { + if (isEncrypted) { + composerEditText.setHint(R.string.room_message_placeholder_encrypted) + composerShieldImageView.isVisible = true + val shield = when (roomEncryptionTrustLevel) { + RoomEncryptionTrustLevel.Trusted -> { + ContextCompat.getDrawable(context, R.drawable.ic_shield_trusted) + } + RoomEncryptionTrustLevel.Warning -> { + ContextCompat.getDrawable(context, R.drawable.ic_shield_warning) + } + else -> ContextCompat.getDrawable(context, R.drawable.ic_shield_black) + } + composerShieldImageView.setImageDrawable(shield) + } else { + composerEditText.setHint(R.string.room_message_placeholder_not_encrypted) + composerShieldImageView.isVisible = false + } } } diff --git a/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml b/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml index ac04dfe3ec..4607f28f34 100644 --- a/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml +++ b/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml @@ -99,18 +99,31 @@ android:layout_width="32dp" android:layout_height="32dp" android:layout_marginStart="8dp" - android:layout_marginLeft="8dp" android:layout_marginTop="8dp" - android:layout_marginEnd="8dp" - android:layout_marginRight="8dp" + android:layout_marginEnd="4dp" + app:layout_goneMarginEnd="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@+id/composerEditText" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1" + app:layout_constraintEnd_toStartOf="@+id/composer_shield" tools:src="@tools:sample/avatars" /> + + + + diff --git a/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml b/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml index d246c988e6..17b350542a 100644 --- a/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml +++ b/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml @@ -107,17 +107,32 @@ android:layout_marginStart="8dp" android:layout_marginLeft="8dp" android:layout_marginTop="8dp" - android:layout_marginEnd="8dp" + android:layout_marginEnd="4dp" + app:layout_goneMarginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@+id/composerEditText" + app:layout_constraintEnd_toStartOf="@+id/composer_shield" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1" tools:src="@tools:sample/avatars" /> + + + + + + %s is typing… %1$s & %2$s are typing… %1$s & %2$s & others are typing… - Send an encrypted message… - Send a message (unencrypted)… + Message… + Message… Send an encrypted reply… Send a reply (unencrypted)… Connectivity to the server has been lost. From 1deacfbb34932e274a3097e34e4fac4bde519a5d Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 14 Apr 2020 10:55:21 +0200 Subject: [PATCH 2/3] Code review --- .../home/room/detail/composer/TextComposerView.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt index b494c901a6..e8d8c8876c 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt @@ -167,16 +167,12 @@ class TextComposerView @JvmOverloads constructor(context: Context, attrs: Attrib if (isEncrypted) { composerEditText.setHint(R.string.room_message_placeholder_encrypted) composerShieldImageView.isVisible = true - val shield = when (roomEncryptionTrustLevel) { - RoomEncryptionTrustLevel.Trusted -> { - ContextCompat.getDrawable(context, R.drawable.ic_shield_trusted) - } - RoomEncryptionTrustLevel.Warning -> { - ContextCompat.getDrawable(context, R.drawable.ic_shield_warning) - } - else -> ContextCompat.getDrawable(context, R.drawable.ic_shield_black) + val shieldRes = when (roomEncryptionTrustLevel) { + RoomEncryptionTrustLevel.Trusted -> R.drawable.ic_shield_trusted + RoomEncryptionTrustLevel.Warning -> R.drawable.ic_shield_warning + else -> R.drawable.ic_shield_black } - composerShieldImageView.setImageDrawable(shield) + composerShieldImageView.setImageDrawable(ContextCompat.getDrawable(context, shieldRes)) } else { composerEditText.setHint(R.string.room_message_placeholder_not_encrypted) composerShieldImageView.isVisible = false From 81012746c45e77930207f3334a3308c31a5c34d1 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 15 Apr 2020 15:11:59 +0200 Subject: [PATCH 3/3] Code review / added new key for message hint --- .../features/home/room/detail/composer/TextComposerView.kt | 4 ++-- vector/src/main/res/values/strings.xml | 4 ++-- vector/src/main/res/values/strings_riotX.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt index e8d8c8876c..4391009b08 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerView.kt @@ -165,7 +165,7 @@ class TextComposerView @JvmOverloads constructor(context: Context, attrs: Attrib fun setRoomEncrypted(isEncrypted: Boolean, roomEncryptionTrustLevel: RoomEncryptionTrustLevel?) { if (isEncrypted) { - composerEditText.setHint(R.string.room_message_placeholder_encrypted) + composerEditText.setHint(R.string.room_message_placeholder) composerShieldImageView.isVisible = true val shieldRes = when (roomEncryptionTrustLevel) { RoomEncryptionTrustLevel.Trusted -> R.drawable.ic_shield_trusted @@ -174,7 +174,7 @@ class TextComposerView @JvmOverloads constructor(context: Context, attrs: Attrib } composerShieldImageView.setImageDrawable(ContextCompat.getDrawable(context, shieldRes)) } else { - composerEditText.setHint(R.string.room_message_placeholder_not_encrypted) + composerEditText.setHint(R.string.room_message_placeholder) composerShieldImageView.isVisible = false } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 50741dfaa1..6b0591595a 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -515,8 +515,8 @@ %s is typing… %1$s & %2$s are typing… %1$s & %2$s & others are typing… - Message… - Message… + Send an encrypted message… + Send a message (unencrypted)… Send an encrypted reply… Send a reply (unencrypted)… Connectivity to the server has been lost. diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index 00bf65e121..025491f94b 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -6,7 +6,7 @@ - + Message…