Clear dynamic shortcuts when user log out
This commit is contained in:
parent
ba8ec97f6a
commit
c0623726ae
|
@ -32,6 +32,7 @@ import im.vector.riotx.core.extensions.startSyncing
|
||||||
import im.vector.riotx.core.platform.VectorBaseActivity
|
import im.vector.riotx.core.platform.VectorBaseActivity
|
||||||
import im.vector.riotx.core.utils.deleteAllFiles
|
import im.vector.riotx.core.utils.deleteAllFiles
|
||||||
import im.vector.riotx.features.home.HomeActivity
|
import im.vector.riotx.features.home.HomeActivity
|
||||||
|
import im.vector.riotx.features.home.ShortcutsHandler
|
||||||
import im.vector.riotx.features.login.LoginActivity
|
import im.vector.riotx.features.login.LoginActivity
|
||||||
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
||||||
import im.vector.riotx.features.settings.VectorPreferences
|
import im.vector.riotx.features.settings.VectorPreferences
|
||||||
|
@ -82,6 +83,7 @@ class MainActivity : VectorBaseActivity() {
|
||||||
@Inject lateinit var errorFormatter: ErrorFormatter
|
@Inject lateinit var errorFormatter: ErrorFormatter
|
||||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||||
@Inject lateinit var uiStateRepository: UiStateRepository
|
@Inject lateinit var uiStateRepository: UiStateRepository
|
||||||
|
@Inject lateinit var shortcutsHandler: ShortcutsHandler
|
||||||
|
|
||||||
override fun injectWith(injector: ScreenComponent) {
|
override fun injectWith(injector: ScreenComponent) {
|
||||||
injector.inject(this)
|
injector.inject(this)
|
||||||
|
@ -105,6 +107,9 @@ class MainActivity : VectorBaseActivity() {
|
||||||
// Dismiss all notifications
|
// Dismiss all notifications
|
||||||
notificationDrawerManager.clearAllEvents()
|
notificationDrawerManager.clearAllEvents()
|
||||||
notificationDrawerManager.persistInfo()
|
notificationDrawerManager.persistInfo()
|
||||||
|
|
||||||
|
// Also clear the dynamic shortcuts
|
||||||
|
shortcutsHandler.clearShortcuts()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseArgs(): MainActivityArgs {
|
private fun parseArgs(): MainActivityArgs {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.riotx.features.home
|
package im.vector.riotx.features.home
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.ShortcutManager
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.content.pm.ShortcutInfoCompat
|
import androidx.core.content.pm.ShortcutInfoCompat
|
||||||
|
@ -26,6 +27,7 @@ import im.vector.matrix.android.api.util.toMatrixItem
|
||||||
import im.vector.riotx.core.glide.GlideApp
|
import im.vector.riotx.core.glide.GlideApp
|
||||||
import im.vector.riotx.core.utils.DimensionConverter
|
import im.vector.riotx.core.utils.DimensionConverter
|
||||||
import im.vector.riotx.features.home.room.detail.RoomDetailActivity
|
import im.vector.riotx.features.home.room.detail.RoomDetailActivity
|
||||||
|
import io.reactivex.Observable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -51,6 +53,11 @@ class ShortcutsHandler @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun observeRoomsAndBuildShortcuts(): Disposable {
|
fun observeRoomsAndBuildShortcuts(): Disposable {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||||
|
// No op
|
||||||
|
return Observable.empty<Unit>().subscribe()
|
||||||
|
}
|
||||||
|
|
||||||
return homeRoomListStore
|
return homeRoomListStore
|
||||||
.observe()
|
.observe()
|
||||||
.distinct()
|
.distinct()
|
||||||
|
@ -78,6 +85,25 @@ class ShortcutsHandler @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clearShortcuts() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||||
|
// No op
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
|
||||||
|
|
||||||
|
// We can only disabled pinned shortcuts with the API, but at least it will prevent the crash
|
||||||
|
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||||
|
context.getSystemService(ShortcutManager::class.java)
|
||||||
|
?.let {
|
||||||
|
it.disableShortcuts(it.pinnedShortcuts.map { pinnedShortcut -> pinnedShortcut.id })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PRIVATE API *********************************************************************************
|
// PRIVATE API *********************************************************************************
|
||||||
|
|
||||||
private fun Bitmap.toProfileImageIcon(): IconCompat {
|
private fun Bitmap.toProfileImageIcon(): IconCompat {
|
||||||
|
|
Loading…
Reference in New Issue