Avoid toggling multi-select mode if long press on card art

Avoid toggling checkbox if user taps on card art
This commit is contained in:
drdev
2016-04-08 15:59:26 +00:00
parent e20ddea9c9
commit d23e016850
3 changed files with 31 additions and 23 deletions

View File

@@ -79,6 +79,9 @@ public class CardManager extends ItemManager<PaperCard> {
@Override @Override
public boolean longPress(Integer index, Entry<PaperCard, Integer> value, float x, float y) { public boolean longPress(Integer index, Entry<PaperCard, Integer> value, float x, float y) {
if (CardRenderer.cardListItemTap(model.getOrderedList(), index, CardManager.this, x, y, 1, compactModeHandler.isCompactMode())) {
return true; //avoid calling onCardLongPress if user long presses on card art
}
onCardLongPress(index, value, x, y); onCardLongPress(index, value, x, y);
return true; return true;
} }

View File

@@ -100,6 +100,9 @@ public class SpellShopManager extends ItemManager<InventoryItem> {
@Override @Override
public boolean longPress(Integer index, Entry<InventoryItem, Integer> value, float x, float y) { public boolean longPress(Integer index, Entry<InventoryItem, Integer> value, float x, float y) {
if (value.getKey() instanceof PaperCard && CardRenderer.cardListItemTap(model.getOrderedList(), index, SpellShopManager.this, x, y, 1, compactModeHandler.isCompactMode())) {
return true; //avoid calling toggleMultiSelectMode if user long presses on card art
}
toggleMultiSelectMode(index); toggleMultiSelectMode(index);
return true; return true;
} }

View File

@@ -200,36 +200,38 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
@Override @Override
public boolean tap(Integer index, Entry<T, Integer> value, float x, float y, int count) { public boolean tap(Integer index, Entry<T, Integer> value, float x, float y, int count) {
if (maxSelections > 1) { if (maxSelections > 1) { //if multi-select
if (selectedIndices.contains(index)) { //don't toggle checkbox if renderer handles tap
//allow removing selection if it won't fall below min if (!renderer.tap(index, value, x, y, count)) {
//or if max selected (since you need to be able to deselect an item before selecting a new item) if (selectedIndices.contains(index)) {
if (selectedIndices.size() > minSelections || selectedIndices.size() == maxSelections) { //allow removing selection if it won't fall below min
selectedIndices.remove(index); //or if max selected (since you need to be able to deselect an item before selecting a new item)
if (selectedIndices.size() > minSelections || selectedIndices.size() == maxSelections) {
selectedIndices.remove(index);
onSelectionChange();
}
}
else if (selectedIndices.size() < maxSelections) {
selectedIndices.add(index);
Collections.sort(selectedIndices); //ensure selected indices are sorted
onSelectionChange(); onSelectionChange();
} }
} }
else if (selectedIndices.size() < maxSelections) {
selectedIndices.add(index);
Collections.sort(selectedIndices); //ensure selected indices are sorted
onSelectionChange();
}
} }
else { else { //if single-select
setSelectedIndex(index); setSelectedIndex(index);
}
if (renderer.tap(index, value, x, y, count)) { //don't activate if renderer handles tap
prevTapIndex = index; if (!renderer.tap(index, value, x, y, count)) {
return true; //don't activate if renderer handles tap if (count == 1) {
} itemManager.showMenu(false);
if (maxSelections <= 1) { }
if (count == 1) { else if (count == 2 && index == prevTapIndex) {
itemManager.showMenu(false); itemManager.activateSelectedItems();
} }
else if (count == 2 && index == prevTapIndex) {
itemManager.activateSelectedItems();
} }
} }
prevTapIndex = index; prevTapIndex = index;
return true; return true;
} }