mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-18 07:11:58 +03:00
Hide multi signout if we have an external account manager (#8616)
This commit is contained in:
parent
425441546e
commit
8941e6396c
6 changed files with 47 additions and 12 deletions
|
@ -40,7 +40,7 @@ import timber.log.Timber
|
|||
|
||||
class DevicesViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: DevicesViewState,
|
||||
activeSessionHolder: ActiveSessionHolder,
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val getCurrentSessionCrossSigningInfoUseCase: GetCurrentSessionCrossSigningInfoUseCase,
|
||||
private val getDeviceFullInfoListUseCase: GetDeviceFullInfoListUseCase,
|
||||
private val refreshDevicesOnCryptoDevicesChangeUseCase: RefreshDevicesOnCryptoDevicesChangeUseCase,
|
||||
|
@ -69,6 +69,18 @@ class DevicesViewModel @AssistedInject constructor(
|
|||
refreshDeviceList()
|
||||
refreshIpAddressVisibility()
|
||||
observePreferences()
|
||||
initExternalAccountManagementUrl()
|
||||
}
|
||||
|
||||
private fun initExternalAccountManagementUrl() {
|
||||
setState {
|
||||
copy(
|
||||
externalAccountManagementUrl = activeSessionHolder.getSafeActiveSession()
|
||||
?.homeServerCapabilitiesService()
|
||||
?.getHomeServerCapabilities()
|
||||
?.externalAccountManagementUrl
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
|
|
|
@ -26,6 +26,7 @@ data class DevicesViewState(
|
|||
val devices: Async<DeviceFullInfoList> = Uninitialized,
|
||||
val isLoading: Boolean = false,
|
||||
val isShowingIpAddress: Boolean = false,
|
||||
val externalAccountManagementUrl: String? = null,
|
||||
) : MavericksState
|
||||
|
||||
data class DeviceFullInfoList(
|
||||
|
|
|
@ -290,8 +290,8 @@ class VectorSettingsDevicesFragment :
|
|||
val unverifiedSessionsCount = deviceFullInfoList?.unverifiedSessionsCount ?: 0
|
||||
|
||||
renderSecurityRecommendations(inactiveSessionsCount, unverifiedSessionsCount)
|
||||
renderCurrentSessionView(currentDeviceInfo, hasOtherDevices = otherDevices?.isNotEmpty().orFalse())
|
||||
renderOtherSessionsView(otherDevices, state.isShowingIpAddress)
|
||||
renderCurrentSessionView(currentDeviceInfo, hasOtherDevices = otherDevices?.isNotEmpty().orFalse(), state)
|
||||
renderOtherSessionsView(otherDevices, state)
|
||||
} else {
|
||||
hideSecurityRecommendations()
|
||||
hideCurrentSessionView()
|
||||
|
@ -347,13 +347,16 @@ class VectorSettingsDevicesFragment :
|
|||
hideInactiveSessionsRecommendation()
|
||||
}
|
||||
|
||||
private fun renderOtherSessionsView(otherDevices: List<DeviceFullInfo>?, isShowingIpAddress: Boolean) {
|
||||
private fun renderOtherSessionsView(otherDevices: List<DeviceFullInfo>?, state: DevicesViewState) {
|
||||
val isShowingIpAddress = state.isShowingIpAddress
|
||||
if (otherDevices.isNullOrEmpty()) {
|
||||
hideOtherSessionsView()
|
||||
} else {
|
||||
views.deviceListHeaderOtherSessions.isVisible = true
|
||||
val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError)
|
||||
val multiSignoutItem = views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderMultiSignout)
|
||||
// Hide multi signout if we have an external account manager
|
||||
multiSignoutItem.isVisible = state.externalAccountManagementUrl == null
|
||||
val nbDevices = otherDevices.size
|
||||
multiSignoutItem.title = stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices)
|
||||
multiSignoutItem.setTextColor(colorDestructive)
|
||||
|
@ -377,23 +380,24 @@ class VectorSettingsDevicesFragment :
|
|||
views.deviceListOtherSessions.isVisible = false
|
||||
}
|
||||
|
||||
private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?, hasOtherDevices: Boolean) {
|
||||
private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?, hasOtherDevices: Boolean, state: DevicesViewState) {
|
||||
currentDeviceInfo?.let {
|
||||
renderCurrentSessionHeaderView(hasOtherDevices)
|
||||
renderCurrentSessionHeaderView(hasOtherDevices, state)
|
||||
renderCurrentSessionListView(it)
|
||||
} ?: run {
|
||||
hideCurrentSessionView()
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderCurrentSessionHeaderView(hasOtherDevices: Boolean) {
|
||||
private fun renderCurrentSessionHeaderView(hasOtherDevices: Boolean, state: DevicesViewState) {
|
||||
views.deviceListHeaderCurrentSession.isVisible = true
|
||||
val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError)
|
||||
val signoutSessionItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignout)
|
||||
signoutSessionItem.setTextColor(colorDestructive)
|
||||
val signoutOtherSessionsItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignoutOtherSessions)
|
||||
signoutOtherSessionsItem.setTextColor(colorDestructive)
|
||||
signoutOtherSessionsItem.isVisible = hasOtherDevices
|
||||
// Hide signout other sessions if we have an external account manager
|
||||
signoutOtherSessionsItem.isVisible = hasOtherDevices && state.externalAccountManagementUrl == null
|
||||
}
|
||||
|
||||
private fun renderCurrentSessionListView(currentDeviceInfo: DeviceFullInfo) {
|
||||
|
|
|
@ -103,10 +103,15 @@ class OtherSessionsFragment :
|
|||
val nbDevices = viewState.devices()?.size ?: 0
|
||||
stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices)
|
||||
}
|
||||
multiSignoutItem.isVisible = if (viewState.isSelectModeEnabled) {
|
||||
viewState.devices.invoke()?.any { it.isSelected }.orFalse()
|
||||
multiSignoutItem.isVisible = if (viewState.externalAccountManagementUrl != null) {
|
||||
// Hide multi signout if we have an external account manager
|
||||
false
|
||||
} else {
|
||||
viewState.devices.invoke()?.isNotEmpty().orFalse()
|
||||
if (viewState.isSelectModeEnabled) {
|
||||
viewState.devices.invoke()?.any { it.isSelected }.orFalse()
|
||||
} else {
|
||||
viewState.devices.invoke()?.isNotEmpty().orFalse()
|
||||
}
|
||||
}
|
||||
val showAsActionFlag = if (viewState.isSelectModeEnabled) MenuItem.SHOW_AS_ACTION_IF_ROOM else MenuItem.SHOW_AS_ACTION_NEVER
|
||||
multiSignoutItem.setShowAsAction(showAsActionFlag or MenuItem.SHOW_AS_ACTION_WITH_TEXT)
|
||||
|
|
|
@ -41,7 +41,7 @@ import timber.log.Timber
|
|||
|
||||
class OtherSessionsViewModel @AssistedInject constructor(
|
||||
@Assisted private val initialState: OtherSessionsViewState,
|
||||
activeSessionHolder: ActiveSessionHolder,
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val getDeviceFullInfoListUseCase: GetDeviceFullInfoListUseCase,
|
||||
private val signoutSessionsUseCase: SignoutSessionsUseCase,
|
||||
private val pendingAuthHandler: PendingAuthHandler,
|
||||
|
@ -65,6 +65,18 @@ class OtherSessionsViewModel @AssistedInject constructor(
|
|||
observeDevices(initialState.currentFilter)
|
||||
refreshIpAddressVisibility()
|
||||
observePreferences()
|
||||
initExternalAccountManagementUrl()
|
||||
}
|
||||
|
||||
private fun initExternalAccountManagementUrl() {
|
||||
setState {
|
||||
copy(
|
||||
externalAccountManagementUrl = activeSessionHolder.getSafeActiveSession()
|
||||
?.homeServerCapabilitiesService()
|
||||
?.getHomeServerCapabilities()
|
||||
?.externalAccountManagementUrl
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
|
|
|
@ -29,6 +29,7 @@ data class OtherSessionsViewState(
|
|||
val isSelectModeEnabled: Boolean = false,
|
||||
val isLoading: Boolean = false,
|
||||
val isShowingIpAddress: Boolean = false,
|
||||
val externalAccountManagementUrl: String? = null,
|
||||
) : MavericksState {
|
||||
|
||||
constructor(args: OtherSessionsArgs) : this(excludeCurrentDevice = args.excludeCurrentDevice)
|
||||
|
|
Loading…
Reference in a new issue