diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-03-20 17:20:47 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-03-20 17:32:53 +0530 |
commit | df17d6140b40fe6a16426f6995a989b9f0dcb6b8 (patch) | |
tree | 952e598d699b2e7adb024e69e33a656efcbce033 /app/src/main/java | |
parent | 940cdd9750fb9d26dfc370d01dd0255372e90d2e (diff) |
Fix launcher shortcut icon rendering
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt index 96fce533..8717d199 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt @@ -8,6 +8,7 @@ import android.Manifest import android.annotation.SuppressLint import android.content.Context import android.content.Intent +import android.content.pm.ShortcutInfo import android.content.pm.ShortcutInfo.Builder import android.content.pm.ShortcutManager import android.graphics.drawable.Icon @@ -466,7 +467,23 @@ class PasswordStore : BaseGitActivity() { // is at the front like it's supposed to. shortcuts.reverse() // Write back the new shortcuts. - shortcutManager.dynamicShortcuts = shortcuts + shortcutManager.dynamicShortcuts = shortcuts.map(::rebuildShortcut) + } + + /** + * Takes an existing [ShortcutInfo] and builds a fresh instance of [ShortcutInfo] with the same + * data, which ensures that the get/set dance in [addShortcut] does not cause invalidation of icon + * assets, resulting in invisible icons in all but the newest launcher shortcut. + */ + @RequiresApi(Build.VERSION_CODES.N_MR1) + private fun rebuildShortcut(shortcut: ShortcutInfo): ShortcutInfo { + // Non-null assertions are fine since we know these values aren't null. + return Builder(this@PasswordStore, shortcut.id) + .setShortLabel(shortcut.shortLabel!!) + .setLongLabel(shortcut.longLabel!!) + .setIcon(Icon.createWithResource(this@PasswordStore, R.drawable.ic_lock_open_24px)) + .setIntent(shortcut.intent!!) + .build() } private fun validateState(): Boolean { |