Creation of a viewState for the SecurityRecommendationView

This commit is contained in:
Maxime NATUREL 2022-09-02 15:23:10 +02:00
parent fbff8d6408
commit c53a8f3288
3 changed files with 41 additions and 12 deletions

View File

@ -41,6 +41,7 @@ import im.vector.app.features.settings.devices.DevicesAction
import im.vector.app.features.settings.devices.DevicesViewEvents
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.SecurityRecommendationViewState
/**
* Display the list of the user's devices and sessions.
@ -152,15 +153,20 @@ class VectorSettingsDevicesFragment :
views.deviceListSecurityRecommendationsDivider.isVisible = true
views.deviceListUnverifiedSessionsRecommendation.isVisible = unverifiedSessionsCount > 0
views.deviceListInactiveSessionsRecommendation.isVisible = inactiveSessionsCount > 0
views.deviceListUnverifiedSessionsRecommendation.setCount(unverifiedSessionsCount)
views.deviceListInactiveSessionsRecommendation.setCount(inactiveSessionsCount)
views.deviceListInactiveSessionsRecommendation.setDescription(
resources.getQuantityString(
val unverifiedSessionsViewState = SecurityRecommendationViewState(
description = getString(R.string.device_manager_unverified_sessions_description),
sessionsCount = unverifiedSessionsCount,
)
views.deviceListUnverifiedSessionsRecommendation.render(unverifiedSessionsViewState)
val inactiveSessionsViewState = SecurityRecommendationViewState(
description = resources.getQuantityString(
R.plurals.device_manager_inactive_sessions_description,
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS,
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS
),
sessionsCount = inactiveSessionsCount,
)
)
views.deviceListInactiveSessionsRecommendation.render(inactiveSessionsViewState)
}
}

View File

@ -56,7 +56,7 @@ class SecurityRecommendationView @JvmOverloads constructor(
private fun setDescription(typedArray: TypedArray) {
val description = typedArray.getString(R.styleable.SecurityRecommendationView_recommendationDescription)
views.recommendationDescriptionTextView.text = description
setDescription(description)
}
private fun setImage(typedArray: TypedArray) {
@ -66,15 +66,16 @@ class SecurityRecommendationView @JvmOverloads constructor(
views.recommendationShieldImageView.backgroundTintList = ColorStateList.valueOf(backgroundTint)
}
fun setTitle(title: String) {
views.recommendationTitleTextView.text = title
}
fun setDescription(description: String) {
private fun setDescription(description: String?) {
views.recommendationDescriptionTextView.text = description
}
fun setCount(sessionsCount: Int) {
private fun setCount(sessionsCount: Int) {
views.recommendationViewAllButton.text = context.getString(R.string.device_manager_other_sessions_view_all, sessionsCount)
}
fun render(viewState: SecurityRecommendationViewState) {
setDescription(viewState.description)
setCount(viewState.sessionsCount)
}
}

View File

@ -0,0 +1,22 @@
/*
* 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
data class SecurityRecommendationViewState(
val description: String,
val sessionsCount: Int,
)