Merge pull request #4427 from vector-im/feature/bma/shortcut_disabled

Add an explicit reason when shortcut are disabled.
This commit is contained in:
Benoit Marty 2021-11-09 20:38:21 +01:00 committed by GitHub
commit dc486557cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View file

@ -21,8 +21,10 @@ import android.content.pm.ShortcutManager
import android.os.Build
import androidx.core.content.getSystemService
import androidx.core.content.pm.ShortcutManagerCompat
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.dispatchers.CoroutineDispatchers
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.pin.PinCodeStore
import im.vector.app.features.pin.PinCodeStoreListener
import kotlinx.coroutines.CoroutineScope
@ -43,6 +45,7 @@ import javax.inject.Inject
class ShortcutsHandler @Inject constructor(
private val context: Context,
private val stringProvider: StringProvider,
private val appDispatchers: CoroutineDispatchers,
private val shortcutCreator: ShortcutCreator,
private val activeSessionHolder: ActiveSessionHolder,
@ -72,7 +75,7 @@ class ShortcutsHandler @Inject constructor(
.onCompletion { pinCodeStore.removeListener(this@ShortcutsHandler) }
.onEach { rooms ->
// Remove dead shortcuts (i.e. deleted rooms)
removeDeadShortcut(rooms.map { it.roomId })
removeDeadShortcuts(rooms.map { it.roomId })
// Create shortcuts
createShortcuts(rooms)
@ -81,7 +84,7 @@ class ShortcutsHandler @Inject constructor(
.launchIn(coroutineScope)
}
private fun removeDeadShortcut(roomIds: List<String>) {
private fun removeDeadShortcuts(roomIds: List<String>) {
val deadShortcutIds = ShortcutManagerCompat.getShortcuts(context, ShortcutManagerCompat.FLAG_MATCH_DYNAMIC)
.map { it.id }
.filter { !roomIds.contains(it) }
@ -91,7 +94,11 @@ class ShortcutsHandler @Inject constructor(
ShortcutManagerCompat.removeLongLivedShortcuts(context, deadShortcutIds)
if (isRequestPinShortcutSupported) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
context.getSystemService<ShortcutManager>()?.disableShortcuts(deadShortcutIds)
ShortcutManagerCompat.disableShortcuts(
context,
deadShortcutIds,
stringProvider.getString(R.string.shortcut_disabled_reason_room_left)
)
}
}
}
@ -130,8 +137,15 @@ class ShortcutsHandler @Inject constructor(
if (isRequestPinShortcutSupported) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
context.getSystemService<ShortcutManager>()
?.let {
it.disableShortcuts(it.pinnedShortcuts.map { pinnedShortcut -> pinnedShortcut.id })
?.pinnedShortcuts
?.takeIf { it.isNotEmpty() }
?.map { pinnedShortcut -> pinnedShortcut.id }
?.let { shortcutIdsToDisable ->
ShortcutManagerCompat.disableShortcuts(
context,
shortcutIdsToDisable,
stringProvider.getString(R.string.shortcut_disabled_reason_sign_out)
)
}
}
}

View file

@ -1080,6 +1080,9 @@
<string name="room_settings_forget">Forget</string>
<string name="room_settings_add_homescreen_shortcut">Add to Home screen</string>
<string name="shortcut_disabled_reason_room_left">The room has been left!</string>
<string name="shortcut_disabled_reason_sign_out">The session has been signed out!</string>
<!-- home sliding menu -->
<string name="room_sliding_menu_messages">Messages</string>
<string name="room_sliding_menu_settings">Settings</string>