-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toggle IP address visibility (PSG-860) #7546
Changes from 11 commits
456762a
eed2a74
b5e8375
0868869
f6bc28f
8bc7000
e888c11
46c60f5
b81fc4f
6f997e8
202c0c5
f63c6c3
c788dea
6c45490
ab749ee
5eb786b
abea9b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Device Manager] Toggle IP address visibility |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.SignoutSessionsReAuthNeeded | ||
|
@@ -49,6 +53,8 @@ class DevicesViewModel @AssistedInject constructor( | |
private val interceptSignoutFlowResponseUseCase: InterceptSignoutFlowResponseUseCase, | ||
private val pendingAuthHandler: PendingAuthHandler, | ||
refreshDevicesUseCase: RefreshDevicesUseCase, | ||
@DefaultPreferences | ||
private val sharedPreferences: SharedPreferences, | ||
) : VectorSessionsListViewModel<DevicesViewState, DevicesAction, DevicesViewEvent>(initialState, activeSessionHolder, refreshDevicesUseCase) { | ||
|
||
@AssistedFactory | ||
|
@@ -63,6 +69,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() { | ||
|
@@ -112,6 +126,17 @@ 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) | ||
} | ||
sharedPreferences.edit { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to encapsulate the domain layer code inside a UseCase. I would see 2 options in prefered order:
What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a use case to set the value. |
||
putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could write instead: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, done. |
||
views.sessionInfoLastIPAddressTextView.isVisible = isShowingIpAddress | ||
} | ||
|
||
private fun renderDetailsButton(isDetailsButtonVisible: Boolean) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -42,7 +46,9 @@ class OtherSessionsViewModel @AssistedInject constructor( | |
private val getDeviceFullInfoListUseCase: GetDeviceFullInfoListUseCase, | ||
private val signoutSessionsUseCase: SignoutSessionsUseCase, | ||
private val pendingAuthHandler: PendingAuthHandler, | ||
refreshDevicesUseCase: RefreshDevicesUseCase | ||
refreshDevicesUseCase: RefreshDevicesUseCase, | ||
@DefaultPreferences | ||
private val sharedPreferences: SharedPreferences, | ||
) : VectorSessionsListViewModel<OtherSessionsViewState, OtherSessionsAction, OtherSessionsViewEvents>( | ||
initialState, activeSessionHolder, refreshDevicesUseCase | ||
) { | ||
|
@@ -58,6 +64,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) { | ||
|
@@ -85,6 +99,17 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark for adding a reusable usecase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored. |
||
setState { | ||
copy(isShowingIpAddress = !isShowingIpAddress) | ||
} | ||
sharedPreferences.edit { | ||
putBoolean(VectorPreferences.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, !isShowingIpAddress) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should either define the default value for this preference somewhere in VectorPreferences or create a method to retrieve this setting so that it can be reused accross the screens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done.