Show info in overview screen

This commit is contained in:
Maxime NATUREL 2022-09-01 10:05:24 +02:00
parent 7c32884df5
commit b626a1e4f9
8 changed files with 115 additions and 27 deletions

View File

@ -3217,8 +3217,14 @@
<string name="a11y_device_manager_device_type_unknown">Unknown device type</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_verified">Verified session</string>
<string name="device_manager_verification_status_unverified">Unverified 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> <!-- TODO TO BE REMOVED: replaced by device_manager_verification_status_detail_current_session_verified -->
<string name="device_manager_verification_status_detail_unverified">Verify your current session for enhanced secure messaging.</string> <string name="device_manager_verification_status_detail_verified" tools:ignore="UnusedResources">Your current session is ready for secure messaging.</string>
<!-- TODO TO BE REMOVED: replaced by device_manager_verification_status_detail_current_session_unverified -->
<string name="device_manager_verification_status_detail_unverified" tools:ignore="UnusedResources">Verify your current session for enhanced secure messaging.</string>
<string name="device_manager_verification_status_detail_current_session_verified">Your current session is ready for secure messaging.</string>
<string name="device_manager_verification_status_detail_other_session_verified">This session is ready for secure messaging.</string>
<string name="device_manager_verification_status_detail_current_session_unverified">Verify your current session for enhanced secure messaging.</string>
<string name="device_manager_verification_status_detail_other_session_unverified">Verify or sign out from this session for best security and reliability.</string>
<string name="device_manager_verify_session">Verify Session</string> <string name="device_manager_verify_session">Verify Session</string>
<string name="device_manager_view_details">View Details</string> <string name="device_manager_view_details">View Details</string>
<string name="device_manager_header_section_current_session">Current Session</string> <string name="device_manager_header_section_current_session">Current Session</string>

View File

@ -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.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.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.SecurityRecommendationViewState
import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -199,7 +200,11 @@ class VectorSettingsDevicesFragment :
currentDeviceInfo?.let { currentDeviceInfo?.let {
views.deviceListHeaderCurrentSession.isVisible = true views.deviceListHeaderCurrentSession.isVisible = true
views.deviceListCurrentSession.isVisible = true views.deviceListCurrentSession.isVisible = true
views.deviceListCurrentSession.render(it) val viewState = SessionInfoViewState(
isCurrentSession = true,
deviceFullInfo = it
)
views.deviceListCurrentSession.render(viewState)
views.deviceListCurrentSession.debouncedClicks { views.deviceListCurrentSession.debouncedClicks {
currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) } currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) }
} }

View File

@ -22,7 +22,6 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import im.vector.app.R import im.vector.app.R
import im.vector.app.databinding.ViewSessionInfoBinding import im.vector.app.databinding.ViewSessionInfoBinding
import im.vector.app.features.settings.devices.DeviceFullInfo
import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.themes.ThemeUtils
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
@ -41,31 +40,42 @@ class SessionInfoView @JvmOverloads constructor(
val viewDetailsButton = views.sessionInfoViewDetailsButton val viewDetailsButton = views.sessionInfoViewDetailsButton
fun render(deviceInfo: DeviceFullInfo) { fun render(sessionInfoViewState: SessionInfoViewState) {
renderDeviceInfo(deviceInfo.deviceInfo.displayName.orEmpty()) renderDeviceInfo(sessionInfoViewState.deviceFullInfo.deviceInfo.displayName.orEmpty())
renderVerificationStatus(deviceInfo.trustLevelForShield) renderVerificationStatus(sessionInfoViewState.deviceFullInfo.trustLevelForShield, sessionInfoViewState.isCurrentSession)
renderDetailsButton(sessionInfoViewState.isDetailsButtonVisible)
} }
private fun renderVerificationStatus(trustLevelForShield: RoomEncryptionTrustLevel) { private fun renderVerificationStatus(encryptionTrustLevel: RoomEncryptionTrustLevel, isCurrentSession: Boolean) {
views.sessionInfoVerificationStatusImageView.render(trustLevelForShield) views.sessionInfoVerificationStatusImageView.render(encryptionTrustLevel)
if (trustLevelForShield == RoomEncryptionTrustLevel.Trusted) { if (encryptionTrustLevel == RoomEncryptionTrustLevel.Trusted) {
renderCrossSigningVerified() renderCrossSigningVerified(isCurrentSession)
} else { } else {
renderCrossSigningUnverified() renderCrossSigningUnverified(isCurrentSession)
} }
} }
private fun renderCrossSigningVerified() { private fun renderCrossSigningVerified(isCurrentSession: Boolean) {
views.sessionInfoVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_verified) views.sessionInfoVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_verified)
views.sessionInfoVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorPrimary)) views.sessionInfoVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorPrimary))
views.sessionInfoVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_verified) val statusResId = if (isCurrentSession) {
R.string.device_manager_verification_status_detail_current_session_verified
} else {
R.string.device_manager_verification_status_detail_other_session_verified
}
views.sessionInfoVerificationStatusDetailTextView.text = context.getString(statusResId)
views.sessionInfoVerifySessionButton.isVisible = false views.sessionInfoVerifySessionButton.isVisible = false
} }
private fun renderCrossSigningUnverified() { private fun renderCrossSigningUnverified(isCurrentSession: Boolean) {
views.sessionInfoVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_unverified) views.sessionInfoVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_unverified)
views.sessionInfoVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorError)) views.sessionInfoVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorError))
views.sessionInfoVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_unverified) val statusResId = if (isCurrentSession) {
R.string.device_manager_verification_status_detail_current_session_unverified
} else {
R.string.device_manager_verification_status_detail_other_session_unverified
}
views.sessionInfoVerificationStatusDetailTextView.text = context.getString(statusResId)
views.sessionInfoVerifySessionButton.isVisible = true views.sessionInfoVerifySessionButton.isVisible = true
} }
@ -75,4 +85,8 @@ class SessionInfoView @JvmOverloads constructor(
views.sessionInfoDeviceTypeImageView.contentDescription = context.getString(R.string.a11y_device_manager_device_type_mobile) views.sessionInfoDeviceTypeImageView.contentDescription = context.getString(R.string.a11y_device_manager_device_type_mobile)
views.sessionInfoNameTextView.text = sessionName views.sessionInfoNameTextView.text = sessionName
} }
private fun renderDetailsButton(isDetailsButtonVisible: Boolean) {
views.sessionInfoViewDetailsButton.isVisible = isDetailsButtonVisible
}
} }

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.settings.devices.v2.list
import im.vector.app.features.settings.devices.DeviceFullInfo
data class SessionInfoViewState(
val isCurrentSession: Boolean,
val deviceFullInfo: DeviceFullInfo,
val isDetailsButtonVisible: Boolean = true,
)

View File

@ -19,28 +19,38 @@ package im.vector.app.features.settings.devices.v2.overview
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentSettingsSessionOverviewBinding import im.vector.app.databinding.FragmentSessionOverviewBinding
import im.vector.app.features.settings.devices.DeviceFullInfo
import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState
/** /**
* Display the overview info about a Session. * Display the overview info about a Session.
*/ */
@AndroidEntryPoint @AndroidEntryPoint
class SessionOverviewFragment : class SessionOverviewFragment :
VectorBaseFragment<FragmentSettingsSessionOverviewBinding>() { VectorBaseFragment<FragmentSessionOverviewBinding>() {
private val viewModel: SessionOverviewViewModel by fragmentViewModel() private val viewModel: SessionOverviewViewModel by fragmentViewModel()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSettingsSessionOverviewBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSessionOverviewBinding {
return FragmentSettingsSessionOverviewBinding.inflate(inflater, container, false) return FragmentSessionOverviewBinding.inflate(inflater, container, false)
} }
override fun invalidate() = withState(viewModel) { state -> override fun invalidate() = withState(viewModel) { state ->
updateToolbar(state.isCurrentSession) updateToolbar(state.isCurrentSession)
if (state.deviceInfo is Success) {
renderSessionInfo(state.isCurrentSession, state.deviceInfo.invoke())
} else {
hideSessionInfo()
}
} }
private fun updateToolbar(isCurrentSession: Boolean) { private fun updateToolbar(isCurrentSession: Boolean) {
@ -49,4 +59,18 @@ class SessionOverviewFragment :
?.supportActionBar ?.supportActionBar
?.setTitle(titleResId) ?.setTitle(titleResId)
} }
private fun renderSessionInfo(isCurrentSession: Boolean, deviceFullInfo: DeviceFullInfo) {
views.sessionOverviewInfo.isVisible = true
val viewState = SessionInfoViewState(
isCurrentSession = isCurrentSession,
deviceFullInfo = deviceFullInfo,
isDetailsButtonVisible = false
)
views.sessionOverviewInfo.render(viewState)
}
private fun hideSessionInfo() {
views.sessionOverviewInfo.isGone = true
}
} }

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<im.vector.app.features.settings.devices.v2.list.SessionInfoView
android:id="@+id/sessionOverviewInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="24dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -70,7 +70,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sessionInfoVerificationStatusContainer" app:layout_constraintTop_toBottomOf="@id/sessionInfoVerificationStatusContainer"
tools:text="@string/device_manager_verification_status_detail_verified" /> tools:text="@string/device_manager_verification_status_detail_current_session_verified" />
<Button <Button
android:id="@+id/sessionInfoVerifySessionButton" android:id="@+id/sessionInfoVerifySessionButton"