Renaming CurrentSessionView into SessionInfoView to be more generic

This commit is contained in:
Maxime NATUREL 2022-09-01 09:32:14 +02:00
parent a5ee4faef4
commit 52006c1bb4
3 changed files with 91 additions and 91 deletions

View file

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

View file

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

View file

@ -8,7 +8,7 @@
android:paddingBottom="16dp">
<ImageView
android:id="@+id/currentSessionDeviceTypeImageView"
android:id="@+id/sessionInfoDeviceTypeImageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="16dp"
@ -21,18 +21,18 @@
tools:src="@drawable/ic_device_type_mobile" />
<TextView
android:id="@+id/currentSessionNameTextView"
android:id="@+id/sessionInfoNameTextView"
style="@style/TextAppearance.Vector.Subtitle.Medium.DevicesManagement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/currentSessionDeviceTypeImageView"
app:layout_constraintTop_toBottomOf="@id/sessionInfoDeviceTypeImageView"
tools:text="Element Mobile: Android" />
<LinearLayout
android:id="@+id/currentSessionVerificationStatusContainer"
android:id="@+id/sessionInfoVerificationStatusContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
@ -40,17 +40,17 @@
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/currentSessionNameTextView">
app:layout_constraintTop_toBottomOf="@id/sessionInfoNameTextView">
<im.vector.app.core.ui.views.ShieldImageView
android:id="@+id/currentSessionVerificationStatusImageView"
android:id="@+id/sessionInfoVerificationStatusImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:importantForAccessibility="no"
tools:src="@drawable/ic_shield_trusted" />
<TextView
android:id="@+id/currentSessionVerificationStatusTextView"
android:id="@+id/sessionInfoVerificationStatusTextView"
style="@style/TextAppearance.Vector.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -60,7 +60,7 @@
</LinearLayout>
<TextView
android:id="@+id/currentSessionVerificationStatusDetailTextView"
android:id="@+id/sessionInfoVerificationStatusDetailTextView"
style="@style/TextAppearance.Vector.Body.DevicesManagement"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -69,11 +69,11 @@
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/currentSessionVerificationStatusContainer"
app:layout_constraintTop_toBottomOf="@id/sessionInfoVerificationStatusContainer"
tools:text="@string/device_manager_verification_status_detail_verified" />
<Button
android:id="@+id/currentSessionVerifySessionButton"
android:id="@+id/sessionInfoVerifySessionButton"
android:layout_width="0dp"
android:layout_height="52dp"
android:layout_marginHorizontal="24dp"
@ -81,10 +81,10 @@
android:text="@string/device_manager_verify_session"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/currentSessionVerificationStatusDetailTextView" />
app:layout_constraintTop_toBottomOf="@id/sessionInfoVerificationStatusDetailTextView" />
<Button
android:id="@+id/currentSessionViewDetailsButton"
android:id="@+id/sessionInfoViewDetailsButton"
style="@style/Widget.Vector.Button.Text"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -93,6 +93,6 @@
android:text="@string/device_manager_view_details"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/currentSessionVerifySessionButton" />
app:layout_constraintTop_toBottomOf="@id/sessionInfoVerifySessionButton" />
</androidx.constraintlayout.widget.ConstraintLayout>