Display trust level indicator in toolbar

This commit is contained in:
Matéo Duparc 2021-05-31 11:42:42 +02:00
parent 78f120c627
commit 5b439898d8
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
7 changed files with 45 additions and 15 deletions

View File

@ -9,6 +9,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
@ -93,9 +94,11 @@ class ChatActivity : ServiceBoundActivity() {
chatAdapter.clear()
val contact = airaService.contacts[sessionId]
val avatar = if (contact == null) {
displayIconTrustLevel(false, false)
sessionName = airaService.savedNames[sessionId]
airaService.savedAvatars[sessionId]
} else {
displayIconTrustLevel(true, contact.verified)
sessionName = contact.name
contact.avatar
}
@ -110,7 +113,6 @@ class ChatActivity : ServiceBoundActivity() {
}
}
if (contact != null) {
displayIconTrustLevel(true, contact.verified)
loadMsgs(contact.uuid)
}
airaService.savedMsgs[sessionId]?.let {
@ -206,15 +208,28 @@ class ChatActivity : ServiceBoundActivity() {
}
private fun displayIconTrustLevel(isContact: Boolean, isVerified: Boolean) {
val setResource = fun (imageView: ImageView, resource: Int?) {
imageView.apply {
visibility = if (resource == null) {
View.GONE
} else {
setImageResource(resource)
View.VISIBLE
}
}
}
when {
isVerified -> {
binding.imageTrustLevel.setImageResource(R.drawable.ic_verified)
setResource(binding.toolbar.toolbarImageTrustLevel, R.drawable.ic_verified)
setResource(binding.bottomImageTrustLevel, R.drawable.ic_verified)
}
isContact -> {
binding.imageTrustLevel.setImageDrawable(null)
setResource(binding.toolbar.toolbarImageTrustLevel, null)
setResource(binding.bottomImageTrustLevel, null)
}
else -> {
binding.imageTrustLevel.setImageResource(R.drawable.ic_warning)
setResource(binding.toolbar.toolbarImageTrustLevel, R.drawable.ic_warning)
setResource(binding.bottomImageTrustLevel, R.drawable.ic_warning)
}
}
}

View File

@ -34,14 +34,14 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/image_trust_level"/>
app:layout_constraintEnd_toStartOf="@id/bottom_image_trust_level"/>
<ImageView
android:id="@+id/image_trust_level"
android:id="@+id/bottom_image_trust_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_warning"
android:contentDescription="@string/trust_level_indicator"
android:layout_marginEnd="5dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/button_attach"
@ -53,10 +53,11 @@
android:layout_height="wrap_content"
android:hint="@string/message_hint"
android:autofillHints="message"
android:inputType="text"
style="@style/EditText"
android:inputType="textShortMessage|textAutoCorrect|textCapSentences"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/image_trust_level"
app:layout_constraintStart_toEndOf="@id/bottom_image_trust_level"
app:layout_constraintEnd_toStartOf="@+id/button_send"/>
<ImageButton

View File

@ -69,6 +69,7 @@
android:imeOptions="actionGo"
android:hint="@string/add_peer_ip"
android:autofillHints="ip"
style="@style/EditText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

@ -25,8 +25,16 @@
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:layout_gravity="center_vertical"/>
<ImageView
android:id="@+id/toolbar_image_trust_level"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:visibility="gone"/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.Toolbar>

View File

@ -3,10 +3,10 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/delete_conversation"
android:id="@+id/session_info"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_delete_conversation"
android:title="@string/delete_conversation" />
android:icon="@drawable/ic_info"
android:title="@string/details"/>
<item
android:id="@+id/verify"
@ -27,10 +27,10 @@
android:title="@string/remove_contact"/>
<item
android:id="@+id/session_info"
android:id="@+id/delete_conversation"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_info"
android:title="@string/details"/>
android:icon="@drawable/ic_delete_conversation"
android:title="@string/delete_conversation" />
<item
android:id="@+id/refresh_profile"

View File

@ -94,6 +94,7 @@
<string name="choose_avatar">Choose avatar</string>
<string name="message_hint">Send a message…</string>
<string name="no_name_error">This session has no name !</string>
<string name="invalid_ip">Invalid IP address</string>
<!--accessibility strings-->
<string name="send_file">Send file</string>

View File

@ -18,6 +18,10 @@
<item name="android:scaleType">fitXY</item>
<item name="android:layout_margin">5dp</item>
</style>
<style name="EditText" parent="Widget.AppCompat.EditText">
<item name="android:background">@color/transparent</item>
<item name="android:textSize">16sp</item>
</style>
<style name="Theme.AIRA.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>