Adding menu for current session header

This commit is contained in:
Maxime NATUREL 2022-12-02 17:08:29 +01:00
parent e857407bc1
commit 62e2f06e2a
4 changed files with 21 additions and 4 deletions

View file

@ -3359,6 +3359,7 @@
<item quantity="one">Sign out of %1$d session</item>
<item quantity="other">Sign out of %1$d sessions</item>
</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_hide_ip_address">Hide IP address</string>
<string name="device_manager_session_overview_signout">Sign out of this session</string>

View file

@ -247,7 +247,7 @@ class VectorSettingsDevicesFragment :
val otherDevices = devices?.filter { it.deviceInfo.deviceId != currentDeviceId }
renderSecurityRecommendations(state.inactiveSessionsCount, state.unverifiedSessionsCount, isCurrentSessionVerified)
renderCurrentDevice(currentDeviceInfo)
renderCurrentSessionView(currentDeviceInfo)
renderOtherSessionsView(otherDevices, state.isShowingIpAddress)
} else {
hideSecurityRecommendations()
@ -310,11 +310,11 @@ class VectorSettingsDevicesFragment :
hideOtherSessionsView()
} else {
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 nbDevices = otherDevices.size
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
val devices = if (isShowingIpAddress) otherDevices else otherDevices.map { it.copy(deviceInfo = it.deviceInfo.copy(lastSeenIp = null)) }
views.deviceListOtherSessions.render(
@ -335,9 +335,12 @@ class VectorSettingsDevicesFragment :
views.deviceListOtherSessions.isVisible = false
}
private fun renderCurrentDevice(currentDeviceInfo: DeviceFullInfo?) {
private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?) {
currentDeviceInfo?.let {
views.deviceListHeaderCurrentSession.isVisible = true
val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError)
val signoutOtherSessionsItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignoutOtherSessions)
signoutOtherSessionsItem.setTextColor(colorDestructive)
views.deviceListCurrentSession.isVisible = true
val viewState = SessionInfoViewState(
isCurrentSession = true,

View file

@ -67,6 +67,7 @@
app:layout_constraintTop_toBottomOf="@id/deviceListSecurityRecommendationsDivider"
app:sessionsListHeaderDescription=""
app:sessionsListHeaderHasLearnMoreLink="false"
app:sessionsListHeaderMenu="@menu/menu_current_session_header"
app:sessionsListHeaderTitle="@string/device_manager_current_session_title" />
<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>