Adding the rename and signout actions in the menu

This commit is contained in:
Maxime NATUREL 2022-12-05 10:26:07 +01:00
parent b8ab1b5620
commit bbc756136c
2 changed files with 44 additions and 20 deletions

View file

@ -101,6 +101,7 @@ class VectorSettingsDevicesFragment :
initWaitingView() initWaitingView()
initCurrentSessionHeaderView() initCurrentSessionHeaderView()
initCurrentSessionListView()
initOtherSessionsHeaderView() initOtherSessionsHeaderView()
initOtherSessionsView() initOtherSessionsView()
initSecurityRecommendationsView() initSecurityRecommendationsView()
@ -153,6 +154,12 @@ class VectorSettingsDevicesFragment :
} }
} }
private fun initCurrentSessionListView() {
views.deviceListCurrentSession.viewVerifyButton.debouncedClicks {
viewModel.handle(DevicesAction.VerifyCurrentSession)
}
}
private fun initOtherSessionsHeaderView() { private fun initOtherSessionsHeaderView() {
views.deviceListHeaderOtherSessions.setOnMenuItemClickListener { menuItem -> views.deviceListHeaderOtherSessions.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
@ -351,31 +358,38 @@ class VectorSettingsDevicesFragment :
private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?, hasOtherDevices: Boolean) { private fun renderCurrentSessionView(currentDeviceInfo: DeviceFullInfo?, hasOtherDevices: Boolean) {
currentDeviceInfo?.let { currentDeviceInfo?.let {
views.deviceListHeaderCurrentSession.isVisible = true renderCurrentSessionHeaderView(hasOtherDevices)
val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError) renderCurrentSessionListView(it)
val signoutOtherSessionsItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignoutOtherSessions)
signoutOtherSessionsItem.setTextColor(colorDestructive)
signoutOtherSessionsItem.isVisible = hasOtherDevices
views.deviceListCurrentSession.isVisible = true
val viewState = SessionInfoViewState(
isCurrentSession = true,
deviceFullInfo = it
)
views.deviceListCurrentSession.render(viewState, dateFormatter, drawableProvider, colorProvider, stringProvider)
views.deviceListCurrentSession.debouncedClicks {
currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) }
}
views.deviceListCurrentSession.viewDetailsButton.debouncedClicks {
currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) }
}
views.deviceListCurrentSession.viewVerifyButton.debouncedClicks {
viewModel.handle(DevicesAction.VerifyCurrentSession)
}
} ?: run { } ?: run {
hideCurrentSessionView() hideCurrentSessionView()
} }
} }
private fun renderCurrentSessionHeaderView(hasOtherDevices: Boolean) {
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
}
private fun renderCurrentSessionListView(currentDeviceInfo: DeviceFullInfo) {
views.deviceListCurrentSession.isVisible = true
val viewState = SessionInfoViewState(
isCurrentSession = true,
deviceFullInfo = currentDeviceInfo
)
views.deviceListCurrentSession.render(viewState, dateFormatter, drawableProvider, colorProvider, stringProvider)
views.deviceListCurrentSession.debouncedClicks {
currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) }
}
views.deviceListCurrentSession.viewDetailsButton.debouncedClicks {
currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) }
}
}
private fun navigateToSessionOverview(deviceId: String) { private fun navigateToSessionOverview(deviceId: String) {
viewNavigator.navigateToSessionOverview( viewNavigator.navigateToSessionOverview(
context = requireActivity(), context = requireActivity(),

View file

@ -4,6 +4,16 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction"> tools:ignore="AlwaysShowAction">
<item
android:id="@+id/currentSessionHeaderRename"
android:title="@string/device_manager_session_rename"
app:showAsAction="withText|never" />
<item
android:id="@+id/currentSessionHeaderSignout"
android:title="@string/logout"
app:showAsAction="withText|never" />
<item <item
android:id="@+id/currentSessionHeaderSignoutOtherSessions" android:id="@+id/currentSessionHeaderSignoutOtherSessions"
android:title="@string/device_manager_signout_all_other_sessions" android:title="@string/device_manager_signout_all_other_sessions"