Fix so switching group by options retains all groups being collapsed

Add option to group by rarity
This commit is contained in:
drdev
2014-02-09 05:30:14 +00:00
parent 319b470acd
commit 1f883c993b
2 changed files with 42 additions and 3 deletions

View File

@@ -76,7 +76,7 @@ public enum GroupDef {
return -1; return -1;
} }
}), }),
CARD_TYPE("Card Type", CARD_TYPE("Type",
new String[] { "Creatures", "Artifacts", "Enchantments", "Planeswalkers", "Instants", "Sorceries", "Lands" }, new String[] { "Creatures", "Artifacts", "Enchantments", "Planeswalkers", "Instants", "Sorceries", "Lands" },
new Function<Integer, ColumnDef>() { new Function<Integer, ColumnDef>() {
@Override @Override
@@ -116,6 +116,36 @@ public enum GroupDef {
} }
return -1; return -1;
} }
}),
CARD_RARITY("Rarity",
new String[] { "Mythic Rares", "Rares", "Uncommons", "Commons", "Basic Lands" },
new Function<Integer, ColumnDef>() {
@Override
public ColumnDef apply(final Integer groupIndex) {
return null;
}
},
new Function<InventoryItem, Integer>() {
@Override
public Integer apply(final InventoryItem item) {
if (item instanceof PaperCard) {
switch (((PaperCard) item).getRarity()) {
case MythicRare:
return 0;
case Rare:
return 1;
case Uncommon:
return 2;
case Common:
return 3;
case BasicLand:
return 4;
default:
return -1; //show Special and Unknown in "Other" group
}
}
return -1;
}
}); });
GroupDef(String name0, String[] groups0, Function<Integer, ColumnDef> fnGetPileByOverride0, Function<InventoryItem, Integer> fnGroupItem0) { GroupDef(String name0, String[] groups0, Function<Integer, ColumnDef> fnGetPileByOverride0, Function<InventoryItem, Integer> fnGroupItem0) {

View File

@@ -61,7 +61,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
private static final int MIN_COLUMN_COUNT = 1; private static final int MIN_COLUMN_COUNT = 1;
private static final int MAX_COLUMN_COUNT = 10; private static final int MAX_COLUMN_COUNT = 10;
private static final GroupDef[] CARD_GROUPBY_OPTIONS = { GroupDef.CREATURE_SPELL_LAND, GroupDef.CARD_TYPE, GroupDef.COLOR, GroupDef.COLOR_IDENTITY }; private static final GroupDef[] CARD_GROUPBY_OPTIONS = { GroupDef.CREATURE_SPELL_LAND, GroupDef.CARD_TYPE, GroupDef.COLOR, GroupDef.COLOR_IDENTITY, GroupDef.CARD_RARITY };
private static final GroupDef[] DECK_GROUPBY_OPTIONS = { GroupDef.COLOR, GroupDef.COLOR_IDENTITY }; private static final GroupDef[] DECK_GROUPBY_OPTIONS = { GroupDef.COLOR, GroupDef.COLOR_IDENTITY };
private static final ColumnDef[] CARD_PILEBY_OPTIONS = { ColumnDef.CMC, ColumnDef.COLOR, ColumnDef.NAME, ColumnDef.COST, ColumnDef.TYPE, ColumnDef.RARITY, ColumnDef.SET }; private static final ColumnDef[] CARD_PILEBY_OPTIONS = { ColumnDef.CMC, ColumnDef.COLOR, ColumnDef.NAME, ColumnDef.COST, ColumnDef.TYPE, ColumnDef.RARITY, ColumnDef.SET };
private static final ColumnDef[] DECK_PILEBY_OPTIONS = { ColumnDef.DECK_COLOR, ColumnDef.DECK_FOLDER, ColumnDef.NAME, ColumnDef.DECK_FORMAT, ColumnDef.DECK_EDITION }; private static final ColumnDef[] DECK_PILEBY_OPTIONS = { ColumnDef.DECK_COLOR, ColumnDef.DECK_FOLDER, ColumnDef.NAME, ColumnDef.DECK_FORMAT, ColumnDef.DECK_EDITION };
@@ -370,13 +370,20 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
if (groupBy == null) { if (groupBy == null) {
groups.add(new Group("")); groups.add(new Group(""));
btnExpandCollapseAll.updateIsAllCollapsed();
} }
else { else {
for (String groupName : groupBy.getGroups()) { for (String groupName : groupBy.getGroups()) {
groups.add(new Group(groupName)); groups.add(new Group(groupName));
} }
//collapse all groups by default if all previous groups were collapsed
if (btnExpandCollapseAll.isAllCollapsed) {
for (Group group : groups) {
group.isCollapsed = true;
}
}
} }
btnExpandCollapseAll.updateIsAllCollapsed();
if (!forSetup) { if (!forSetup) {
refresh(null, -1, 0); refresh(null, -1, 0);
@@ -520,6 +527,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
} }
else { else {
otherItems = new Group("Other"); otherItems = new Group("Other");
otherItems.isCollapsed = btnExpandCollapseAll.isAllCollapsed;
groups.add(otherItems); groups.add(otherItems);
} }
} }
@@ -530,6 +538,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
if (otherItems == null && groups.size() > groupBy.getGroups().length) { if (otherItems == null && groups.size() > groupBy.getGroups().length) {
groups.remove(groups.size() - 1); //remove Other group if empty groups.remove(groups.size() - 1); //remove Other group if empty
btnExpandCollapseAll.updateIsAllCollapsed();
} }
updateLayout(true); updateLayout(true);