Adding learn more link in verification status details

This commit is contained in:
Maxime NATUREL 2022-09-01 17:46:15 +02:00
parent 384c118b8d
commit 3eaf5f7fe0
3 changed files with 59 additions and 3 deletions

View file

@ -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) {

View file

@ -22,4 +22,5 @@ data class SessionInfoViewState(
val isCurrentSession: Boolean,
val deviceFullInfo: DeviceFullInfo,
val isDetailsButtonVisible: Boolean = true,
val hasLearnMoreLink: Boolean = false
)

View file

@ -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)
}