Handling correct UI for selected session

This commit is contained in:
Maxime NATUREL 2022-10-19 15:32:09 +02:00
parent a703b8ae10
commit 3390d7fde4
5 changed files with 42 additions and 12 deletions

View File

@ -22,7 +22,6 @@ import android.view.View.OnLongClickListener
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
@ -30,6 +29,8 @@ import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.views.ShieldImageView
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
@ -59,6 +60,12 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
@EpoxyAttribute
lateinit var stringProvider: StringProvider
@EpoxyAttribute
lateinit var colorProvider: ColorProvider
@EpoxyAttribute
lateinit var drawableProvider: DrawableProvider
@EpoxyAttribute
var selected: Boolean = false
@ -74,11 +81,18 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
super.bind(holder)
holder.view.onClick(clickListener)
holder.view.setOnLongClickListener(onLongClickListener)
if (clickListener == null) {
if (clickListener == null && onLongClickListener == null) {
holder.view.isClickable = false
}
holder.otherSessionDeviceTypeImageView.isSelected = selected
if (selected) {
val drawableColor = colorProvider.getColorFromAttribute(android.R.attr.colorBackground)
val drawable = drawableProvider.getDrawable(R.drawable.ic_check_on, drawableColor)
holder.otherSessionDeviceTypeImageView.setImageDrawable(drawable)
} else {
setDeviceTypeIconUseCase.execute(deviceType, holder.otherSessionDeviceTypeImageView, stringProvider)
}
holder.otherSessionVerificationStatusImageView.render(roomEncryptionTrustLevel)
holder.otherSessionNameTextView.text = sessionName
holder.otherSessionDescriptionTextView.text = sessionDescription
@ -86,9 +100,7 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
holder.otherSessionDescriptionTextView.setTextColor(it)
}
holder.otherSessionDescriptionTextView.setCompoundDrawablesWithIntrinsicBounds(sessionDescriptionDrawable, null, null, null)
// TODO set drawable with correct color and corners
val color = if (selected) R.color.alert_default_error_background else android.R.color.transparent
holder.otherSessionItemBackgroundView.setBackgroundColor(ContextCompat.getColor(holder.view.context, color))
holder.otherSessionItemBackgroundView.isSelected = selected
}
class Holder : VectorEpoxyHolder() {

View File

@ -73,6 +73,8 @@ class OtherSessionsController @Inject constructor(
sessionDescriptionDrawable(descriptionDrawable)
sessionDescriptionColor(descriptionColor)
stringProvider(this@OtherSessionsController.stringProvider)
colorProvider(this@OtherSessionsController.colorProvider)
drawableProvider(this@OtherSessionsController.drawableProvider)
selected(device.isSelected)
clickListener { device.deviceInfo.deviceId?.let { host.callback?.onItemClicked(it) } }
onLongClickListener(View.OnLongClickListener {

View File

@ -1,7 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="?vctr_system" />
</shape>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="oval">
<solid android:color="?attr/vctr_content_primary" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="?attr/colorSurface" />
</shape>
</item>
</selector>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/rounded_rect_shape_8" android:state_selected="true" />
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
</shape>
</item>
</selector>

View File

@ -12,6 +12,7 @@
android:id="@+id/otherSessionItemBackground"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_other_session"
app:layout_constraintBottom_toBottomOf="@id/otherSessionVerificationStatusImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"