From 52006c1bb453057f2c3cbe7195c819edea3da2c2 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 1 Sep 2022 09:32:14 +0200 Subject: [PATCH] Renaming CurrentSessionView into SessionInfoView to be more generic --- .../devices/v2/list/CurrentSessionView.kt | 78 ------------------- .../devices/v2/list/SessionInfoView.kt | 78 +++++++++++++++++++ ...rent_session.xml => view_session_info.xml} | 26 +++---- 3 files changed, 91 insertions(+), 91 deletions(-) delete mode 100644 vector/src/main/java/im/vector/app/features/settings/devices/v2/list/CurrentSessionView.kt create mode 100644 vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt rename vector/src/main/res/layout/{view_current_session.xml => view_session_info.xml} (78%) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/CurrentSessionView.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/CurrentSessionView.kt deleted file mode 100644 index 1ce035931f..0000000000 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/CurrentSessionView.kt +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 android.content.Context -import android.util.AttributeSet -import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.view.isVisible -import im.vector.app.R -import im.vector.app.databinding.ViewCurrentSessionBinding -import im.vector.app.features.settings.devices.DeviceFullInfo -import im.vector.app.features.themes.ThemeUtils -import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel - -class CurrentSessionView @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0 -) : ConstraintLayout(context, attrs, defStyleAttr) { - - private val views: ViewCurrentSessionBinding - - init { - inflate(context, R.layout.view_current_session, this) - views = ViewCurrentSessionBinding.bind(this) - } - - val viewDetailsButton = views.currentSessionViewDetailsButton - - fun render(currentDeviceInfo: DeviceFullInfo) { - renderDeviceInfo(currentDeviceInfo.deviceInfo.displayName.orEmpty()) - renderVerificationStatus(currentDeviceInfo.trustLevelForShield) - } - - private fun renderVerificationStatus(trustLevelForShield: RoomEncryptionTrustLevel) { - views.currentSessionVerificationStatusImageView.render(trustLevelForShield) - if (trustLevelForShield == RoomEncryptionTrustLevel.Trusted) { - renderCrossSigningVerified() - } else { - renderCrossSigningUnverified() - } - } - - private fun renderCrossSigningVerified() { - views.currentSessionVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_verified) - views.currentSessionVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorPrimary)) - views.currentSessionVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_verified) - views.currentSessionVerifySessionButton.isVisible = false - } - - private fun renderCrossSigningUnverified() { - views.currentSessionVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_unverified) - views.currentSessionVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorError)) - views.currentSessionVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_unverified) - views.currentSessionVerifySessionButton.isVisible = true - } - - // TODO. We don't have this info yet. Update later accordingly. - private fun renderDeviceInfo(sessionName: String) { - views.currentSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_mobile) - views.currentSessionDeviceTypeImageView.contentDescription = context.getString(R.string.a11y_device_manager_device_type_mobile) - views.currentSessionNameTextView.text = sessionName - } -} 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 new file mode 100644 index 0000000000..b79adfb2d4 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt @@ -0,0 +1,78 @@ +/* + * 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 android.content.Context +import android.util.AttributeSet +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.view.isVisible +import im.vector.app.R +import im.vector.app.databinding.ViewSessionInfoBinding +import im.vector.app.features.settings.devices.DeviceFullInfo +import im.vector.app.features.themes.ThemeUtils +import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel + +class SessionInfoView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + private val views: ViewSessionInfoBinding + + init { + inflate(context, R.layout.view_session_info, this) + views = ViewSessionInfoBinding.bind(this) + } + + val viewDetailsButton = views.sessionInfoViewDetailsButton + + fun render(deviceInfo: DeviceFullInfo) { + renderDeviceInfo(deviceInfo.deviceInfo.displayName.orEmpty()) + renderVerificationStatus(deviceInfo.trustLevelForShield) + } + + private fun renderVerificationStatus(trustLevelForShield: RoomEncryptionTrustLevel) { + views.sessionInfoVerificationStatusImageView.render(trustLevelForShield) + if (trustLevelForShield == RoomEncryptionTrustLevel.Trusted) { + renderCrossSigningVerified() + } else { + renderCrossSigningUnverified() + } + } + + private fun renderCrossSigningVerified() { + views.sessionInfoVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_verified) + views.sessionInfoVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorPrimary)) + views.sessionInfoVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_verified) + views.sessionInfoVerifySessionButton.isVisible = false + } + + private fun renderCrossSigningUnverified() { + views.sessionInfoVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_unverified) + views.sessionInfoVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorError)) + views.sessionInfoVerificationStatusDetailTextView.text = context.getString(R.string.device_manager_verification_status_detail_unverified) + views.sessionInfoVerifySessionButton.isVisible = true + } + + // TODO. We don't have this info yet. Update later accordingly. + private fun renderDeviceInfo(sessionName: String) { + views.sessionInfoDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_mobile) + views.sessionInfoDeviceTypeImageView.contentDescription = context.getString(R.string.a11y_device_manager_device_type_mobile) + views.sessionInfoNameTextView.text = sessionName + } +} diff --git a/vector/src/main/res/layout/view_current_session.xml b/vector/src/main/res/layout/view_session_info.xml similarity index 78% rename from vector/src/main/res/layout/view_current_session.xml rename to vector/src/main/res/layout/view_session_info.xml index 91977eba40..015f4961c9 100644 --- a/vector/src/main/res/layout/view_current_session.xml +++ b/vector/src/main/res/layout/view_session_info.xml @@ -8,7 +8,7 @@ android:paddingBottom="16dp"> + app:layout_constraintTop_toBottomOf="@id/sessionInfoNameTextView">