Set the corresponding deviceType icon in list item and in overview view

This commit is contained in:
Maxime NATUREL 2022-10-04 16:01:09 +02:00
parent 5c95cee1c6
commit bf502f4f3d
6 changed files with 68 additions and 26 deletions

View file

@ -33,6 +33,7 @@ import im.vector.app.core.dialogs.ManuallyVerifyDialog
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.databinding.FragmentSettingsDevicesBinding
import im.vector.app.features.crypto.recover.SetupMode
import im.vector.app.features.crypto.verification.VerificationBottomSheet
@ -61,6 +62,8 @@ class VectorSettingsDevicesFragment :
@Inject lateinit var colorProvider: ColorProvider
@Inject lateinit var stringProvider: StringProvider
private val viewModel: DevicesViewModel by fragmentViewModel()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSettingsDevicesBinding {
@ -237,7 +240,7 @@ class VectorSettingsDevicesFragment :
isCurrentSession = true,
deviceFullInfo = it
)
views.deviceListCurrentSession.render(viewState, dateFormatter, drawableProvider, colorProvider)
views.deviceListCurrentSession.render(viewState, dateFormatter, drawableProvider, colorProvider, stringProvider)
views.deviceListCurrentSession.debouncedClicks {
currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) }
}

View file

@ -59,6 +59,8 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var clickListener: ClickListener? = null
private val setDeviceTypeIconUseCase = SetDeviceTypeIconUseCase()
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.onClick(clickListener)
@ -66,24 +68,7 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
holder.view.isClickable = false
}
when (deviceType) {
DeviceType.MOBILE -> {
holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_mobile)
holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_mobile)
}
DeviceType.WEB -> {
holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_web)
holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_web)
}
DeviceType.DESKTOP -> {
holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_desktop)
holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_desktop)
}
DeviceType.UNKNOWN -> {
holder.otherSessionDeviceTypeImageView.setImageResource(R.drawable.ic_device_type_unknown)
holder.otherSessionDeviceTypeImageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_unknown)
}
}
setDeviceTypeIconUseCase.execute(deviceType, holder.otherSessionDeviceTypeImageView, stringProvider)
holder.otherSessionVerificationStatusImageView.render(roomEncryptionTrustLevel)
holder.otherSessionNameTextView.text = sessionName
holder.otherSessionDescriptionTextView.text = sessionDescription

View file

@ -64,7 +64,7 @@ class OtherSessionsController @Inject constructor(
otherSessionItem {
id(device.deviceInfo.deviceId)
deviceType(DeviceType.UNKNOWN) // TODO. We don't have this info yet. Update accordingly.
deviceType(device.deviceExtendedInfo.deviceType)
roomEncryptionTrustLevel(device.roomEncryptionTrustLevel)
sessionName(device.deviceInfo.displayName)
sessionDescription(description)

View file

@ -28,6 +28,7 @@ import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.extensions.setTextWithColoredPart
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.databinding.ViewSessionInfoBinding
import im.vector.app.features.themes.ThemeUtils
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
@ -51,13 +52,20 @@ class SessionInfoView @JvmOverloads constructor(
val viewDetailsButton = views.sessionInfoViewDetailsButton
val viewVerifyButton = views.sessionInfoVerifySessionButton
private val setDeviceTypeIconUseCase = SetDeviceTypeIconUseCase()
fun render(
sessionInfoViewState: SessionInfoViewState,
dateFormatter: VectorDateFormatter,
drawableProvider: DrawableProvider,
colorProvider: ColorProvider,
stringProvider: StringProvider,
) {
renderDeviceInfo(sessionInfoViewState.deviceFullInfo.deviceInfo.displayName.orEmpty())
renderDeviceInfo(
sessionInfoViewState.deviceFullInfo.deviceInfo.displayName.orEmpty(),
sessionInfoViewState.deviceFullInfo.deviceExtendedInfo.deviceType,
stringProvider,
)
renderVerificationStatus(
sessionInfoViewState.deviceFullInfo.roomEncryptionTrustLevel,
sessionInfoViewState.isCurrentSession,
@ -134,10 +142,8 @@ class SessionInfoView @JvmOverloads constructor(
views.sessionInfoVerifySessionButton.isVisible = isVerifyButtonVisible
}
// 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)
private fun renderDeviceInfo(sessionName: String, deviceType: DeviceType, stringProvider: StringProvider) {
setDeviceTypeIconUseCase.execute(deviceType, views.sessionInfoDeviceTypeImageView, stringProvider)
views.sessionInfoNameTextView.text = sessionName
}

View file

@ -0,0 +1,45 @@
/*
* 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.widget.ImageView
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
class SetDeviceTypeIconUseCase {
fun execute(deviceType: DeviceType, imageView: ImageView, stringProvider: StringProvider) {
when (deviceType) {
DeviceType.MOBILE -> {
imageView.setImageResource(R.drawable.ic_device_type_mobile)
imageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_mobile)
}
DeviceType.WEB -> {
imageView.setImageResource(R.drawable.ic_device_type_web)
imageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_web)
}
DeviceType.DESKTOP -> {
imageView.setImageResource(R.drawable.ic_device_type_desktop)
imageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_desktop)
}
DeviceType.UNKNOWN -> {
imageView.setImageResource(R.drawable.ic_device_type_unknown)
imageView.contentDescription = stringProvider.getString(R.string.a11y_device_manager_device_type_unknown)
}
}
}
}

View file

@ -37,6 +37,7 @@ import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.databinding.FragmentSessionOverviewBinding
import im.vector.app.features.auth.ReAuthActivity
import im.vector.app.features.crypto.recover.SetupMode
@ -64,6 +65,8 @@ class SessionOverviewFragment :
@Inject lateinit var colorProvider: ColorProvider
@Inject lateinit var stringProvider: StringProvider
private val viewModel: SessionOverviewViewModel by fragmentViewModel()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSessionOverviewBinding {
@ -205,7 +208,7 @@ class SessionOverviewFragment :
isLearnMoreLinkVisible = true,
isLastSeenDetailsVisible = true,
)
views.sessionOverviewInfo.render(infoViewState, dateFormatter, drawableProvider, colorProvider)
views.sessionOverviewInfo.render(infoViewState, dateFormatter, drawableProvider, colorProvider, stringProvider)
views.sessionOverviewInfo.onLearnMoreClickListener = {
showLearnMoreInfoVerificationStatus(deviceInfo.roomEncryptionTrustLevel == RoomEncryptionTrustLevel.Trusted)
}