]> git.ktnx.net Git - mobile-ledger.git/commitdiff
limit the number of launcher shortcuts to the maximum supported
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 25 Jan 2020 12:46:29 +0000 (14:46 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 25 Jan 2020 12:46:29 +0000 (14:46 +0200)
instead of crashing attempting th breach the limit

app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index 876f8da8c4e60f8f411f4eeba803ba3b5fdbac03..0d800fce3e920e3b7193c43ed87da58f936bcf18 100644 (file)
@@ -325,9 +325,13 @@ public class MainActivity extends ProfileThemedActivity {
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
             return;
 
+        ShortcutManager sm = getSystemService(ShortcutManager.class);
         List<ShortcutInfo> shortcuts = new ArrayList<>();
         int i = 0;
         for (MobileLedgerProfile p : list) {
+            if (shortcuts.size() >= sm.getMaxShortcutCountPerActivity())
+                break;
+
             if (!p.isPostingPermitted())
                 continue;
 
@@ -351,7 +355,6 @@ public class MainActivity extends ProfileThemedActivity {
             shortcuts.add(si);
             i++;
         }
-        ShortcutManager sm = getSystemService(ShortcutManager.class);
         sm.setDynamicShortcuts(shortcuts);
     }
     private void onProfileListChanged(List<MobileLedgerProfile> newList) {