Code review fixes.

This commit is contained in:
Onuray Sahin 2022-08-30 15:47:00 +03:00
parent 2c6c23da9c
commit 66fa5ca98e
9 changed files with 47 additions and 32 deletions

View file

@ -114,13 +114,13 @@ class VectorSettingsDevicesFragment :
} }
private fun initLearnMoreButtons() { private fun initLearnMoreButtons() {
views.deviceListHeaderSectionOther.onLearnMoreClickListener = { views.deviceListHeaderOtherSessions.onLearnMoreClickListener = {
Toast.makeText(context, "Learn more other", Toast.LENGTH_LONG).show() Toast.makeText(context, "Learn more other", Toast.LENGTH_LONG).show()
} }
} }
private fun cleanUpLearnMoreButtonsListeners() { private fun cleanUpLearnMoreButtonsListeners() {
views.deviceListHeaderSectionOther.onLearnMoreClickListener = null views.deviceListHeaderOtherSessions.onLearnMoreClickListener = null
} }
override fun invalidate() = withState(viewModel) { state -> override fun invalidate() = withState(viewModel) { state ->
@ -145,29 +145,29 @@ class VectorSettingsDevicesFragment :
if (otherDevices.isNullOrEmpty()) { if (otherDevices.isNullOrEmpty()) {
hideOtherSessionsView() hideOtherSessionsView()
} else { } else {
views.deviceListHeaderSectionOther.isVisible = true views.deviceListHeaderOtherSessions.isVisible = true
views.deviceListOtherSessions.isVisible = true views.deviceListOtherSessions.isVisible = true
views.deviceListOtherSessions.update(otherDevices) views.deviceListOtherSessions.render(otherDevices)
} }
} }
private fun hideOtherSessionsView() { private fun hideOtherSessionsView() {
views.deviceListHeaderSectionOther.isVisible = false views.deviceListHeaderOtherSessions.isVisible = false
views.deviceListOtherSessions.isVisible = false views.deviceListOtherSessions.isVisible = false
} }
private fun renderCurrentDevice(currentDeviceInfo: DeviceFullInfo?) { private fun renderCurrentDevice(currentDeviceInfo: DeviceFullInfo?) {
currentDeviceInfo?.let { currentDeviceInfo?.let {
views.deviceListHeaderSectionCurrent.isVisible = true views.deviceListHeaderCurrentSession.isVisible = true
views.deviceListCurrentSession.isVisible = true views.deviceListCurrentSession.isVisible = true
views.deviceListCurrentSession.update(it) views.deviceListCurrentSession.render(it)
} ?: run { } ?: run {
hideCurrentSessionView() hideCurrentSessionView()
} }
} }
private fun hideCurrentSessionView() { private fun hideCurrentSessionView() {
views.deviceListHeaderSectionCurrent.isVisible = false views.deviceListHeaderCurrentSession.isVisible = false
views.deviceListCurrentSession.isVisible = false views.deviceListCurrentSession.isVisible = false
} }

View file

@ -39,8 +39,8 @@ class CurrentSessionView @JvmOverloads constructor(
views = ViewCurrentSessionBinding.bind(this) views = ViewCurrentSessionBinding.bind(this)
} }
fun update(currentDeviceInfo: DeviceFullInfo) { fun render(currentDeviceInfo: DeviceFullInfo) {
renderDeviceInfo(currentDeviceInfo.deviceInfo.displayName ?: "") renderDeviceInfo(currentDeviceInfo.deviceInfo.displayName.orEmpty())
renderVerificationStatus(currentDeviceInfo.trustLevelForShield) renderVerificationStatus(currentDeviceInfo.trustLevelForShield)
} }

View file

@ -16,7 +16,7 @@
package im.vector.app.features.settings.devices.v2.list package im.vector.app.features.settings.devices.v2.list
enum class SessionDeviceType { enum class DeviceType {
MOBILE, MOBILE,
WEB, WEB,
DESKTOP, DESKTOP,

View file

@ -23,6 +23,7 @@ import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.views.ShieldImageView import im.vector.app.core.ui.views.ShieldImageView
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
@ -30,7 +31,7 @@ import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.layout.item_other_session) { abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.layout.item_other_session) {
@EpoxyAttribute @EpoxyAttribute
var deviceType: SessionDeviceType = SessionDeviceType.UNKNOWN var deviceType: DeviceType = DeviceType.UNKNOWN
@EpoxyAttribute @EpoxyAttribute
var roomEncryptionTrustLevel: RoomEncryptionTrustLevel? = null var roomEncryptionTrustLevel: RoomEncryptionTrustLevel? = null
@ -41,16 +42,29 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
@EpoxyAttribute @EpoxyAttribute
var sessionDescription: String? = null var sessionDescription: String? = null
@EpoxyAttribute
lateinit var stringProvider: StringProvider
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.otherSessionDeviceTypeImageView.setImageResource( when (deviceType) {
when (deviceType) { DeviceType.MOBILE -> {
SessionDeviceType.MOBILE -> R.drawable.ic_device_type_mobile holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_mobile)
SessionDeviceType.WEB -> R.drawable.ic_device_type_web holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_mobile)
SessionDeviceType.DESKTOP -> R.drawable.ic_device_type_desktop }
SessionDeviceType.UNKNOWN -> R.drawable.ic_device_type_unknown DeviceType.WEB -> {
} holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_web)
) holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_web)
}
DeviceType.DESKTOP -> {
holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_desktop)
holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_desktop)
}
DeviceType.UNKNOWN -> {
holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_unknown)
holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_unknown)
}
}
holder.otherSessionVerificationStatusImageView.render(roomEncryptionTrustLevel) holder.otherSessionVerificationStatusImageView.render(roomEncryptionTrustLevel)
holder.otherSessionNameTextView.text = sessionName holder.otherSessionNameTextView.text = sessionName
holder.otherSessionDescriptionTextView.text = sessionDescription holder.otherSessionDescriptionTextView.text = sessionDescription

View file

@ -32,7 +32,6 @@ class OtherSessionsController @Inject constructor(
) : TypedEpoxyController<List<DeviceFullInfo>>() { ) : TypedEpoxyController<List<DeviceFullInfo>>() {
override fun buildModels(data: List<DeviceFullInfo>?) { override fun buildModels(data: List<DeviceFullInfo>?) {
data ?: return
val host = this val host = this
if (data.isNullOrEmpty()) { if (data.isNullOrEmpty()) {
@ -51,10 +50,11 @@ class OtherSessionsController @Inject constructor(
otherSessionItem { otherSessionItem {
id(device.deviceInfo.deviceId) id(device.deviceInfo.deviceId)
deviceType(SessionDeviceType.UNKNOWN) // TODO. We don't have this info yet. Update accordingly. deviceType(DeviceType.UNKNOWN) // TODO. We don't have this info yet. Update accordingly.
roomEncryptionTrustLevel(device.trustLevelForShield) roomEncryptionTrustLevel(device.trustLevelForShield)
sessionName(device.deviceInfo.displayName) sessionName(device.deviceInfo.displayName)
sessionDescription(description) sessionDescription(description)
stringProvider(this@OtherSessionsController.stringProvider)
} }
} }
} }

View file

@ -42,7 +42,7 @@ class OtherSessionsView @JvmOverloads constructor(
views = ViewOtherSessionsBinding.bind(this) views = ViewOtherSessionsBinding.bind(this)
} }
fun update(devices: List<DeviceFullInfo>) { fun render(devices: List<DeviceFullInfo>) {
views.otherSessionsRecyclerView.configureWith(otherSessionsController, hasFixedSize = true) views.otherSessionsRecyclerView.configureWith(otherSessionsController, hasFixedSize = true)
views.otherSessionsViewAllButton.text = context.getString(R.string.device_manager_other_sessions_view_all, devices.size) views.otherSessionsViewAllButton.text = context.getString(R.string.device_manager_other_sessions_view_all, devices.size)
otherSessionsController.setData(devices) otherSessionsController.setData(devices)

View file

@ -9,7 +9,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<im.vector.app.features.settings.devices.v2.list.DevicesListHeaderView <im.vector.app.features.settings.devices.v2.list.DevicesListHeaderView
android:id="@+id/deviceListHeaderSectionCurrent" android:id="@+id/deviceListHeaderCurrentSession"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:devicesListHeaderDescription="" app:devicesListHeaderDescription=""
@ -26,10 +26,10 @@
android:layout_marginVertical="16dp" android:layout_marginVertical="16dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/deviceListHeaderSectionCurrent" /> app:layout_constraintTop_toBottomOf="@id/deviceListHeaderCurrentSession" />
<View <View
android:id="@+id/deviceListCurrentSessionDivider" android:id="@+id/deviceListDividerCurrentSession"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
@ -39,14 +39,14 @@
app:layout_constraintTop_toBottomOf="@id/deviceListCurrentSession" /> app:layout_constraintTop_toBottomOf="@id/deviceListCurrentSession" />
<im.vector.app.features.settings.devices.v2.list.DevicesListHeaderView <im.vector.app.features.settings.devices.v2.list.DevicesListHeaderView
android:id="@+id/deviceListHeaderSectionOther" android:id="@+id/deviceListHeaderOtherSessions"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:devicesListHeaderDescription="@string/settings_sessions_other_description" app:devicesListHeaderDescription="@string/settings_sessions_other_description"
app:devicesListHeaderTitle="@string/settings_sessions_other_title" app:devicesListHeaderTitle="@string/settings_sessions_other_title"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/deviceListCurrentSessionDivider" /> app:layout_constraintTop_toBottomOf="@id/deviceListDividerCurrentSession" />
<im.vector.app.features.settings.devices.v2.list.OtherSessionsView <im.vector.app.features.settings.devices.v2.list.OtherSessionsView
android:id="@+id/deviceListOtherSessions" android:id="@+id/deviceListOtherSessions"
@ -55,7 +55,7 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/deviceListHeaderSectionOther" /> app:layout_constraintTop_toBottomOf="@id/deviceListHeaderOtherSessions" />
<include <include
android:id="@+id/waiting_view" android:id="@+id/waiting_view"

View file

@ -61,7 +61,7 @@
<TextView <TextView
android:id="@+id/currentSessionVerificationStatusDetailTextView" android:id="@+id/currentSessionVerificationStatusDetailTextView"
style="@style/TextAppearance.Vector.Caption" style="@style/TextAppearance.Vector.Body.DevicesManagement"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="32dp" android:layout_marginHorizontal="32dp"

View file

@ -3208,8 +3208,9 @@
<!-- Device Manager --> <!-- Device Manager -->
<string name="device_manager_settings_active_sessions_show_all">Show All Sessions (V2, WIP)</string> <string name="device_manager_settings_active_sessions_show_all">Show All Sessions (V2, WIP)</string>
<string name="a11y_device_manager_device_type_mobile">Mobile</string> <string name="a11y_device_manager_device_type_mobile">Mobile</string>
<string name="a11y_device_manager_device_type_web" tools:ignore="UnusedResources">Web</string> <string name="a11y_device_manager_device_type_web">Web</string>
<string name="a11y_device_manager_device_type_desktop" tools:ignore="UnusedResources">Desktop</string> <string name="a11y_device_manager_device_type_desktop">Desktop</string>
<string name="a11y_device_manager_device_type_unknown">Unknown device type</string>
<string name="device_manager_verification_status_verified">Verified session</string> <string name="device_manager_verification_status_verified">Verified session</string>
<string name="device_manager_verification_status_unverified">Unverified session</string> <string name="device_manager_verification_status_unverified">Unverified session</string>
<string name="device_manager_verification_status_detail_verified">Your current session is ready for secure messaging.</string> <string name="device_manager_verification_status_detail_verified">Your current session is ready for secure messaging.</string>