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

View File

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

View File

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

View File

@ -23,6 +23,7 @@ import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
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
@ -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) {
@EpoxyAttribute
var deviceType: SessionDeviceType = SessionDeviceType.UNKNOWN
var deviceType: DeviceType = DeviceType.UNKNOWN
@EpoxyAttribute
var roomEncryptionTrustLevel: RoomEncryptionTrustLevel? = null
@ -41,16 +42,29 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
@EpoxyAttribute
var sessionDescription: String? = null
@EpoxyAttribute
lateinit var stringProvider: StringProvider
override fun bind(holder: Holder) {
super.bind(holder)
holder.otherSessionDeviceTypeImageView.setImageResource(
when (deviceType) {
SessionDeviceType.MOBILE -> R.drawable.ic_device_type_mobile
SessionDeviceType.WEB -> R.drawable.ic_device_type_web
SessionDeviceType.DESKTOP -> R.drawable.ic_device_type_desktop
SessionDeviceType.UNKNOWN -> R.drawable.ic_device_type_unknown
}
)
when (deviceType) {
DeviceType.MOBILE -> {
holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_mobile)
holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_mobile)
}
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.otherSessionNameTextView.text = sessionName
holder.otherSessionDescriptionTextView.text = sessionDescription

View File

@ -32,7 +32,6 @@ class OtherSessionsController @Inject constructor(
) : TypedEpoxyController<List<DeviceFullInfo>>() {
override fun buildModels(data: List<DeviceFullInfo>?) {
data ?: return
val host = this
if (data.isNullOrEmpty()) {
@ -51,10 +50,11 @@ class OtherSessionsController @Inject constructor(
otherSessionItem {
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)
sessionName(device.deviceInfo.displayName)
sessionDescription(description)
stringProvider(this@OtherSessionsController.stringProvider)
}
}
}

View File

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

View File

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

View File

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

View File

@ -3208,8 +3208,9 @@
<!-- Device Manager -->
<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_web" tools:ignore="UnusedResources">Web</string>
<string name="a11y_device_manager_device_type_desktop" tools:ignore="UnusedResources">Desktop</string>
<string name="a11y_device_manager_device_type_web">Web</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_unverified">Unverified session</string>
<string name="device_manager_verification_status_detail_verified">Your current session is ready for secure messaging.</string>