Skip to content

Commit

Permalink
Run shortcuts update in bg thread (fixes #959)
Browse files Browse the repository at this point in the history
  • Loading branch information
nevenz committed Sep 1, 2022
1 parent ac9e6c4 commit a88e502
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/src/main/java/com/orgzly/android/SharingShortcutsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ class SharingShortcutsManager {
}

fun replaceDynamicShortcuts(context: Context) {
val shortcuts = createShortcuts(context)
.take(ShortcutManagerCompat.getMaxShortcutCountPerActivity(context))
App.EXECUTORS.diskIO().execute {
val t1 = System.currentTimeMillis()

ShortcutManagerCompat.removeAllDynamicShortcuts(context)
ShortcutManagerCompat.addDynamicShortcuts(context, shortcuts)
val shortcuts = createShortcuts(context)
.take(ShortcutManagerCompat.getMaxShortcutCountPerActivity(context))

if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "Published ${shortcuts.size} shortcuts")
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
ShortcutManagerCompat.addDynamicShortcuts(context, shortcuts)

if (BuildConfig.LOG_DEBUG) {
val t2 = System.currentTimeMillis()
LogUtils.d(TAG, "Published ${shortcuts.size} shortcuts in ${t2 - t1}ms")
}
}
}

private fun createShortcuts(context: Context): List<ShortcutInfoCompat> {
Expand Down

0 comments on commit a88e502

Please sign in to comment.