From c1b02f58ff96beb24cf8fcb20dd242e52e7b5165 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Sun, 8 Aug 2021 23:04:55 +0200 Subject: [PATCH] Fix indent --- .../protect/card_locker/ShortcutHelper.java | 156 +++++++++--------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/app/src/main/java/protect/card_locker/ShortcutHelper.java b/app/src/main/java/protect/card_locker/ShortcutHelper.java index 5c8d61987..98f400d91 100644 --- a/app/src/main/java/protect/card_locker/ShortcutHelper.java +++ b/app/src/main/java/protect/card_locker/ShortcutHelper.java @@ -31,89 +31,89 @@ class ShortcutHelper */ static void updateShortcuts(Context context, LoyaltyCard card, Intent intent) { - LinkedList list = new LinkedList<>(ShortcutManagerCompat.getDynamicShortcuts(context)); + LinkedList list = new LinkedList<>(ShortcutManagerCompat.getDynamicShortcuts(context)); - DBHelper dbHelper = new DBHelper(context); + DBHelper dbHelper = new DBHelper(context); - String shortcutId = Integer.toString(card.id); + String shortcutId = Integer.toString(card.id); - // Sort the shortcuts by rank, so working with the relative order will be easier. - // This sorts so that the lowest rank is first. - Collections.sort(list, Comparator.comparingInt(ShortcutInfoCompat::getRank)); + // Sort the shortcuts by rank, so working with the relative order will be easier. + // This sorts so that the lowest rank is first. + Collections.sort(list, Comparator.comparingInt(ShortcutInfoCompat::getRank)); - Integer foundIndex = null; + Integer foundIndex = null; - for(int index = 0; index < list.size(); index++) + for(int index = 0; index < list.size(); index++) + { + if(list.get(index).getId().equals(shortcutId)) { - if(list.get(index).getId().equals(shortcutId)) - { - // Found the item already - foundIndex = index; - break; - } + // Found the item already + foundIndex = index; + break; + } + } + + if(foundIndex != null) + { + // If the item is already found, then the list needs to be + // reordered, so that the selected item now has the lowest + // rank, thus letting it survive longer. + ShortcutInfoCompat found = list.remove(foundIndex.intValue()); + list.addFirst(found); + } + else + { + // The item is new to the list. First, we need to trim the list + // until it is able to accept a new item, then the item is + // inserted. + while(list.size() >= MAX_SHORTCUTS) + { + list.pollLast(); } - if(foundIndex != null) - { - // If the item is already found, then the list needs to be - // reordered, so that the selected item now has the lowest - // rank, thus letting it survive longer. - ShortcutInfoCompat found = list.remove(foundIndex.intValue()); - list.addFirst(found); - } - else - { - // The item is new to the list. First, we need to trim the list - // until it is able to accept a new item, then the item is - // inserted. - while(list.size() >= MAX_SHORTCUTS) - { - list.pollLast(); - } + ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(context, Integer.toString(card.id)) + .setShortLabel(card.store) + .setLongLabel(card.store) + .setIntent(intent) + .build(); - ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(context, Integer.toString(card.id)) - .setShortLabel(card.store) - .setLongLabel(card.store) - .setIntent(intent) - .build(); + list.addFirst(shortcut); + } - list.addFirst(shortcut); + LinkedList finalList = new LinkedList<>(); + + // The ranks are now updated; the order in the list is the rank. + for(int index = 0; index < list.size(); index++) + { + ShortcutInfoCompat prevShortcut = list.get(index); + + Intent shortcutIntent = prevShortcut.getIntent(); + + Bitmap iconBitmap = Utils.generateIcon(context, dbHelper.getLoyaltyCard(Integer.parseInt(prevShortcut.getId())), true).getLetterTile(); + + IconCompat icon = IconCompat.createWithAdaptiveBitmap(iconBitmap); + + // Prevent instances of the view activity from piling up; if one exists let this + // one replace it. + shortcutIntent.setFlags(shortcutIntent.getFlags() | Intent.FLAG_ACTIVITY_SINGLE_TOP); + + final CharSequence longLabel = prevShortcut.getLongLabel(); + + ShortcutInfoCompat updatedShortcut = null; + if (longLabel != null) { + updatedShortcut = new ShortcutInfoCompat.Builder(context, prevShortcut.getId()) + .setShortLabel(prevShortcut.getShortLabel()) + .setLongLabel(longLabel) + .setIntent(shortcutIntent) + .setIcon(icon) + .setRank(index) + .build(); } - LinkedList finalList = new LinkedList<>(); + finalList.addLast(updatedShortcut); + } - // The ranks are now updated; the order in the list is the rank. - for(int index = 0; index < list.size(); index++) - { - ShortcutInfoCompat prevShortcut = list.get(index); - - Intent shortcutIntent = prevShortcut.getIntent(); - - Bitmap iconBitmap = Utils.generateIcon(context, dbHelper.getLoyaltyCard(Integer.parseInt(prevShortcut.getId())), true).getLetterTile(); - - IconCompat icon = IconCompat.createWithAdaptiveBitmap(iconBitmap); - - // Prevent instances of the view activity from piling up; if one exists let this - // one replace it. - shortcutIntent.setFlags(shortcutIntent.getFlags() | Intent.FLAG_ACTIVITY_SINGLE_TOP); - - final CharSequence longLabel = prevShortcut.getLongLabel(); - - ShortcutInfoCompat updatedShortcut = null; - if (longLabel != null) { - updatedShortcut = new ShortcutInfoCompat.Builder(context, prevShortcut.getId()) - .setShortLabel(prevShortcut.getShortLabel()) - .setLongLabel(longLabel) - .setIntent(shortcutIntent) - .setIcon(icon) - .setRank(index) - .build(); - } - - finalList.addLast(updatedShortcut); - } - - ShortcutManagerCompat.setDynamicShortcuts(context, finalList); + ShortcutManagerCompat.setDynamicShortcuts(context, finalList); } /** @@ -124,17 +124,17 @@ class ShortcutHelper { List list = ShortcutManagerCompat.getDynamicShortcuts(context); - String shortcutId = Integer.toString(cardId); + String shortcutId = Integer.toString(cardId); - for(int index = 0; index < list.size(); index++) + for(int index = 0; index < list.size(); index++) + { + if(list.get(index).getId().equals(shortcutId)) { - if(list.get(index).getId().equals(shortcutId)) - { - list.remove(index); - break; - } + list.remove(index); + break; } + } - ShortcutManagerCompat.setDynamicShortcuts(context, list); + ShortcutManagerCompat.setDynamicShortcuts(context, list); } }