From 30710f7f15db0730236daa9737b41c08ac2468a7 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 1 Sep 2022 10:43:17 +0200 Subject: [PATCH] Navigation from other session item --- .../devices/v2/VectorSettingsDevicesFragment.kt | 10 ++++++++++ .../settings/devices/v2/list/OtherSessionItem.kt | 10 ++++++++++ .../devices/v2/list/OtherSessionsController.kt | 7 +++++++ .../settings/devices/v2/list/OtherSessionsView.kt | 5 +++++ vector/src/main/res/layout/item_other_session.xml | 1 + 5 files changed, 33 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt index 8bab4ebd60..f7f6ca6db4 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt @@ -42,6 +42,7 @@ import im.vector.app.features.settings.devices.DevicesViewEvents import im.vector.app.features.settings.devices.DevicesViewModel import im.vector.app.features.settings.devices.v2.list.SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationViewState +import im.vector.app.features.settings.devices.v2.list.OtherSessionsController import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState import javax.inject.Inject @@ -76,6 +77,7 @@ class VectorSettingsDevicesFragment : initLearnMoreButtons() initWaitingView() + initOtherSessionsView() observeViewEvents() } @@ -114,6 +116,14 @@ class VectorSettingsDevicesFragment : views.waitingView.waitingStatusText.isVisible = true } + private fun initOtherSessionsView() { + views.deviceListOtherSessions.setCallback(object : OtherSessionsController.Callback { + override fun onItemClicked(deviceId: String) { + navigateToSessionOverview(deviceId) + } + }) + } + override fun onDestroyView() { cleanUpLearnMoreButtonsListeners() super.onDestroyView() diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt index e9376953e0..c73389d775 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt @@ -22,8 +22,10 @@ import android.widget.TextView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.app.R +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.StringProvider import im.vector.app.core.ui.views.ShieldImageView import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel @@ -49,8 +51,16 @@ abstract class OtherSessionItem : VectorEpoxyModel(R.la @EpoxyAttribute lateinit var stringProvider: StringProvider + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) + var clickListener: ClickListener? = null + override fun bind(holder: Holder) { super.bind(holder) + holder.view.onClick(clickListener) + if (clickListener == null) { + holder.view.isClickable = false + } + when (deviceType) { DeviceType.MOBILE -> { holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_mobile) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt index 8a5ee05af7..6419d02fc9 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt @@ -35,6 +35,12 @@ class OtherSessionsController @Inject constructor( private val colorProvider: ColorProvider, ) : TypedEpoxyController>() { + var callback: Callback? = null + + interface Callback { + fun onItemClicked(deviceId: String) + } + override fun buildModels(data: List?) { val host = this @@ -70,6 +76,7 @@ class OtherSessionsController @Inject constructor( sessionDescription(description) sessionDescriptionDrawable(descriptionDrawable) stringProvider(this@OtherSessionsController.stringProvider) + clickListener { device.deviceInfo.deviceId?.let { host.callback?.onItemClicked(it) } } } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsView.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsView.kt index 55978e61fd..682a9c6e64 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsView.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsView.kt @@ -49,7 +49,12 @@ class OtherSessionsView @JvmOverloads constructor( otherSessionsController.setData(devices) } + fun setCallback(callback: OtherSessionsController.Callback) { + otherSessionsController.callback = callback + } + override fun onDetachedFromWindow() { + otherSessionsController.callback = null views.otherSessionsRecyclerView.cleanup() super.onDetachedFromWindow() } diff --git a/vector/src/main/res/layout/item_other_session.xml b/vector/src/main/res/layout/item_other_session.xml index 2c41ce6a56..2f93c2be5d 100644 --- a/vector/src/main/res/layout/item_other_session.xml +++ b/vector/src/main/res/layout/item_other_session.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:foreground="?selectableItemBackground" android:paddingTop="16dp">