Adding new menu entry for multi signout

This commit is contained in:
Maxime NATUREL 2022-10-20 10:13:34 +02:00
parent 97cfc7dde4
commit f45cc715d1
3 changed files with 27 additions and 0 deletions

View file

@ -3345,6 +3345,8 @@
<string name="device_manager_other_sessions_no_inactive_sessions_found">No inactive sessions found.</string>
<string name="device_manager_other_sessions_clear_filter">Clear Filter</string>
<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>
<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

@ -25,6 +25,7 @@ import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.activity.addCallback
import androidx.annotation.StringRes
import androidx.core.text.toSpannable
import androidx.core.view.isVisible
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.args
@ -32,12 +33,14 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.orEmpty
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment.ResultListener.Companion.RESULT_OK
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.colorizeMatchingText
import im.vector.app.databinding.FragmentOtherSessionsBinding
import im.vector.app.features.settings.devices.v2.DeviceFullInfo
import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterBottomSheet
@ -77,9 +80,26 @@ class OtherSessionsFragment :
menu.findItem(R.id.otherSessionsSelectAll).isVisible = isSelectModeEnabled
menu.findItem(R.id.otherSessionsDeselectAll).isVisible = isSelectModeEnabled
menu.findItem(R.id.otherSessionsSelect).isVisible = !isSelectModeEnabled && state.devices()?.isNotEmpty().orFalse()
val multiSignoutItem = menu.findItem(R.id.otherSessionsMultiSignout)
multiSignoutItem.title = if (isSelectModeEnabled) {
getString(R.string.device_manager_other_sessions_multi_signout_selection).uppercase()
} else {
getString(R.string.device_manager_other_sessions_multi_signout_all)
}
val showAsActionFlag = if (isSelectModeEnabled) MenuItem.SHOW_AS_ACTION_ALWAYS else MenuItem.SHOW_AS_ACTION_NEVER
multiSignoutItem.setShowAsAction(showAsActionFlag or MenuItem.SHOW_AS_ACTION_WITH_TEXT)
changeTextColorOfDestructiveAction(multiSignoutItem)
}
}
private fun changeTextColorOfDestructiveAction(menuItem: MenuItem) {
val titleColor = colorProvider.getColorFromAttribute(R.attr.colorError)
val currentTitle = menuItem.title.orEmpty().toString()
menuItem.title = currentTitle
.toSpannable()
.colorizeMatchingText(currentTitle, titleColor)
}
override fun handleMenuItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.otherSessionsSelect -> {

View file

@ -9,6 +9,11 @@
android:title="@string/device_manager_other_sessions_select"
app:showAsAction="withText|never" />
<item
android:id="@+id/otherSessionsMultiSignout"
android:title="@string/device_manager_other_sessions_multi_signout_all"
app:showAsAction="withText|never" />
<item
android:id="@+id/otherSessionsSelectAll"
android:title="@string/action_select_all"