From 456762a464f5b959508a6b3d9883ebc0a33e5890 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 7 Nov 2022 18:26:54 +0300 Subject: [PATCH 01/14] Add toggle ip address menu option. --- .../src/main/res/values/strings.xml | 2 ++ .../settings/devices/v2/DevicesAction.kt | 1 + .../settings/devices/v2/DevicesViewModel.kt | 6 ++++++ .../settings/devices/v2/DevicesViewState.kt | 1 + .../v2/VectorSettingsDevicesFragment.kt | 19 ++++++++++++++++--- .../res/menu/menu_other_sessions_header.xml | 5 +++++ 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index cd7cb3f477..0292847f0b 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -3350,6 +3350,8 @@ Sign out of %1$d session Sign out of %1$d sessions + Show IP address + Hide IP address Sign out of this session Session details Application, device, and activity information. diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesAction.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesAction.kt index 21cbb86e94..6f002359c8 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesAction.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesAction.kt @@ -29,4 +29,5 @@ sealed class DevicesAction : VectorViewModelAction { object VerifyCurrentSession : DevicesAction() data class MarkAsManuallyVerified(val cryptoDeviceInfo: CryptoDeviceInfo) : DevicesAction() object MultiSignoutOtherSessions : DevicesAction() + object ToggleIpAddressVisibility : DevicesAction() } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt index c714645b9a..3cacf82f14 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt @@ -116,9 +116,15 @@ class DevicesViewModel @AssistedInject constructor( is DevicesAction.VerifyCurrentSession -> handleVerifyCurrentSessionAction() is DevicesAction.MarkAsManuallyVerified -> handleMarkAsManuallyVerifiedAction() DevicesAction.MultiSignoutOtherSessions -> handleMultiSignoutOtherSessions() + DevicesAction.ToggleIpAddressVisibility -> handleToggleIpAddressVisibility() } } + private fun handleToggleIpAddressVisibility() = withState { state -> + val isShowingIpAddress = state.isShowingIpAddress + setState { copy(isShowingIpAddress = !isShowingIpAddress) } + } + private fun handleVerifyCurrentSessionAction() { viewModelScope.launch { val currentSessionCanBeVerified = checkIfCurrentSessionCanBeVerifiedUseCase.execute() diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt index e8bed35e24..e0531c34dc 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt @@ -27,4 +27,5 @@ data class DevicesViewState( val unverifiedSessionsCount: Int = 0, val inactiveSessionsCount: Int = 0, val isLoading: Boolean = false, + val isShowingIpAddress: Boolean = false, ) : MavericksState diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt index 3a3c3463fb..c9957efc58 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt @@ -146,11 +146,19 @@ class VectorSettingsDevicesFragment : confirmMultiSignoutOtherSessions() true } + R.id.otherSessionsHeaderToggleIpAddress -> { + handleToggleIpAddressVisibility() + true + } else -> false } } } + private fun handleToggleIpAddressVisibility() { + viewModel.handle(DevicesAction.ToggleIpAddressVisibility) + } + private fun confirmMultiSignoutOtherSessions() { activity?.let { buildConfirmSignoutDialogUseCase.execute(it, this::multiSignoutOtherSessions) @@ -240,7 +248,7 @@ class VectorSettingsDevicesFragment : renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount, isCurrentSessionVerified) renderCurrentDevice(currentDeviceInfo) - renderOtherSessionsView(otherDevices) + renderOtherSessionsView(otherDevices, state.isShowingIpAddress) } else { hideSecurityRecommendations() hideCurrentSessionView() @@ -297,7 +305,7 @@ class VectorSettingsDevicesFragment : hideInactiveSessionsRecommendation() } - private fun renderOtherSessionsView(otherDevices: List?) { + private fun renderOtherSessionsView(otherDevices: List?, isShowingIpAddress: Boolean) { if (otherDevices.isNullOrEmpty()) { hideOtherSessionsView() } else { @@ -313,7 +321,12 @@ class VectorSettingsDevicesFragment : totalNumberOfDevices = otherDevices.size, showViewAll = otherDevices.size > NUMBER_OF_OTHER_DEVICES_TO_RENDER ) - } + views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderToggleIpAddress).title = if (isShowingIpAddress) { + stringProvider.getString(R.string.device_manager_other_sessions_hide_ip_address) + } else { + stringProvider.getString(R.string.device_manager_other_sessions_show_ip_address) + } + } } private fun hideOtherSessionsView() { diff --git a/vector/src/main/res/menu/menu_other_sessions_header.xml b/vector/src/main/res/menu/menu_other_sessions_header.xml index 00778ed36e..d1386ba461 100644 --- a/vector/src/main/res/menu/menu_other_sessions_header.xml +++ b/vector/src/main/res/menu/menu_other_sessions_header.xml @@ -4,6 +4,11 @@ xmlns:tools="http://schemas.android.com/tools" tools:ignore="AlwaysShowAction"> + + Date: Tue, 8 Nov 2022 14:36:27 +0300 Subject: [PATCH 02/14] Toggle ip address on others section of the main screen. --- .../devices/v2/VectorSettingsDevicesFragment.kt | 7 ++++--- .../settings/devices/v2/list/OtherSessionItem.kt | 6 ++++++ .../devices/v2/list/OtherSessionsController.kt | 1 + vector/src/main/res/layout/item_other_session.xml | 15 +++++++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt index c9957efc58..b27d8a7270 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt @@ -316,10 +316,11 @@ class VectorSettingsDevicesFragment : multiSignoutItem.title = stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices) multiSignoutItem.setTextColor(color) views.deviceListOtherSessions.isVisible = true + val devices = if (isShowingIpAddress) otherDevices else otherDevices.map { it.copy(deviceInfo = it.deviceInfo.copy(lastSeenIp = null)) } views.deviceListOtherSessions.render( - devices = otherDevices.take(NUMBER_OF_OTHER_DEVICES_TO_RENDER), - totalNumberOfDevices = otherDevices.size, - showViewAll = otherDevices.size > NUMBER_OF_OTHER_DEVICES_TO_RENDER + devices = devices.take(NUMBER_OF_OTHER_DEVICES_TO_RENDER), + totalNumberOfDevices = devices.size, + showViewAll = devices.size > NUMBER_OF_OTHER_DEVICES_TO_RENDER ) views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderToggleIpAddress).title = if (isShowingIpAddress) { stringProvider.getString(R.string.device_manager_other_sessions_hide_ip_address) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt index de1cd33d35..9d9cb15c28 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionItem.kt @@ -29,6 +29,7 @@ import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.onClick +import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.DrawableProvider import im.vector.app.core.resources.StringProvider @@ -69,6 +70,9 @@ abstract class OtherSessionItem : VectorEpoxyModel(R.la @EpoxyAttribute var selected: Boolean = false + @EpoxyAttribute + var ipAddress: String? = null + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var clickListener: ClickListener? = null @@ -100,6 +104,7 @@ abstract class OtherSessionItem : VectorEpoxyModel(R.la holder.otherSessionDescriptionTextView.setTextColor(it) } holder.otherSessionDescriptionTextView.setCompoundDrawablesWithIntrinsicBounds(sessionDescriptionDrawable, null, null, null) + holder.otherSessionIpAddressTextView.setTextOrHide(ipAddress) holder.otherSessionItemBackgroundView.isSelected = selected } @@ -108,6 +113,7 @@ abstract class OtherSessionItem : VectorEpoxyModel(R.la val otherSessionVerificationStatusImageView by bind(R.id.otherSessionVerificationStatusImageView) val otherSessionNameTextView by bind(R.id.otherSessionNameTextView) val otherSessionDescriptionTextView by bind(R.id.otherSessionDescriptionTextView) + val otherSessionIpAddressTextView by bind(R.id.otherSessionIpAddressTextView) val otherSessionItemBackgroundView by bind(R.id.otherSessionItemBackground) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt index 8d70552101..5e2549f42a 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/OtherSessionsController.kt @@ -72,6 +72,7 @@ class OtherSessionsController @Inject constructor( sessionDescription(description) sessionDescriptionDrawable(descriptionDrawable) sessionDescriptionColor(descriptionColor) + ipAddress(device.deviceInfo.lastSeenIp) stringProvider(host.stringProvider) colorProvider(host.colorProvider) drawableProvider(host.drawableProvider) diff --git a/vector/src/main/res/layout/item_other_session.xml b/vector/src/main/res/layout/item_other_session.xml index f514cea56b..dee96d2b2f 100644 --- a/vector/src/main/res/layout/item_other_session.xml +++ b/vector/src/main/res/layout/item_other_session.xml @@ -67,12 +67,23 @@ android:layout_height="wrap_content" android:layout_marginTop="2dp" android:drawablePadding="8dp" - app:layout_constraintBottom_toBottomOf="@id/otherSessionDeviceTypeImageView" app:layout_constraintEnd_toEndOf="@id/otherSessionNameTextView" app:layout_constraintStart_toStartOf="@id/otherSessionNameTextView" app:layout_constraintTop_toBottomOf="@id/otherSessionNameTextView" tools:text="@string/device_manager_verification_status_verified" /> + + + app:layout_constraintTop_toBottomOf="@id/otherSessionIpAddressTextView" /> From b5e8375592d43aaebfbcc20a6efe8694170f3668 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 8 Nov 2022 15:16:09 +0300 Subject: [PATCH 03/14] Toggle ip address on other sessions screen. --- .../v2/othersessions/OtherSessionsAction.kt | 1 + .../v2/othersessions/OtherSessionsFragment.kt | 21 ++++++++++++++++--- .../othersessions/OtherSessionsViewModel.kt | 8 +++++++ .../othersessions/OtherSessionsViewState.kt | 1 + .../src/main/res/menu/menu_other_sessions.xml | 5 +++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt index 24d2a08bdc..f249a9f0b6 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt @@ -33,4 +33,5 @@ sealed class OtherSessionsAction : VectorViewModelAction { object SelectAll : OtherSessionsAction() object DeselectAll : OtherSessionsAction() object MultiSignout : OtherSessionsAction() + object ToggleIpAddressVisibility: OtherSessionsAction() } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt index 487531646a..c2beeb4db5 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt @@ -85,6 +85,12 @@ class OtherSessionsFragment : menu.findItem(R.id.otherSessionsSelectAll).isVisible = isSelectModeEnabled menu.findItem(R.id.otherSessionsDeselectAll).isVisible = isSelectModeEnabled menu.findItem(R.id.otherSessionsSelect).isVisible = !isSelectModeEnabled && state.devices()?.isNotEmpty().orFalse() + menu.findItem(R.id.otherSessionsToggleIpAddress).isVisible = !isSelectModeEnabled + menu.findItem(R.id.otherSessionsToggleIpAddress).title = if (state.isShowingIpAddress) { + getString(R.string.device_manager_other_sessions_hide_ip_address) + } else { + getString(R.string.device_manager_other_sessions_show_ip_address) + } updateMultiSignoutMenuItem(menu, state) } } @@ -130,10 +136,18 @@ class OtherSessionsFragment : confirmMultiSignout() true } + R.id.otherSessionsToggleIpAddress -> { + toggleIpAddressVisibility() + true + } else -> false } } + private fun toggleIpAddressVisibility() { + viewModel.handle(OtherSessionsAction.ToggleIpAddressVisibility) + } + private fun confirmMultiSignout() { activity?.let { buildConfirmSignoutDialogUseCase.execute(it, this::multiSignout) @@ -213,7 +227,7 @@ class OtherSessionsFragment : updateLoading(state.isLoading) if (state.devices is Success) { val devices = state.devices.invoke() - renderDevices(devices, state.currentFilter) + renderDevices(devices, state.currentFilter, state.isShowingIpAddress) updateToolbar(devices, state.isSelectModeEnabled) } } @@ -237,7 +251,7 @@ class OtherSessionsFragment : toolbar?.title = title } - private fun renderDevices(devices: List, currentFilter: DeviceManagerFilterType) { + private fun renderDevices(devices: List, currentFilter: DeviceManagerFilterType, isShowingIpAddress: Boolean) { views.otherSessionsFilterBadgeImageView.isVisible = currentFilter != DeviceManagerFilterType.ALL_SESSIONS views.otherSessionsSecurityRecommendationView.isVisible = currentFilter != DeviceManagerFilterType.ALL_SESSIONS views.deviceListHeaderOtherSessions.isVisible = currentFilter == DeviceManagerFilterType.ALL_SESSIONS @@ -296,7 +310,8 @@ class OtherSessionsFragment : } else { views.deviceListOtherSessions.isVisible = true views.otherSessionsNotFoundLayout.isVisible = false - views.deviceListOtherSessions.render(devices = devices, totalNumberOfDevices = devices.size, showViewAll = false) + val mappedDevices = if (isShowingIpAddress) devices else devices.map { it.copy(deviceInfo = it.deviceInfo.copy(lastSeenIp = null)) } + views.deviceListOtherSessions.render(devices = mappedDevices, totalNumberOfDevices = mappedDevices.size, showViewAll = false) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt index c33490400b..d1302cf443 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt @@ -91,6 +91,14 @@ class OtherSessionsViewModel @AssistedInject constructor( OtherSessionsAction.DeselectAll -> handleDeselectAll() OtherSessionsAction.SelectAll -> handleSelectAll() OtherSessionsAction.MultiSignout -> handleMultiSignout() + OtherSessionsAction.ToggleIpAddressVisibility -> handleToggleIpAddressVisibility() + } + } + + private fun handleToggleIpAddressVisibility() = withState { state -> + val isShowingIpAddress = state.isShowingIpAddress + setState { + copy(isShowingIpAddress = !isShowingIpAddress) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt index c0b50fded8..f4dd3640ee 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt @@ -28,6 +28,7 @@ data class OtherSessionsViewState( val excludeCurrentDevice: Boolean = false, val isSelectModeEnabled: Boolean = false, val isLoading: Boolean = false, + val isShowingIpAddress: Boolean = false, ) : MavericksState { constructor(args: OtherSessionsArgs) : this(excludeCurrentDevice = args.excludeCurrentDevice) diff --git a/vector/src/main/res/menu/menu_other_sessions.xml b/vector/src/main/res/menu/menu_other_sessions.xml index 7893575dde..98f9dd8256 100644 --- a/vector/src/main/res/menu/menu_other_sessions.xml +++ b/vector/src/main/res/menu/menu_other_sessions.xml @@ -9,6 +9,11 @@ android:title="@string/device_manager_other_sessions_select" app:showAsAction="withText|never" /> + + Date: Tue, 8 Nov 2022 16:33:20 +0300 Subject: [PATCH 04/14] Toggle ip address on sessions overview screen. --- .../devices/v2/list/SessionInfoView.kt | 3 +++ .../devices/v2/list/SessionInfoViewState.kt | 1 + .../v2/overview/SessionOverviewAction.kt | 1 + .../v2/overview/SessionOverviewFragment.kt | 20 +++++++++++++++++++ .../v2/overview/SessionOverviewViewModel.kt | 8 ++++++++ .../v2/overview/SessionOverviewViewState.kt | 1 + .../main/res/menu/menu_session_overview.xml | 5 +++++ 7 files changed, 39 insertions(+) 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 index 3d9c3a8f37..6e7e57fc49 100644 --- 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 @@ -76,6 +76,7 @@ class SessionInfoView @JvmOverloads constructor( sessionInfoViewState.deviceFullInfo.isInactive, sessionInfoViewState.deviceFullInfo.deviceInfo, sessionInfoViewState.isLastSeenDetailsVisible, + sessionInfoViewState.isShowingIpAddress, dateFormatter, drawableProvider, colorProvider, @@ -157,6 +158,7 @@ class SessionInfoView @JvmOverloads constructor( isInactive: Boolean, deviceInfo: DeviceInfo, isLastSeenDetailsVisible: Boolean, + isShowingIpAddress: Boolean, dateFormatter: VectorDateFormatter, drawableProvider: DrawableProvider, colorProvider: ColorProvider, @@ -187,6 +189,7 @@ class SessionInfoView @JvmOverloads constructor( views.sessionInfoLastActivityTextView.isGone = true } views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible }) + views.sessionInfoLastIPAddressTextView.isVisible = isShowingIpAddress } private fun renderDetailsButton(isDetailsButtonVisible: Boolean) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt index 287bb956f5..5d3c4b4f4b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoViewState.kt @@ -25,4 +25,5 @@ data class SessionInfoViewState( val isDetailsButtonVisible: Boolean = true, val isLearnMoreLinkVisible: Boolean = false, val isLastSeenDetailsVisible: Boolean = false, + val isShowingIpAddress: Boolean = false, ) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt index 9a92d5b629..2b6c40eead 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewAction.kt @@ -29,4 +29,5 @@ sealed class SessionOverviewAction : VectorViewModelAction { val deviceId: String, val enabled: Boolean, ) : SessionOverviewAction() + object ToggleIpAddressVisibility : SessionOverviewAction() } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt index e149023f22..61f7ab39dd 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt @@ -19,6 +19,7 @@ package im.vector.app.features.settings.devices.v2.overview import android.app.Activity import android.os.Bundle import android.view.LayoutInflater +import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewGroup @@ -156,16 +157,34 @@ class SessionOverviewFragment : override fun getMenuRes() = R.menu.menu_session_overview + override fun handlePrepareMenu(menu: Menu) { + withState(viewModel) { state -> + menu.findItem(R.id.sessionOverviewToggleIpAddress).title = if (state.isShowingIpAddress) { + getString(R.string.device_manager_other_sessions_hide_ip_address) + } else { + getString(R.string.device_manager_other_sessions_show_ip_address) + } + } + } + override fun handleMenuItemSelected(item: MenuItem): Boolean { return when (item.itemId) { R.id.sessionOverviewRename -> { goToRenameSession() true } + R.id.sessionOverviewToggleIpAddress -> { + toggleIpAddressVisibility() + true + } else -> false } } + private fun toggleIpAddressVisibility() { + viewModel.handle(SessionOverviewAction.ToggleIpAddressVisibility) + } + private fun goToRenameSession() = withState(viewModel) { state -> viewNavigator.goToRenameSession(requireContext(), state.deviceId) } @@ -206,6 +225,7 @@ class SessionOverviewFragment : isDetailsButtonVisible = false, isLearnMoreLinkVisible = deviceInfo.roomEncryptionTrustLevel != RoomEncryptionTrustLevel.Default, isLastSeenDetailsVisible = !isCurrentSession, + isShowingIpAddress = viewState.isShowingIpAddress, ) views.sessionOverviewInfo.render(infoViewState, dateFormatter, drawableProvider, colorProvider, stringProvider) views.sessionOverviewInfo.onLearnMoreClickListener = { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index 59eeaaadb4..74ab5ce617 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -113,6 +113,14 @@ class SessionOverviewViewModel @AssistedInject constructor( is SessionOverviewAction.PasswordAuthDone -> handlePasswordAuthDone(action) SessionOverviewAction.ReAuthCancelled -> handleReAuthCancelled() is SessionOverviewAction.TogglePushNotifications -> handleTogglePusherAction(action) + SessionOverviewAction.ToggleIpAddressVisibility -> handleToggleIpAddressVisibility() + } + } + + private fun handleToggleIpAddressVisibility() = withState { state -> + val isShowingIpAddress = state.isShowingIpAddress + setState { + copy(isShowingIpAddress = !isShowingIpAddress) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt index 019dd2d724..0f66605f98 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt @@ -28,6 +28,7 @@ data class SessionOverviewViewState( val deviceInfo: Async = Uninitialized, val isLoading: Boolean = false, val notificationsStatus: NotificationsStatus = NotificationsStatus.NOT_SUPPORTED, + val isShowingIpAddress: Boolean = false, ) : MavericksState { constructor(args: SessionOverviewArgs) : this( deviceId = args.deviceId diff --git a/vector/src/main/res/menu/menu_session_overview.xml b/vector/src/main/res/menu/menu_session_overview.xml index 7de3953dcc..4179a0d975 100644 --- a/vector/src/main/res/menu/menu_session_overview.xml +++ b/vector/src/main/res/menu/menu_session_overview.xml @@ -4,6 +4,11 @@ xmlns:tools="http://schemas.android.com/tools" tools:ignore="AlwaysShowAction"> + + Date: Tue, 8 Nov 2022 17:43:48 +0300 Subject: [PATCH 05/14] Persist user preference of ip address visibility. --- .../features/settings/VectorPreferences.kt | 3 +++ .../settings/devices/v2/DevicesViewModel.kt | 21 ++++++++++++++++++- .../othersessions/OtherSessionsViewModel.kt | 19 ++++++++++++++++- .../v2/overview/SessionOverviewViewModel.kt | 17 +++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 9f40a7cede..3424c2b54c 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -209,6 +209,9 @@ class VectorPreferences @Inject constructor( private const val SETTINGS_SECURITY_USE_GRACE_PERIOD_FLAG = "SETTINGS_SECURITY_USE_GRACE_PERIOD_FLAG" const val SETTINGS_SECURITY_USE_COMPLETE_NOTIFICATIONS_FLAG = "SETTINGS_SECURITY_USE_COMPLETE_NOTIFICATIONS_FLAG" + // New Session Manager + const val SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS = "SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS" + // other const val SETTINGS_MEDIA_SAVING_PERIOD_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_KEY" private const val SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY = "SETTINGS_MEDIA_SAVING_PERIOD_SELECTED_KEY" diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt index 3cacf82f14..bf42867b38 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt @@ -16,15 +16,19 @@ package im.vector.app.features.settings.devices.v2 +import android.content.SharedPreferences +import androidx.core.content.edit import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.features.auth.PendingAuthHandler +import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase import im.vector.app.features.settings.devices.v2.signout.SignoutSessionResult @@ -53,6 +57,8 @@ class DevicesViewModel @AssistedInject constructor( private val interceptSignoutFlowResponseUseCase: InterceptSignoutFlowResponseUseCase, private val pendingAuthHandler: PendingAuthHandler, refreshDevicesUseCase: RefreshDevicesUseCase, + @DefaultPreferences + private val sharedPreferences: SharedPreferences, ) : VectorSessionsListViewModel(initialState, activeSessionHolder, refreshDevicesUseCase) { @AssistedFactory @@ -67,6 +73,14 @@ class DevicesViewModel @AssistedInject constructor( observeDevices() refreshDevicesOnCryptoDevicesChange() refreshDeviceList() + refreshIpAddressVisibility() + } + + private fun refreshIpAddressVisibility() { + val shouldShowIpAddress = sharedPreferences.getBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, false) + setState { + copy(isShowingIpAddress = shouldShowIpAddress) + } } private fun observeCurrentSessionCrossSigningInfo() { @@ -122,7 +136,12 @@ class DevicesViewModel @AssistedInject constructor( private fun handleToggleIpAddressVisibility() = withState { state -> val isShowingIpAddress = state.isShowingIpAddress - setState { copy(isShowingIpAddress = !isShowingIpAddress) } + setState { + copy(isShowingIpAddress = !isShowingIpAddress) + } + sharedPreferences.edit { + putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) + } } private fun handleVerifyCurrentSessionAction() { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt index d1302cf443..7cca2e54e1 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt @@ -16,15 +16,19 @@ package im.vector.app.features.settings.devices.v2.othersessions +import android.content.SharedPreferences +import androidx.core.content.edit import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.features.auth.PendingAuthHandler +import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.devices.v2.GetDeviceFullInfoListUseCase import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel @@ -48,7 +52,9 @@ class OtherSessionsViewModel @AssistedInject constructor( private val signoutSessionsUseCase: SignoutSessionsUseCase, private val interceptSignoutFlowResponseUseCase: InterceptSignoutFlowResponseUseCase, private val pendingAuthHandler: PendingAuthHandler, - refreshDevicesUseCase: RefreshDevicesUseCase + refreshDevicesUseCase: RefreshDevicesUseCase, + @DefaultPreferences + private val sharedPreferences: SharedPreferences, ) : VectorSessionsListViewModel( initialState, activeSessionHolder, refreshDevicesUseCase ) { @@ -64,6 +70,14 @@ class OtherSessionsViewModel @AssistedInject constructor( init { observeDevices(initialState.currentFilter) + refreshIpAddressVisibility() + } + + private fun refreshIpAddressVisibility() { + val shouldShowIpAddress = sharedPreferences.getBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, false) + setState { + copy(isShowingIpAddress = shouldShowIpAddress) + } } private fun observeDevices(currentFilter: DeviceManagerFilterType) { @@ -100,6 +114,9 @@ class OtherSessionsViewModel @AssistedInject constructor( setState { copy(isShowingIpAddress = !isShowingIpAddress) } + sharedPreferences.edit { + putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) + } } private fun handleFilterDevices(action: OtherSessionsAction.FilterDevices) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index 74ab5ce617..a344474eba 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -16,15 +16,19 @@ package im.vector.app.features.settings.devices.v2.overview +import android.content.SharedPreferences +import androidx.core.content.edit import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.features.auth.PendingAuthHandler +import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel import im.vector.app.features.settings.devices.v2.notification.GetNotificationsStatusUseCase @@ -58,6 +62,8 @@ class SessionOverviewViewModel @AssistedInject constructor( private val togglePushNotificationUseCase: TogglePushNotificationUseCase, private val getNotificationsStatusUseCase: GetNotificationsStatusUseCase, refreshDevicesUseCase: RefreshDevicesUseCase, + @DefaultPreferences + private val sharedPreferences: SharedPreferences, ) : VectorSessionsListViewModel( initialState, activeSessionHolder, refreshDevicesUseCase ) { @@ -74,6 +80,14 @@ class SessionOverviewViewModel @AssistedInject constructor( observeSessionInfo(initialState.deviceId) observeCurrentSessionInfo() observeNotificationsStatus(initialState.deviceId) + refreshIpAddressVisibility() + } + + private fun refreshIpAddressVisibility() { + val shouldShowIpAddress = sharedPreferences.getBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, false) + setState { + copy(isShowingIpAddress = shouldShowIpAddress) + } } private fun refreshPushers() { @@ -122,6 +136,9 @@ class SessionOverviewViewModel @AssistedInject constructor( setState { copy(isShowingIpAddress = !isShowingIpAddress) } + sharedPreferences.edit { + putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) + } } private fun handleVerifySessionAction() = withState { viewState -> From 8bc70002d9eb047cdf39917a59b76b7173252c1b Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 8 Nov 2022 19:31:59 +0300 Subject: [PATCH 06/14] Add changelog. --- changelog.d/7546.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7546.feature diff --git a/changelog.d/7546.feature b/changelog.d/7546.feature new file mode 100644 index 0000000000..94450082c9 --- /dev/null +++ b/changelog.d/7546.feature @@ -0,0 +1 @@ +[Device Manager] Toggle IP address visibility From e888c1174726dedd0029efd004f57c1bda2ee71e Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 8 Nov 2022 20:05:16 +0300 Subject: [PATCH 07/14] Lint fix. --- .../settings/devices/v2/othersessions/OtherSessionsAction.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt index f249a9f0b6..bdad65ca43 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsAction.kt @@ -33,5 +33,5 @@ sealed class OtherSessionsAction : VectorViewModelAction { object SelectAll : OtherSessionsAction() object DeselectAll : OtherSessionsAction() object MultiSignout : OtherSessionsAction() - object ToggleIpAddressVisibility: OtherSessionsAction() + object ToggleIpAddressVisibility : OtherSessionsAction() } From 46c60f5897670e98c8e477477599afce631304b8 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 9 Nov 2022 16:57:16 +0300 Subject: [PATCH 08/14] Fix unit tests. --- .../app/features/settings/devices/v2/DevicesViewModelTest.kt | 4 ++++ .../devices/v2/othersessions/OtherSessionsViewModelTest.kt | 4 ++++ .../devices/v2/overview/SessionOverviewViewModelTest.kt | 4 ++++ .../java/im/vector/app/test/fakes/FakeSharedPreferences.kt | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt index 852fc64fd5..87bae3abb7 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt @@ -28,6 +28,7 @@ import im.vector.app.features.settings.devices.v2.verification.CurrentSessionCro import im.vector.app.features.settings.devices.v2.verification.GetCurrentSessionCrossSigningInfoUseCase import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakePendingAuthHandler +import im.vector.app.test.fakes.FakeSharedPreferences import im.vector.app.test.fakes.FakeSignoutSessionsUseCase import im.vector.app.test.fakes.FakeVerificationService import im.vector.app.test.test @@ -72,6 +73,7 @@ class DevicesViewModelTest { private val fakeInterceptSignoutFlowResponseUseCase = mockk() private val fakePendingAuthHandler = FakePendingAuthHandler() private val fakeRefreshDevicesUseCase = mockk(relaxUnitFun = true) + private val fakeSharedPreferences = FakeSharedPreferences() private fun createViewModel(): DevicesViewModel { return DevicesViewModel( @@ -85,6 +87,7 @@ class DevicesViewModelTest { interceptSignoutFlowResponseUseCase = fakeInterceptSignoutFlowResponseUseCase, pendingAuthHandler = fakePendingAuthHandler.instance, refreshDevicesUseCase = fakeRefreshDevicesUseCase, + sharedPreferences = fakeSharedPreferences, ) } @@ -97,6 +100,7 @@ class DevicesViewModelTest { givenVerificationService() givenCurrentSessionCrossSigningInfo() givenDeviceFullInfoList(deviceId1 = A_DEVICE_ID_1, deviceId2 = A_DEVICE_ID_2) + fakeSharedPreferences.givenSessionManagerShowIpAddress(false) } private fun givenVerificationService(): FakeVerificationService { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt index e01d6e058c..e7bb14695c 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt @@ -26,6 +26,7 @@ import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakePendingAuthHandler +import im.vector.app.test.fakes.FakeSharedPreferences import im.vector.app.test.fakes.FakeSignoutSessionsUseCase import im.vector.app.test.fakes.FakeVerificationService import im.vector.app.test.fixtures.aDeviceFullInfo @@ -68,6 +69,7 @@ class OtherSessionsViewModelTest { private val fakeSignoutSessionsUseCase = FakeSignoutSessionsUseCase() private val fakeInterceptSignoutFlowResponseUseCase = mockk() private val fakePendingAuthHandler = FakePendingAuthHandler() + private val fakeSharedPreferences = FakeSharedPreferences() private fun createViewModel(viewState: OtherSessionsViewState = OtherSessionsViewState(defaultArgs)) = OtherSessionsViewModel( @@ -78,6 +80,7 @@ class OtherSessionsViewModelTest { interceptSignoutFlowResponseUseCase = fakeInterceptSignoutFlowResponseUseCase, pendingAuthHandler = fakePendingAuthHandler.instance, refreshDevicesUseCase = fakeRefreshDevicesUseCase, + sharedPreferences = fakeSharedPreferences, ) @Before @@ -87,6 +90,7 @@ class OtherSessionsViewModelTest { every { SystemClock.elapsedRealtime() } returns 1234 givenVerificationService() + fakeSharedPreferences.givenSessionManagerShowIpAddress(false) } private fun givenVerificationService(): FakeVerificationService { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt index b2ab939bd1..aec555d8eb 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt @@ -28,6 +28,7 @@ import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowRe import im.vector.app.features.settings.devices.v2.verification.CheckIfCurrentSessionCanBeVerifiedUseCase import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakePendingAuthHandler +import im.vector.app.test.fakes.FakeSharedPreferences import im.vector.app.test.fakes.FakeSignoutSessionUseCase import im.vector.app.test.fakes.FakeTogglePushNotificationUseCase import im.vector.app.test.fakes.FakeVerificationService @@ -77,6 +78,7 @@ class SessionOverviewViewModelTest { private val togglePushNotificationUseCase = FakeTogglePushNotificationUseCase() private val fakeGetNotificationsStatusUseCase = mockk() private val notificationsStatus = NotificationsStatus.ENABLED + private val fakeSharedPreferences = FakeSharedPreferences() private fun createViewModel() = SessionOverviewViewModel( initialState = SessionOverviewViewState(args), @@ -89,6 +91,7 @@ class SessionOverviewViewModelTest { refreshDevicesUseCase = refreshDevicesUseCase, togglePushNotificationUseCase = togglePushNotificationUseCase.instance, getNotificationsStatusUseCase = fakeGetNotificationsStatusUseCase, + sharedPreferences = fakeSharedPreferences, ) @Before @@ -99,6 +102,7 @@ class SessionOverviewViewModelTest { givenVerificationService() every { fakeGetNotificationsStatusUseCase.execute(A_SESSION_ID_1) } returns flowOf(notificationsStatus) + fakeSharedPreferences.givenSessionManagerShowIpAddress(false) } private fun givenVerificationService(): FakeVerificationService { diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt index f9d525fd13..0242bfe148 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt @@ -18,6 +18,7 @@ package im.vector.app.test.fakes import android.content.SharedPreferences import im.vector.app.features.settings.FontScaleValue +import im.vector.app.features.settings.VectorPreferences.Companion.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS import io.mockk.every import io.mockk.mockk @@ -32,4 +33,8 @@ class FakeSharedPreferences : SharedPreferences by mockk() { every { contains("APPLICATION_USE_SYSTEM_FONT_SCALE_KEY") } returns true every { getBoolean("APPLICATION_USE_SYSTEM_FONT_SCALE_KEY", any()) } returns useSystemScale } + + fun givenSessionManagerShowIpAddress(showIpAddress: Boolean) { + every { getBoolean(SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, any()) } returns showIpAddress + } } From f63c6c328fc1a13adbb15da68367373a0cc82752 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 17 Nov 2022 13:19:40 +0300 Subject: [PATCH 09/14] Fix italic text is truncated when bubble mode and markdown is enabled. --- .../im/vector/app/features/html/EventHtmlRenderer.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt index 9e869ecde1..a5bf6cc184 100644 --- a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt @@ -27,6 +27,7 @@ package im.vector.app.features.html import android.content.Context import android.content.res.Resources +import android.graphics.Typeface import android.graphics.drawable.Drawable import android.text.Spannable import androidx.core.text.toSpannable @@ -40,6 +41,7 @@ import im.vector.app.features.settings.VectorPreferences import io.noties.markwon.AbstractMarkwonPlugin import io.noties.markwon.Markwon import io.noties.markwon.MarkwonPlugin +import io.noties.markwon.MarkwonSpansFactory import io.noties.markwon.PrecomputedFutureTextSetterCompat import io.noties.markwon.ext.latex.JLatexMathPlugin import io.noties.markwon.ext.latex.JLatexMathTheme @@ -50,6 +52,8 @@ import io.noties.markwon.inlineparser.EntityInlineProcessor import io.noties.markwon.inlineparser.HtmlInlineProcessor import io.noties.markwon.inlineparser.MarkwonInlineParser import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin +import me.gujun.android.span.style.CustomTypefaceSpan +import org.commonmark.node.Emphasis import org.commonmark.node.Node import org.commonmark.parser.Parser import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl @@ -123,6 +127,11 @@ class EventHtmlRenderer @Inject constructor( ) ) .usePlugin(object : AbstractMarkwonPlugin() { + override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) { + builder.setFactory( + Emphasis::class.java + ) { _, _ -> CustomTypefaceSpan(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC)) } + } override fun configureParser(builder: Parser.Builder) { /* Configuring the Markwon block formatting processor. * Default settings are all Markdown blocks. Turn those off. From c788deacf5a3de628f974cf1556479938cc023ea Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 17 Nov 2022 13:26:09 +0300 Subject: [PATCH 10/14] Revert "Fix italic text is truncated when bubble mode and markdown is enabled." This reverts commit f63c6c328fc1a13adbb15da68367373a0cc82752. --- .../im/vector/app/features/html/EventHtmlRenderer.kt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt index a5bf6cc184..9e869ecde1 100644 --- a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt @@ -27,7 +27,6 @@ package im.vector.app.features.html import android.content.Context import android.content.res.Resources -import android.graphics.Typeface import android.graphics.drawable.Drawable import android.text.Spannable import androidx.core.text.toSpannable @@ -41,7 +40,6 @@ import im.vector.app.features.settings.VectorPreferences import io.noties.markwon.AbstractMarkwonPlugin import io.noties.markwon.Markwon import io.noties.markwon.MarkwonPlugin -import io.noties.markwon.MarkwonSpansFactory import io.noties.markwon.PrecomputedFutureTextSetterCompat import io.noties.markwon.ext.latex.JLatexMathPlugin import io.noties.markwon.ext.latex.JLatexMathTheme @@ -52,8 +50,6 @@ import io.noties.markwon.inlineparser.EntityInlineProcessor import io.noties.markwon.inlineparser.HtmlInlineProcessor import io.noties.markwon.inlineparser.MarkwonInlineParser import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin -import me.gujun.android.span.style.CustomTypefaceSpan -import org.commonmark.node.Emphasis import org.commonmark.node.Node import org.commonmark.parser.Parser import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl @@ -127,11 +123,6 @@ class EventHtmlRenderer @Inject constructor( ) ) .usePlugin(object : AbstractMarkwonPlugin() { - override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) { - builder.setFactory( - Emphasis::class.java - ) { _, _ -> CustomTypefaceSpan(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC)) } - } override fun configureParser(builder: Parser.Builder) { /* Configuring the Markwon block formatting processor. * Default settings are all Markdown blocks. Turn those off. From 6c45490dd19034b407d07fcab60b5aff23074bf1 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 21 Nov 2022 18:44:45 +0300 Subject: [PATCH 11/14] Code review fixes. --- .../src/main/res/values/config-settings.xml | 1 + .../features/settings/VectorPreferences.kt | 10 ++++++ .../settings/devices/v2/DevicesViewModel.kt | 12 ++----- .../othersessions/OtherSessionsViewModel.kt | 12 ++----- .../v2/overview/SessionOverviewViewModel.kt | 12 ++----- .../main/res/layout/item_other_session.xml | 6 ++-- .../devices/v2/DevicesViewModelTest.kt | 33 ++++++++++++++++--- .../OtherSessionsViewModelTest.kt | 8 ++--- .../overview/SessionOverviewViewModelTest.kt | 8 ++--- .../app/test/fakes/FakeSharedPreferences.kt | 5 --- .../app/test/fakes/FakeVectorPreferences.kt | 4 +++ 11 files changed, 65 insertions(+), 46 deletions(-) diff --git a/vector-config/src/main/res/values/config-settings.xml b/vector-config/src/main/res/values/config-settings.xml index 504c587b8d..ef9695a080 100755 --- a/vector-config/src/main/res/values/config-settings.xml +++ b/vector-config/src/main/res/values/config-settings.xml @@ -51,6 +51,7 @@ false true false + false diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 3424c2b54c..30b5ef9131 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -1231,4 +1231,14 @@ class VectorPreferences @Inject constructor( return vectorFeatures.isVoiceBroadcastEnabled() && defaultPrefs.getBoolean(SETTINGS_LABS_VOICE_BROADCAST_KEY, getDefault(R.bool.settings_labs_enable_voice_broadcast_default)) } + + fun showIpAddressInDeviceManagerScreens(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, getDefault(R.bool.settings_device_manager_show_ip_address)) + } + + fun setIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) { + defaultPrefs.edit { + putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, isVisible) + } + } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt index b0ca32016f..971fb123f0 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt @@ -16,15 +16,12 @@ package im.vector.app.features.settings.devices.v2 -import android.content.SharedPreferences -import androidx.core.content.edit import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.core.di.ActiveSessionHolder -import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.features.auth.PendingAuthHandler @@ -53,8 +50,7 @@ class DevicesViewModel @AssistedInject constructor( private val interceptSignoutFlowResponseUseCase: InterceptSignoutFlowResponseUseCase, private val pendingAuthHandler: PendingAuthHandler, refreshDevicesUseCase: RefreshDevicesUseCase, - @DefaultPreferences - private val sharedPreferences: SharedPreferences, + private val vectorPreferences: VectorPreferences, ) : VectorSessionsListViewModel(initialState, activeSessionHolder, refreshDevicesUseCase) { @AssistedFactory @@ -73,7 +69,7 @@ class DevicesViewModel @AssistedInject constructor( } private fun refreshIpAddressVisibility() { - val shouldShowIpAddress = sharedPreferences.getBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, false) + val shouldShowIpAddress = vectorPreferences.showIpAddressInDeviceManagerScreens() setState { copy(isShowingIpAddress = shouldShowIpAddress) } @@ -135,9 +131,7 @@ class DevicesViewModel @AssistedInject constructor( setState { copy(isShowingIpAddress = !isShowingIpAddress) } - sharedPreferences.edit { - putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) - } + vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!isShowingIpAddress) } private fun handleVerifyCurrentSessionAction() { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt index fb20f0fd31..0f1dcca4cc 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt @@ -16,15 +16,12 @@ package im.vector.app.features.settings.devices.v2.othersessions -import android.content.SharedPreferences -import androidx.core.content.edit import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.core.di.ActiveSessionHolder -import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.features.auth.PendingAuthHandler @@ -47,8 +44,7 @@ class OtherSessionsViewModel @AssistedInject constructor( private val signoutSessionsUseCase: SignoutSessionsUseCase, private val pendingAuthHandler: PendingAuthHandler, refreshDevicesUseCase: RefreshDevicesUseCase, - @DefaultPreferences - private val sharedPreferences: SharedPreferences, + private val vectorPreferences: VectorPreferences, ) : VectorSessionsListViewModel( initialState, activeSessionHolder, refreshDevicesUseCase ) { @@ -68,7 +64,7 @@ class OtherSessionsViewModel @AssistedInject constructor( } private fun refreshIpAddressVisibility() { - val shouldShowIpAddress = sharedPreferences.getBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, false) + val shouldShowIpAddress = vectorPreferences.showIpAddressInDeviceManagerScreens() setState { copy(isShowingIpAddress = shouldShowIpAddress) } @@ -108,9 +104,7 @@ class OtherSessionsViewModel @AssistedInject constructor( setState { copy(isShowingIpAddress = !isShowingIpAddress) } - sharedPreferences.edit { - putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) - } + vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!isShowingIpAddress) } private fun handleFilterDevices(action: OtherSessionsAction.FilterDevices) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index a105c40e9c..6c159fd50e 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -16,15 +16,12 @@ package im.vector.app.features.settings.devices.v2.overview -import android.content.SharedPreferences -import androidx.core.content.edit import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.core.di.ActiveSessionHolder -import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.features.auth.PendingAuthHandler @@ -58,8 +55,7 @@ class SessionOverviewViewModel @AssistedInject constructor( private val togglePushNotificationUseCase: TogglePushNotificationUseCase, private val getNotificationsStatusUseCase: GetNotificationsStatusUseCase, refreshDevicesUseCase: RefreshDevicesUseCase, - @DefaultPreferences - private val sharedPreferences: SharedPreferences, + private val vectorPreferences: VectorPreferences, ) : VectorSessionsListViewModel( initialState, activeSessionHolder, refreshDevicesUseCase ) { @@ -80,7 +76,7 @@ class SessionOverviewViewModel @AssistedInject constructor( } private fun refreshIpAddressVisibility() { - val shouldShowIpAddress = sharedPreferences.getBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, false) + val shouldShowIpAddress = vectorPreferences.showIpAddressInDeviceManagerScreens() setState { copy(isShowingIpAddress = shouldShowIpAddress) } @@ -134,9 +130,7 @@ class SessionOverviewViewModel @AssistedInject constructor( setState { copy(isShowingIpAddress = !isShowingIpAddress) } - sharedPreferences.edit { - putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) - } + vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!isShowingIpAddress) } private fun handleVerifySessionAction() = withState { viewState -> diff --git a/vector/src/main/res/layout/item_other_session.xml b/vector/src/main/res/layout/item_other_session.xml index dee96d2b2f..a6205e7d50 100644 --- a/vector/src/main/res/layout/item_other_session.xml +++ b/vector/src/main/res/layout/item_other_session.xml @@ -13,7 +13,7 @@ android:layout_width="0dp" android:layout_height="0dp" android:background="@drawable/bg_other_session" - app:layout_constraintBottom_toBottomOf="@id/otherSessionVerificationStatusImageView" + app:layout_constraintBottom_toBottomOf="@id/otherSessionSeparator" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -53,11 +53,12 @@ android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginEnd="8dp" + android:layout_marginTop="8dp" android:ellipsize="end" android:lines="1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/otherSessionDeviceTypeImageView" - app:layout_constraintTop_toTopOf="@id/otherSessionDeviceTypeImageView" + app:layout_constraintTop_toTopOf="@id/otherSessionItemBackground" tools:text="Element Mobile: Android" /> () private val fakePendingAuthHandler = FakePendingAuthHandler() private val fakeRefreshDevicesUseCase = mockk(relaxUnitFun = true) - private val fakeSharedPreferences = FakeSharedPreferences() + private val fakeVectorPreferences = FakeVectorPreferences() private fun createViewModel(): DevicesViewModel { return DevicesViewModel( @@ -87,7 +89,7 @@ class DevicesViewModelTest { interceptSignoutFlowResponseUseCase = fakeInterceptSignoutFlowResponseUseCase, pendingAuthHandler = fakePendingAuthHandler.instance, refreshDevicesUseCase = fakeRefreshDevicesUseCase, - sharedPreferences = fakeSharedPreferences, + vectorPreferences = fakeVectorPreferences.instance, ) } @@ -100,7 +102,7 @@ class DevicesViewModelTest { givenVerificationService() givenCurrentSessionCrossSigningInfo() givenDeviceFullInfoList(deviceId1 = A_DEVICE_ID_1, deviceId2 = A_DEVICE_ID_2) - fakeSharedPreferences.givenSessionManagerShowIpAddress(false) + fakeVectorPreferences.givenSessionManagerShowIpAddress(false) } private fun givenVerificationService(): FakeVerificationService { @@ -347,6 +349,29 @@ class DevicesViewModelTest { } } + @Test + fun `given the viewModel when initializing it then view state of ip address visibility is false`() { + // When + val viewModelTest = createViewModel().test() + + // Then + viewModelTest.assertLatestState { it.isShowingIpAddress == false } + viewModelTest.finish() + } + + @Test + fun `given the viewModel when toggleIpAddressVisibility action is triggered then view state and preference change accordingly`() { + // When + val viewModel = createViewModel() + val viewModelTest = viewModel.test() + viewModel.handle(DevicesAction.ToggleIpAddressVisibility) + + // Then + viewModelTest.assertLatestState { it.isShowingIpAddress == true } + every { fakeVectorPreferences.instance.setIpAddressVisibilityInDeviceManagerScreens(true) } just runs + viewModelTest.finish() + } + private fun givenCurrentSessionCrossSigningInfo(): CurrentSessionCrossSigningInfo { val currentSessionCrossSigningInfo = mockk() every { currentSessionCrossSigningInfo.deviceId } returns A_CURRENT_DEVICE_ID diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt index d6ed5a61a7..054369ec9f 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt @@ -25,8 +25,8 @@ import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakePendingAuthHandler -import im.vector.app.test.fakes.FakeSharedPreferences import im.vector.app.test.fakes.FakeSignoutSessionsUseCase +import im.vector.app.test.fakes.FakeVectorPreferences import im.vector.app.test.fakes.FakeVerificationService import im.vector.app.test.fixtures.aDeviceFullInfo import im.vector.app.test.test @@ -67,7 +67,7 @@ class OtherSessionsViewModelTest { private val fakeRefreshDevicesUseCase = mockk(relaxed = true) private val fakeSignoutSessionsUseCase = FakeSignoutSessionsUseCase() private val fakePendingAuthHandler = FakePendingAuthHandler() - private val fakeSharedPreferences = FakeSharedPreferences() + private val fakeVectorPreferences = FakeVectorPreferences() private fun createViewModel(viewState: OtherSessionsViewState = OtherSessionsViewState(defaultArgs)) = OtherSessionsViewModel( @@ -77,7 +77,7 @@ class OtherSessionsViewModelTest { signoutSessionsUseCase = fakeSignoutSessionsUseCase.instance, pendingAuthHandler = fakePendingAuthHandler.instance, refreshDevicesUseCase = fakeRefreshDevicesUseCase, - sharedPreferences = fakeSharedPreferences, + vectorPreferences = fakeVectorPreferences.instance, ) @Before @@ -87,7 +87,7 @@ class OtherSessionsViewModelTest { every { SystemClock.elapsedRealtime() } returns 1234 givenVerificationService() - fakeSharedPreferences.givenSessionManagerShowIpAddress(false) + fakeVectorPreferences.givenSessionManagerShowIpAddress(false) } private fun givenVerificationService(): FakeVerificationService { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt index c4ab82b7e8..3f81abd483 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt @@ -28,9 +28,9 @@ import im.vector.app.features.settings.devices.v2.verification.CheckIfCurrentSes import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakeGetNotificationsStatusUseCase import im.vector.app.test.fakes.FakePendingAuthHandler -import im.vector.app.test.fakes.FakeSharedPreferences import im.vector.app.test.fakes.FakeSignoutSessionsUseCase import im.vector.app.test.fakes.FakeTogglePushNotificationUseCase +import im.vector.app.test.fakes.FakeVectorPreferences import im.vector.app.test.fakes.FakeVerificationService import im.vector.app.test.test import im.vector.app.test.testDispatcher @@ -78,7 +78,7 @@ class SessionOverviewViewModelTest { private val togglePushNotificationUseCase = FakeTogglePushNotificationUseCase() private val fakeGetNotificationsStatusUseCase = FakeGetNotificationsStatusUseCase() private val notificationsStatus = NotificationsStatus.ENABLED - private val fakeSharedPreferences = FakeSharedPreferences() + private val fakeVectorPreferences = FakeVectorPreferences() private fun createViewModel() = SessionOverviewViewModel( initialState = SessionOverviewViewState(args), @@ -91,7 +91,7 @@ class SessionOverviewViewModelTest { refreshDevicesUseCase = refreshDevicesUseCase, togglePushNotificationUseCase = togglePushNotificationUseCase.instance, getNotificationsStatusUseCase = fakeGetNotificationsStatusUseCase.instance, - sharedPreferences = fakeSharedPreferences, + vectorPreferences = fakeVectorPreferences.instance, ) @Before @@ -106,7 +106,7 @@ class SessionOverviewViewModelTest { A_SESSION_ID_1, notificationsStatus ) - fakeSharedPreferences.givenSessionManagerShowIpAddress(false) + fakeVectorPreferences.givenSessionManagerShowIpAddress(false) } private fun givenVerificationService(): FakeVerificationService { diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt index 0242bfe148..f9d525fd13 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeSharedPreferences.kt @@ -18,7 +18,6 @@ package im.vector.app.test.fakes import android.content.SharedPreferences import im.vector.app.features.settings.FontScaleValue -import im.vector.app.features.settings.VectorPreferences.Companion.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS import io.mockk.every import io.mockk.mockk @@ -33,8 +32,4 @@ class FakeSharedPreferences : SharedPreferences by mockk() { every { contains("APPLICATION_USE_SYSTEM_FONT_SCALE_KEY") } returns true every { getBoolean("APPLICATION_USE_SYSTEM_FONT_SCALE_KEY", any()) } returns useSystemScale } - - fun givenSessionManagerShowIpAddress(showIpAddress: Boolean) { - every { getBoolean(SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, any()) } returns showIpAddress - } } diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt index 4baa7e2b90..f05f5f1493 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt @@ -52,4 +52,8 @@ class FakeVectorPreferences { fun verifySetNotificationEnabledForDevice(enabled: Boolean, inverse: Boolean = false) { verify(inverse = inverse) { instance.setNotificationEnabledForDevice(enabled) } } + + fun givenSessionManagerShowIpAddress(showIpAddress: Boolean) { + every { instance.showIpAddressInDeviceManagerScreens() } returns showIpAddress + } } From ab749eee6a174edc20dc371f8bc7479bfa02fc4f Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 22 Nov 2022 16:05:37 +0300 Subject: [PATCH 12/14] Code review fixes. --- .../settings/devices/v2/DevicesViewModel.kt | 29 +++++++++++++----- .../v2/ToggleIpAddressVisibilityUseCase.kt | 30 +++++++++++++++++++ .../othersessions/OtherSessionsViewModel.kt | 27 ++++++++++++----- .../v2/overview/SessionOverviewViewModel.kt | 26 +++++++++++----- .../devices/v2/DevicesViewModelTest.kt | 9 +++++- .../OtherSessionsViewModelTest.kt | 3 ++ .../overview/SessionOverviewViewModelTest.kt | 3 ++ 7 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt index 971fb123f0..236237ddbb 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt @@ -16,6 +16,7 @@ package im.vector.app.features.settings.devices.v2 +import android.content.SharedPreferences import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted @@ -51,7 +52,11 @@ class DevicesViewModel @AssistedInject constructor( private val pendingAuthHandler: PendingAuthHandler, refreshDevicesUseCase: RefreshDevicesUseCase, private val vectorPreferences: VectorPreferences, -) : VectorSessionsListViewModel(initialState, activeSessionHolder, refreshDevicesUseCase) { + private val toggleIpAddressVisibilityUseCase: ToggleIpAddressVisibilityUseCase, +) : VectorSessionsListViewModel(initialState, activeSessionHolder, refreshDevicesUseCase), + SharedPreferences.OnSharedPreferenceChangeListener { @AssistedFactory interface Factory : MavericksAssistedViewModelFactory { @@ -66,6 +71,20 @@ class DevicesViewModel @AssistedInject constructor( refreshDevicesOnCryptoDevicesChange() refreshDeviceList() refreshIpAddressVisibility() + observePreferences() + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + refreshIpAddressVisibility() + } + + private fun observePreferences() { + vectorPreferences.subscribeToChanges(this) + } + + override fun onCleared() { + vectorPreferences.unsubscribeToChanges(this) + super.onCleared() } private fun refreshIpAddressVisibility() { @@ -126,12 +145,8 @@ class DevicesViewModel @AssistedInject constructor( } } - private fun handleToggleIpAddressVisibility() = withState { state -> - val isShowingIpAddress = state.isShowingIpAddress - setState { - copy(isShowingIpAddress = !isShowingIpAddress) - } - vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!isShowingIpAddress) + private fun handleToggleIpAddressVisibility() { + toggleIpAddressVisibilityUseCase.execute() } private fun handleVerifyCurrentSessionAction() { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt new file mode 100644 index 0000000000..ef99d3489a --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt @@ -0,0 +1,30 @@ +/* + * 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 + +import im.vector.app.features.settings.VectorPreferences +import javax.inject.Inject + +class ToggleIpAddressVisibilityUseCase @Inject constructor( + private val vectorPreferences: VectorPreferences, +) { + + fun execute() { + val currentVisibility = vectorPreferences.showIpAddressInDeviceManagerScreens() + vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!currentVisibility) + } +} diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt index 0f1dcca4cc..bd6e31dd4d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt @@ -16,6 +16,7 @@ package im.vector.app.features.settings.devices.v2.othersessions +import android.content.SharedPreferences import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted @@ -28,6 +29,7 @@ import im.vector.app.features.auth.PendingAuthHandler import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.devices.v2.GetDeviceFullInfoListUseCase import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase +import im.vector.app.features.settings.devices.v2.ToggleIpAddressVisibilityUseCase import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsReAuthNeeded @@ -45,9 +47,10 @@ class OtherSessionsViewModel @AssistedInject constructor( private val pendingAuthHandler: PendingAuthHandler, refreshDevicesUseCase: RefreshDevicesUseCase, private val vectorPreferences: VectorPreferences, + private val toggleIpAddressVisibilityUseCase: ToggleIpAddressVisibilityUseCase, ) : VectorSessionsListViewModel( initialState, activeSessionHolder, refreshDevicesUseCase -) { +), SharedPreferences.OnSharedPreferenceChangeListener { @AssistedFactory interface Factory : MavericksAssistedViewModelFactory { @@ -61,6 +64,20 @@ class OtherSessionsViewModel @AssistedInject constructor( init { observeDevices(initialState.currentFilter) refreshIpAddressVisibility() + observePreferences() + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + refreshIpAddressVisibility() + } + + private fun observePreferences() { + vectorPreferences.subscribeToChanges(this) + } + + override fun onCleared() { + vectorPreferences.unsubscribeToChanges(this) + super.onCleared() } private fun refreshIpAddressVisibility() { @@ -99,12 +116,8 @@ class OtherSessionsViewModel @AssistedInject constructor( } } - private fun handleToggleIpAddressVisibility() = withState { state -> - val isShowingIpAddress = state.isShowingIpAddress - setState { - copy(isShowingIpAddress = !isShowingIpAddress) - } - vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!isShowingIpAddress) + private fun handleToggleIpAddressVisibility() { + toggleIpAddressVisibilityUseCase.execute() } private fun handleFilterDevices(action: OtherSessionsAction.FilterDevices) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index 6c159fd50e..d423d4a743 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -16,6 +16,7 @@ package im.vector.app.features.settings.devices.v2.overview +import android.content.SharedPreferences import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import dagger.assisted.Assisted @@ -27,6 +28,7 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.features.auth.PendingAuthHandler import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase +import im.vector.app.features.settings.devices.v2.ToggleIpAddressVisibilityUseCase import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel import im.vector.app.features.settings.devices.v2.notification.GetNotificationsStatusUseCase import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase @@ -56,9 +58,10 @@ class SessionOverviewViewModel @AssistedInject constructor( private val getNotificationsStatusUseCase: GetNotificationsStatusUseCase, refreshDevicesUseCase: RefreshDevicesUseCase, private val vectorPreferences: VectorPreferences, + private val toggleIpAddressVisibilityUseCase: ToggleIpAddressVisibilityUseCase, ) : VectorSessionsListViewModel( initialState, activeSessionHolder, refreshDevicesUseCase -) { +), SharedPreferences.OnSharedPreferenceChangeListener { companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() @@ -73,8 +76,21 @@ class SessionOverviewViewModel @AssistedInject constructor( observeCurrentSessionInfo() observeNotificationsStatus(initialState.deviceId) refreshIpAddressVisibility() + observePreferences() } + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + refreshIpAddressVisibility() + } + + private fun observePreferences() { + vectorPreferences.subscribeToChanges(this) + } + + override fun onCleared() { + vectorPreferences.unsubscribeToChanges(this) + super.onCleared() + } private fun refreshIpAddressVisibility() { val shouldShowIpAddress = vectorPreferences.showIpAddressInDeviceManagerScreens() setState { @@ -125,12 +141,8 @@ class SessionOverviewViewModel @AssistedInject constructor( } } - private fun handleToggleIpAddressVisibility() = withState { state -> - val isShowingIpAddress = state.isShowingIpAddress - setState { - copy(isShowingIpAddress = !isShowingIpAddress) - } - vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!isShowingIpAddress) + private fun handleToggleIpAddressVisibility() { + toggleIpAddressVisibilityUseCase.execute() } private fun handleVerifySessionAction() = withState { viewState -> diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt index e34dd8e180..30320806e0 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt @@ -16,6 +16,7 @@ package im.vector.app.features.settings.devices.v2 +import android.content.SharedPreferences import android.os.SystemClock import com.airbnb.mvrx.Success import com.airbnb.mvrx.test.MavericksTestRule @@ -76,6 +77,7 @@ class DevicesViewModelTest { private val fakePendingAuthHandler = FakePendingAuthHandler() private val fakeRefreshDevicesUseCase = mockk(relaxUnitFun = true) private val fakeVectorPreferences = FakeVectorPreferences() + private val toggleIpAddressVisibilityUseCase = mockk() private fun createViewModel(): DevicesViewModel { return DevicesViewModel( @@ -90,6 +92,7 @@ class DevicesViewModelTest { pendingAuthHandler = fakePendingAuthHandler.instance, refreshDevicesUseCase = fakeRefreshDevicesUseCase, vectorPreferences = fakeVectorPreferences.instance, + toggleIpAddressVisibilityUseCase = toggleIpAddressVisibilityUseCase, ) } @@ -364,11 +367,15 @@ class DevicesViewModelTest { // When val viewModel = createViewModel() val viewModelTest = viewModel.test() + every { toggleIpAddressVisibilityUseCase.execute() } just runs + every { fakeVectorPreferences.instance.setIpAddressVisibilityInDeviceManagerScreens(true) } just runs + every { fakeVectorPreferences.instance.showIpAddressInDeviceManagerScreens() } returns true + viewModel.handle(DevicesAction.ToggleIpAddressVisibility) + viewModel.onSharedPreferenceChanged(null, null) // Then viewModelTest.assertLatestState { it.isShowingIpAddress == true } - every { fakeVectorPreferences.instance.setIpAddressVisibilityInDeviceManagerScreens(true) } just runs viewModelTest.finish() } diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt index 054369ec9f..82f40d911d 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt @@ -22,6 +22,7 @@ import com.airbnb.mvrx.test.MavericksTestRule import im.vector.app.features.settings.devices.v2.DeviceFullInfo import im.vector.app.features.settings.devices.v2.GetDeviceFullInfoListUseCase import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase +import im.vector.app.features.settings.devices.v2.ToggleIpAddressVisibilityUseCase import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakePendingAuthHandler @@ -68,6 +69,7 @@ class OtherSessionsViewModelTest { private val fakeSignoutSessionsUseCase = FakeSignoutSessionsUseCase() private val fakePendingAuthHandler = FakePendingAuthHandler() private val fakeVectorPreferences = FakeVectorPreferences() + private val toggleIpAddressVisibilityUseCase = mockk() private fun createViewModel(viewState: OtherSessionsViewState = OtherSessionsViewState(defaultArgs)) = OtherSessionsViewModel( @@ -78,6 +80,7 @@ class OtherSessionsViewModelTest { pendingAuthHandler = fakePendingAuthHandler.instance, refreshDevicesUseCase = fakeRefreshDevicesUseCase, vectorPreferences = fakeVectorPreferences.instance, + toggleIpAddressVisibilityUseCase = toggleIpAddressVisibilityUseCase, ) @Before diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt index 3f81abd483..287bdd159c 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModelTest.kt @@ -22,6 +22,7 @@ import com.airbnb.mvrx.Success import com.airbnb.mvrx.test.MavericksTestRule import im.vector.app.features.settings.devices.v2.DeviceFullInfo import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase +import im.vector.app.features.settings.devices.v2.ToggleIpAddressVisibilityUseCase import im.vector.app.features.settings.devices.v2.notification.NotificationsStatus import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase import im.vector.app.features.settings.devices.v2.verification.CheckIfCurrentSessionCanBeVerifiedUseCase @@ -79,6 +80,7 @@ class SessionOverviewViewModelTest { private val fakeGetNotificationsStatusUseCase = FakeGetNotificationsStatusUseCase() private val notificationsStatus = NotificationsStatus.ENABLED private val fakeVectorPreferences = FakeVectorPreferences() + private val toggleIpAddressVisibilityUseCase = mockk() private fun createViewModel() = SessionOverviewViewModel( initialState = SessionOverviewViewState(args), @@ -92,6 +94,7 @@ class SessionOverviewViewModelTest { togglePushNotificationUseCase = togglePushNotificationUseCase.instance, getNotificationsStatusUseCase = fakeGetNotificationsStatusUseCase.instance, vectorPreferences = fakeVectorPreferences.instance, + toggleIpAddressVisibilityUseCase = toggleIpAddressVisibilityUseCase, ) @Before From 5eb786b55f854ff7950115448655cd0a7f0303f5 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 22 Nov 2022 16:11:20 +0300 Subject: [PATCH 13/14] Code review fixes. --- .../app/features/settings/devices/v2/list/SessionInfoView.kt | 3 +-- .../app/features/settings/devices/v2/DevicesViewModelTest.kt | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) 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 index 6e7e57fc49..c6044d04a4 100644 --- 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 @@ -188,8 +188,7 @@ class SessionInfoView @JvmOverloads constructor( } else { views.sessionInfoLastActivityTextView.isGone = true } - views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible }) - views.sessionInfoLastIPAddressTextView.isVisible = isShowingIpAddress + views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible && isShowingIpAddress }) } private fun renderDetailsButton(isDetailsButtonVisible: Boolean) { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt index 30320806e0..16ccaab37f 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt @@ -16,7 +16,6 @@ package im.vector.app.features.settings.devices.v2 -import android.content.SharedPreferences import android.os.SystemClock import com.airbnb.mvrx.Success import com.airbnb.mvrx.test.MavericksTestRule From abea9b686a3407eea3e343061ae7dd5ab96ca38a Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 22 Nov 2022 18:02:48 +0300 Subject: [PATCH 14/14] Code review fixes. --- vector-config/src/main/res/values/config-settings.xml | 3 ++- .../java/im/vector/app/features/settings/VectorPreferences.kt | 4 ++-- .../app/features/settings/devices/v2/DevicesViewModel.kt | 2 +- .../settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt | 2 +- .../devices/v2/othersessions/OtherSessionsViewModel.kt | 2 +- .../settings/devices/v2/overview/SessionOverviewViewModel.kt | 2 +- .../app/features/settings/devices/v2/DevicesViewModelTest.kt | 2 +- .../java/im/vector/app/test/fakes/FakeVectorPreferences.kt | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/vector-config/src/main/res/values/config-settings.xml b/vector-config/src/main/res/values/config-settings.xml index ef9695a080..ad9c16c214 100755 --- a/vector-config/src/main/res/values/config-settings.xml +++ b/vector-config/src/main/res/values/config-settings.xml @@ -51,12 +51,13 @@ false true false - false + + false diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 30b5ef9131..447038d768 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -1232,8 +1232,8 @@ class VectorPreferences @Inject constructor( defaultPrefs.getBoolean(SETTINGS_LABS_VOICE_BROADCAST_KEY, getDefault(R.bool.settings_labs_enable_voice_broadcast_default)) } - fun showIpAddressInDeviceManagerScreens(): Boolean { - return defaultPrefs.getBoolean(SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, getDefault(R.bool.settings_device_manager_show_ip_address)) + fun showIpAddressInSessionManagerScreens(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, getDefault(R.bool.settings_session_manager_show_ip_address)) } fun setIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt index 236237ddbb..f42d5af398 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt @@ -88,7 +88,7 @@ class DevicesViewModel @AssistedInject constructor( } private fun refreshIpAddressVisibility() { - val shouldShowIpAddress = vectorPreferences.showIpAddressInDeviceManagerScreens() + val shouldShowIpAddress = vectorPreferences.showIpAddressInSessionManagerScreens() setState { copy(isShowingIpAddress = shouldShowIpAddress) } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt index ef99d3489a..1e1dc19c96 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ToggleIpAddressVisibilityUseCase.kt @@ -24,7 +24,7 @@ class ToggleIpAddressVisibilityUseCase @Inject constructor( ) { fun execute() { - val currentVisibility = vectorPreferences.showIpAddressInDeviceManagerScreens() + val currentVisibility = vectorPreferences.showIpAddressInSessionManagerScreens() vectorPreferences.setIpAddressVisibilityInDeviceManagerScreens(!currentVisibility) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt index bd6e31dd4d..a5282e7ba2 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt @@ -81,7 +81,7 @@ class OtherSessionsViewModel @AssistedInject constructor( } private fun refreshIpAddressVisibility() { - val shouldShowIpAddress = vectorPreferences.showIpAddressInDeviceManagerScreens() + val shouldShowIpAddress = vectorPreferences.showIpAddressInSessionManagerScreens() setState { copy(isShowingIpAddress = shouldShowIpAddress) } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index d423d4a743..472e0a4269 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -92,7 +92,7 @@ class SessionOverviewViewModel @AssistedInject constructor( super.onCleared() } private fun refreshIpAddressVisibility() { - val shouldShowIpAddress = vectorPreferences.showIpAddressInDeviceManagerScreens() + val shouldShowIpAddress = vectorPreferences.showIpAddressInSessionManagerScreens() setState { copy(isShowingIpAddress = shouldShowIpAddress) } diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt index 16ccaab37f..03177aac47 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt @@ -368,7 +368,7 @@ class DevicesViewModelTest { val viewModelTest = viewModel.test() every { toggleIpAddressVisibilityUseCase.execute() } just runs every { fakeVectorPreferences.instance.setIpAddressVisibilityInDeviceManagerScreens(true) } just runs - every { fakeVectorPreferences.instance.showIpAddressInDeviceManagerScreens() } returns true + every { fakeVectorPreferences.instance.showIpAddressInSessionManagerScreens() } returns true viewModel.handle(DevicesAction.ToggleIpAddressVisibility) viewModel.onSharedPreferenceChanged(null, null) diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt index f05f5f1493..d89764a77e 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt @@ -54,6 +54,6 @@ class FakeVectorPreferences { } fun givenSessionManagerShowIpAddress(showIpAddress: Boolean) { - every { instance.showIpAddressInDeviceManagerScreens() } returns showIpAddress + every { instance.showIpAddressInSessionManagerScreens() } returns showIpAddress } }