From 3eaf5f7fe0bad399f4edc2d37d4f04ef6f1269df Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 1 Sep 2022 17:46:15 +0200 Subject: [PATCH] Adding learn more link in verification status details --- .../devices/v2/list/SessionInfoView.kt | 35 +++++++++++++++++-- .../devices/v2/list/SessionInfoViewState.kt | 1 + .../v2/overview/SessionOverviewFragment.kt | 26 +++++++++++++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt index be6cfad1c8..536184faec 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt @@ -21,6 +21,7 @@ import android.util.AttributeSet import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isVisible import im.vector.app.R +import im.vector.app.core.extensions.setTextWithColoredPart import im.vector.app.databinding.ViewSessionInfoBinding import im.vector.app.features.themes.ThemeUtils import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel @@ -33,6 +34,8 @@ class SessionInfoView @JvmOverloads constructor( private val views: ViewSessionInfoBinding + var onLearnMoreClickListener: (() -> Unit)? = null + init { inflate(context, R.layout.view_session_info, this) views = ViewSessionInfoBinding.bind(this) @@ -42,17 +45,45 @@ class SessionInfoView @JvmOverloads constructor( fun render(sessionInfoViewState: SessionInfoViewState) { renderDeviceInfo(sessionInfoViewState.deviceFullInfo.deviceInfo.displayName.orEmpty()) - renderVerificationStatus(sessionInfoViewState.deviceFullInfo.trustLevelForShield, sessionInfoViewState.isCurrentSession) + renderVerificationStatus( + sessionInfoViewState.deviceFullInfo.trustLevelForShield, + sessionInfoViewState.isCurrentSession, + sessionInfoViewState.hasLearnMoreLink + ) renderDetailsButton(sessionInfoViewState.isDetailsButtonVisible) } - private fun renderVerificationStatus(encryptionTrustLevel: RoomEncryptionTrustLevel, isCurrentSession: Boolean) { + private fun renderVerificationStatus( + encryptionTrustLevel: RoomEncryptionTrustLevel, + isCurrentSession: Boolean, + hasLearnMoreLink: Boolean, + ) { views.sessionInfoVerificationStatusImageView.render(encryptionTrustLevel) if (encryptionTrustLevel == RoomEncryptionTrustLevel.Trusted) { renderCrossSigningVerified(isCurrentSession) } else { renderCrossSigningUnverified(isCurrentSession) } + if (hasLearnMoreLink) { + appendLearnMoreToVerificationStatus() + } + } + + private fun appendLearnMoreToVerificationStatus() { + val status = views.sessionInfoVerificationStatusDetailTextView.text + val learnMore = context.getString(R.string.action_learn_more) + val stringBuilder = StringBuilder() + stringBuilder.append(status) + stringBuilder.append(" ") + stringBuilder.append(learnMore) + + views.sessionInfoVerificationStatusDetailTextView.setTextWithColoredPart( + fullText = stringBuilder.toString(), + coloredPart = learnMore, + underline = false + ) { + onLearnMoreClickListener?.invoke() + } } private fun renderCrossSigningVerified(isCurrentSession: Boolean) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt index c9a351f568..cf7c6f0ae8 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt @@ -22,4 +22,5 @@ data class SessionInfoViewState( val isCurrentSession: Boolean, val deviceFullInfo: DeviceFullInfo, val isDetailsButtonVisible: Boolean = true, + val hasLearnMoreLink: Boolean = false ) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt index 60d58c8a8d..eb2a3aa93f 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt @@ -16,8 +16,11 @@ package im.vector.app.features.settings.devices.v2.overview +import android.os.Bundle import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.view.isGone import androidx.core.view.isVisible @@ -44,6 +47,26 @@ class SessionOverviewFragment : return FragmentSessionOverviewBinding.inflate(inflater, container, false) } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + initSessionInfoView() + } + + private fun initSessionInfoView() { + views.sessionOverviewInfo.onLearnMoreClickListener = { + Toast.makeText(context, "Learn more verification status", Toast.LENGTH_LONG).show() + } + } + + override fun onDestroyView() { + cleanUpSessionInfoView() + super.onDestroyView() + } + + private fun cleanUpSessionInfoView() { + views.sessionOverviewInfo.onLearnMoreClickListener = null + } + override fun invalidate() = withState(viewModel) { state -> updateToolbar(state.isCurrentSession) if (state.deviceInfo is Success) { @@ -65,7 +88,8 @@ class SessionOverviewFragment : val viewState = SessionInfoViewState( isCurrentSession = isCurrentSession, deviceFullInfo = deviceFullInfo, - isDetailsButtonVisible = false + isDetailsButtonVisible = false, + hasLearnMoreLink = true ) views.sessionOverviewInfo.render(viewState) }