diff --git a/app/src/main/java/com/limelight/PcView.java b/app/src/main/java/com/limelight/PcView.java index 63167d9f..5a72bf78 100644 --- a/app/src/main/java/com/limelight/PcView.java +++ b/app/src/main/java/com/limelight/PcView.java @@ -357,6 +357,9 @@ public class PcView extends Activity implements AdapterFragmentCallbacks { // Invalidate reachability information after pairing to force // a refresh before reading pair state again managerBinder.invalidateStateForComputer(computer.uuid); + + // Add a launcher shortcut for this PC + shortcutHelper.createAppViewShortcut(computer.uuid.toString(), computer); } else { // Should be no other values @@ -505,8 +508,6 @@ public class PcView extends Activity implements AdapterFragmentCallbacks { return; } - shortcutHelper.createAppViewShortcut(computer.uuid.toString(), computer); - Intent i = new Intent(this, AppView.class); i.putExtra(AppView.NAME_EXTRA, computer.name); i.putExtra(AppView.UUID_EXTRA, computer.uuid.toString()); @@ -609,6 +610,11 @@ public class PcView extends Activity implements AdapterFragmentCallbacks { } } + // Add a launcher shortcut for this PC + if (details.pairState == PairState.PAIRED) { + shortcutHelper.createAppViewShortcut(details.uuid.toString(), details); + } + if (existingEntry != null) { // Replace the information in the existing entry existingEntry.details = details; diff --git a/app/src/main/java/com/limelight/utils/ShortcutHelper.java b/app/src/main/java/com/limelight/utils/ShortcutHelper.java index 538a6cb9..215b088f 100644 --- a/app/src/main/java/com/limelight/utils/ShortcutHelper.java +++ b/app/src/main/java/com/limelight/utils/ShortcutHelper.java @@ -67,6 +67,17 @@ public class ShortcutHelper { return null; } + @TargetApi(Build.VERSION_CODES.N_MR1) + private boolean isExistingDynamicShortcut(String id) { + for (ShortcutInfo si : sm.getDynamicShortcuts()) { + if (si.getId().equals(id)) { + return true; + } + } + + return false; + } + public void reportShortcutUsed(String id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutInfo sinfo = getInfoForId(id); @@ -96,11 +107,12 @@ public class ShortcutHelper { sm.updateShortcuts(Collections.singletonList(sinfo)); sm.enableShortcuts(Collections.singletonList(id)); } - else { - // Reap shortcuts to make space for this new one - reapShortcutsForDynamicAdd(); - // Add the new shortcut + // Reap shortcuts to make space for this if it's new + // NOTE: This CAN'T be an else on the above if, because it's + // possible that we have an existing shortcut but it's not a dynamic one. + if (!isExistingDynamicShortcut(id)) { + reapShortcutsForDynamicAdd(); sm.addDynamicShortcuts(Collections.singletonList(sinfo)); } }