mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Adding learn more link in verification status details
This commit is contained in:
parent
384c118b8d
commit
3eaf5f7fe0
@ -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) {
|
||||
|
@ -22,4 +22,5 @@ data class SessionInfoViewState(
|
||||
val isCurrentSession: Boolean,
|
||||
val deviceFullInfo: DeviceFullInfo,
|
||||
val isDetailsButtonVisible: Boolean = true,
|
||||
val hasLearnMoreLink: Boolean = false
|
||||
)
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user