Fix indent

This commit is contained in:
Sylvia van Os
2021-08-08 23:04:55 +02:00
parent 0bac2dfb62
commit c1b02f58ff

View File

@@ -31,89 +31,89 @@ class ShortcutHelper
*/
static void updateShortcuts(Context context, LoyaltyCard card, Intent intent)
{
LinkedList<ShortcutInfoCompat> list = new LinkedList<>(ShortcutManagerCompat.getDynamicShortcuts(context));
LinkedList<ShortcutInfoCompat> 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<ShortcutInfoCompat> 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<ShortcutInfoCompat> 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<ShortcutInfoCompat> 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);
}
}