Updating the action title to include sessions number

This commit is contained in:
Maxime NATUREL 2022-10-24 13:59:09 +02:00
parent 810c93cef9
commit 7e836c0e97
5 changed files with 14 additions and 9 deletions

View file

@ -3347,6 +3347,10 @@
<string name="device_manager_other_sessions_select">Select sessions</string>
<string name="device_manager_other_sessions_multi_signout_all">Sign out of these sessions</string>
<string name="device_manager_other_sessions_multi_signout_selection">Sign out</string>
<plurals name="device_manager_other_sessions_multi_signout_all">
<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_session_overview_signout">Sign out of this session</string>
<string name="device_manager_session_details_title">Session details</string>
<string name="device_manager_session_details_description">Application, device, and activity information.</string>

View file

@ -19,11 +19,9 @@ package im.vector.app.features.settings.devices.v2
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.ActionMenuView.OnMenuItemClickListener
import androidx.core.view.isVisible
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.fragmentViewModel
@ -50,7 +48,6 @@ import im.vector.app.features.settings.devices.v2.list.SESSION_IS_MARKED_AS_INAC
import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationView
import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationViewState
import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsAction
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
import javax.inject.Inject
@ -137,10 +134,8 @@ class VectorSettingsDevicesFragment :
}
private fun initOtherSessionsHeaderView() {
val color = colorProvider.getColorFromAttribute(R.attr.colorError)
views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderMultiSignout).setTextColor(color)
views.deviceListHeaderOtherSessions.setOnMenuItemClickListener { menuItem ->
when(menuItem.itemId) {
when (menuItem.itemId) {
R.id.otherSessionsHeaderMultiSignout -> {
viewModel.handle(DevicesAction.MultiSignoutOtherSessions)
true
@ -290,6 +285,11 @@ class VectorSettingsDevicesFragment :
hideOtherSessionsView()
} else {
views.deviceListHeaderOtherSessions.isVisible = true
val color = 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)
views.deviceListOtherSessions.isVisible = true
views.deviceListOtherSessions.render(
devices = otherDevices.take(NUMBER_OF_OTHER_DEVICES_TO_RENDER),

View file

@ -87,7 +87,8 @@ class OtherSessionsFragment :
multiSignoutItem.title = if (viewState.isSelectModeEnabled) {
getString(R.string.device_manager_other_sessions_multi_signout_selection).uppercase()
} else {
getString(R.string.device_manager_other_sessions_multi_signout_all)
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()

View file

@ -11,7 +11,7 @@
<item
android:id="@+id/otherSessionsMultiSignout"
android:title="@string/device_manager_other_sessions_multi_signout_all"
android:title="@plurals/device_manager_other_sessions_multi_signout_all"
app:showAsAction="withText|never" />
<item

View file

@ -6,7 +6,7 @@
<item
android:id="@+id/otherSessionsHeaderMultiSignout"
android:title="@string/device_manager_other_sessions_multi_signout_all"
android:title="@plurals/device_manager_other_sessions_multi_signout_all"
app:showAsAction="withText|never" />
</menu>