| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | @TargetApi(Build.VERSION_CODES.N_MR1) |
| 118 | protected void onExecuted(Bundle args, List<ShortcutInfoCompat> shortcuts) { |
| 119 | List<ShortcutInfoCompat> add = new ArrayList<>(); |
| 120 | List<String> remove = new ArrayList<>(); |
| 121 | |
| 122 | if (BuildConfig.DEBUG && false) |
| 123 | ShortcutManagerCompat.removeAllDynamicShortcuts(context.getApplicationContext()); |
| 124 | |
| 125 | List<ShortcutInfoCompat> existing = ShortcutManagerCompat.getDynamicShortcuts(context.getApplicationContext()); |
| 126 | |
| 127 | for (ShortcutInfoCompat shortcut : shortcuts) { |
| 128 | boolean exists = false; |
| 129 | for (ShortcutInfoCompat current : existing) |
| 130 | if (Objects.equals(shortcut.getId(), current.getId())) { |
| 131 | Log.i("Found shortcut=" + current.getId()); |
| 132 | exists = true; |
| 133 | break; |
| 134 | } |
| 135 | if (!exists) |
| 136 | add.add(shortcut); |
| 137 | } |
| 138 | |
| 139 | for (ShortcutInfoCompat current : existing) { |
| 140 | boolean found = false; |
| 141 | for (ShortcutInfoCompat shortcut : shortcuts) |
| 142 | if (Objects.equals(shortcut.getId(), current.getId())) { |
| 143 | found = true; |
| 144 | break; |
| 145 | } |
| 146 | if (!found) { |
| 147 | Log.i("Not found shortcut=" + current.getId()); |
| 148 | remove.add(current.getId()); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | Log.i("Shortcuts count=" + shortcuts.size() + |
| 153 | " add=" + add.size() + |
| 154 | " remove=" + remove.size()); |
| 155 | |
| 156 | if (remove.size() > 0) |
| 157 | ShortcutManagerCompat.removeDynamicShortcuts(context.getApplicationContext(), remove); |
| 158 | |
| 159 | for (ShortcutInfoCompat shortcut : add) { |
| 160 | Log.i("Push shortcut id=" + shortcut.getId()); |
| 161 | ShortcutManagerCompat.pushDynamicShortcut(context.getApplicationContext(), shortcut); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | protected void onException(Bundle args, Throwable ex) { |