Merge pull request #7696 from vector-im/feature/mna/signout-all-other-sessions

[Session manager] Add action to signout all the other session (PSG-888)
This commit is contained in:
Maxime NATUREL 2022-12-05 17:50:14 +01:00 committed by GitHub
commit b5f6dc0034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 5 deletions

1
changelog.d/7693.feature Normal file
View File

@ -0,0 +1 @@
[Session manager] Add action to signout all the other session

View File

@ -3363,6 +3363,7 @@
<item quantity="one">Sign out of %1$d session</item> <item quantity="one">Sign out of %1$d session</item>
<item quantity="other">Sign out of %1$d sessions</item> <item quantity="other">Sign out of %1$d sessions</item>
</plurals> </plurals>
<string name="device_manager_signout_all_other_sessions">Sign out of all other sessions</string>
<string name="device_manager_other_sessions_show_ip_address">Show IP address</string> <string name="device_manager_other_sessions_show_ip_address">Show IP address</string>
<string name="device_manager_other_sessions_hide_ip_address">Hide IP address</string> <string name="device_manager_other_sessions_hide_ip_address">Hide IP address</string>
<string name="device_manager_session_overview_signout">Sign out of this session</string> <string name="device_manager_session_overview_signout">Sign out of this session</string>

View File

@ -53,6 +53,7 @@ import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationVie
import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState
import im.vector.app.features.settings.devices.v2.signout.BuildConfirmSignoutDialogUseCase import im.vector.app.features.settings.devices.v2.signout.BuildConfirmSignoutDialogUseCase
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
import javax.inject.Inject import javax.inject.Inject
@ -99,6 +100,7 @@ class VectorSettingsDevicesFragment :
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
initWaitingView() initWaitingView()
initCurrentSessionHeaderView()
initOtherSessionsHeaderView() initOtherSessionsHeaderView()
initOtherSessionsView() initOtherSessionsView()
initSecurityRecommendationsView() initSecurityRecommendationsView()
@ -139,6 +141,18 @@ class VectorSettingsDevicesFragment :
views.waitingView.waitingStatusText.isVisible = true views.waitingView.waitingStatusText.isVisible = true
} }
private fun initCurrentSessionHeaderView() {
views.deviceListHeaderCurrentSession.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.currentSessionHeaderSignoutOtherSessions -> {
confirmMultiSignoutOtherSessions()
true
}
else -> false
}
}
}
private fun initOtherSessionsHeaderView() { private fun initOtherSessionsHeaderView() {
views.deviceListHeaderOtherSessions.setOnMenuItemClickListener { menuItem -> views.deviceListHeaderOtherSessions.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
@ -247,7 +261,7 @@ class VectorSettingsDevicesFragment :
val otherDevices = devices?.filter { it.deviceInfo.deviceId != currentDeviceId } val otherDevices = devices?.filter { it.deviceInfo.deviceId != currentDeviceId }
renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount, isCurrentSessionVerified) renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount, isCurrentSessionVerified)
renderCurrentDevice(currentDeviceInfo) renderCurrentSessionView(currentDeviceInfo, hasOtherDevices = otherDevices?.isNotEmpty().orFalse())
renderOtherSessionsView(otherDevices, state.isShowingIpAddress) renderOtherSessionsView(otherDevices, state.isShowingIpAddress)
} else { } else {
hideSecurityRecommendations() hideSecurityRecommendations()
@ -310,11 +324,11 @@ class VectorSettingsDevicesFragment :
hideOtherSessionsView() hideOtherSessionsView()
} else { } else {
views.deviceListHeaderOtherSessions.isVisible = true views.deviceListHeaderOtherSessions.isVisible = true
val color = colorProvider.getColorFromAttribute(R.attr.colorError) val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError)
val multiSignoutItem = views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderMultiSignout) val multiSignoutItem = views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderMultiSignout)
val nbDevices = otherDevices.size val nbDevices = otherDevices.size
multiSignoutItem.title = stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices) multiSignoutItem.title = stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices)
multiSignoutItem.setTextColor(color) multiSignoutItem.setTextColor(colorDestructive)
views.deviceListOtherSessions.isVisible = true views.deviceListOtherSessions.isVisible = true
val devices = if (isShowingIpAddress) otherDevices else otherDevices.map { it.copy(deviceInfo = it.deviceInfo.copy(lastSeenIp = null)) } val devices = if (isShowingIpAddress) otherDevices else otherDevices.map { it.copy(deviceInfo = it.deviceInfo.copy(lastSeenIp = null)) }
views.deviceListOtherSessions.render( views.deviceListOtherSessions.render(
@ -327,7 +341,7 @@ class VectorSettingsDevicesFragment :
} else { } else {
stringProvider.getString(R.string.device_manager_other_sessions_show_ip_address) stringProvider.getString(R.string.device_manager_other_sessions_show_ip_address)
} }
} }
} }
private fun hideOtherSessionsView() { private fun hideOtherSessionsView() {
@ -335,9 +349,13 @@ class VectorSettingsDevicesFragment :
views.deviceListOtherSessions.isVisible = false views.deviceListOtherSessions.isVisible = false
} }
private fun renderCurrentDevice(currentDeviceInfo: DeviceFullInfo?) { private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?, hasOtherDevices: Boolean) {
currentDeviceInfo?.let { currentDeviceInfo?.let {
views.deviceListHeaderCurrentSession.isVisible = true views.deviceListHeaderCurrentSession.isVisible = true
val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError)
val signoutOtherSessionsItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignoutOtherSessions)
signoutOtherSessionsItem.setTextColor(colorDestructive)
signoutOtherSessionsItem.isVisible = hasOtherDevices
views.deviceListCurrentSession.isVisible = true views.deviceListCurrentSession.isVisible = true
val viewState = SessionInfoViewState( val viewState = SessionInfoViewState(
isCurrentSession = true, isCurrentSession = true,

View File

@ -67,6 +67,7 @@
app:layout_constraintTop_toBottomOf="@id/deviceListSecurityRecommendationsDivider" app:layout_constraintTop_toBottomOf="@id/deviceListSecurityRecommendationsDivider"
app:sessionsListHeaderDescription="" app:sessionsListHeaderDescription=""
app:sessionsListHeaderHasLearnMoreLink="false" app:sessionsListHeaderHasLearnMoreLink="false"
app:sessionsListHeaderMenu="@menu/menu_current_session_header"
app:sessionsListHeaderTitle="@string/device_manager_current_session_title" /> app:sessionsListHeaderTitle="@string/device_manager_current_session_title" />
<im.vector.app.features.settings.devices.v2.list.SessionInfoView <im.vector.app.features.settings.devices.v2.list.SessionInfoView

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction">
<item
android:id="@+id/currentSessionHeaderSignoutOtherSessions"
android:title="@string/device_manager_signout_all_other_sessions"
app:showAsAction="withText|never" />
</menu>