Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions app/src/main/java/dnd/jon/spellbook/SortFilterFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
setup();
needSetup = false;
}
viewModel.currentCreatedSources().observe(getViewLifecycleOwner(), (sources) -> this.refreshSourceFilters());
viewModel.currentCreatedSources().observe(getViewLifecycleOwner(), (sources) -> {
if (viewModel.getSourceFilterRefreshNeeded()) {
this.refreshSourceFilters();
viewModel.setSourceFilterRefreshNeeded(false);
}
});
}

private String stringFromID(int stringID) { return getResources().getString(stringID); }
Expand Down Expand Up @@ -489,36 +494,47 @@ private <Q extends NameDisplayable> List<ItemFilterViewBinding> populateFilters(

// On a long press, turn off all other buttons in this grid, and turn this one on
final Consumer<ToggleButton> longPressConsumer = (v) -> {
if (!v.isSet()) { v.callOnClick(); }
if (!v.isSet()) {
v.callOnClick();
}
//final E item = (E) v.getTag();
final Class<? extends NameDisplayable> t = q.getClass();
final Map<NameDisplayable,ToggleButton> gridButtons = filterButtonMaps.get(t);
if (gridButtons == null) { return; }
SpellbookUtils.clickButtons(gridButtons.values(), (tb) -> (tb != v && tb.isSet()) );
final Map<NameDisplayable, ToggleButton> gridButtons = filterButtonMaps.get(t);
if (gridButtons == null) {
return;
}
SpellbookUtils.clickButtons(gridButtons.values(), (tb) -> (tb != v && tb.isSet()));
};
button.setOnLongClickListener((v) -> { longPressConsumer.accept((ToggleButton) v); return true; });
button.setOnLongClickListener((v) -> {
longPressConsumer.accept((ToggleButton) v);
return true;
});

// Set up the select all button
selectAllButton.setTag(type);
selectAllButton.setOnClickListener((v) -> {
final Class<? extends NameDisplayable> t = (Class<? extends NameDisplayable>) selectAllButton.getTag();
final Map<NameDisplayable,ToggleButton> gridButtons = filterButtonMaps.get(t);
if (gridButtons == null) { return; }
final Map<NameDisplayable, ToggleButton> gridButtons = filterButtonMaps.get(t);
if (gridButtons == null) {
return;
}
SpellbookUtils.clickButtons(gridButtons.values(), (tb) -> !tb.isSet());
});

// Set up the unselect all button
unselectAllButton.setTag(type);
unselectAllButton.setOnClickListener((v) -> {
final Class<? extends NameDisplayable> t = (Class<? extends NameDisplayable>) unselectAllButton.getTag();
final Map<NameDisplayable,ToggleButton> gridButtons = filterButtonMaps.get(t);
if (gridButtons == null) { return; }
final Map<NameDisplayable, ToggleButton> gridButtons = filterButtonMaps.get(t);
if (gridButtons == null) {
return;
}
SpellbookUtils.clickButtons(gridButtons.values(), ToggleButton::isSet);
});

// If this is a spanning type, we want to also set up the range view, set the button to toggle the corresponding range view's visibility,
// as well as do some other stuff
final boolean spanning = ( rangeNeeded && (q instanceof QuantityType) && ( ((QuantityType) q).isSpanningType()) );
final boolean spanning = (rangeNeeded && (q instanceof QuantityType) && (((QuantityType) q).isSpanningType()));
if (spanning) {

// Get the range view
Expand Down Expand Up @@ -549,18 +565,19 @@ private <Q extends NameDisplayable> List<ItemFilterViewBinding> populateFilters(
notFeaturedRows.add(view);
view.setVisibility(View.GONE);
}
}

if (haveFeatured && showMoreButton != null) {
showMoreButton.setTag(false);
showMoreButton.setOnClickListener((v) -> {
final boolean visible = (boolean) showMoreButton.getTag();
for (View nfr : notFeaturedRows) {
nfr.setVisibility(visible ? View.GONE : View.VISIBLE);
}
showMoreButton.setTag(!visible);
showMoreButton.setText(visible ? R.string.show_more : R.string.show_less);
});
}
if (haveFeatured && showMoreButton != null) {
showMoreButton.setTag(false);
showMoreButton.setText(R.string.show_more);
showMoreButton.setOnClickListener((v) -> {
final boolean visible = (boolean) showMoreButton.getTag();
for (View nfr : notFeaturedRows) {
nfr.setVisibility(visible ? View.GONE : View.VISIBLE);
}
showMoreButton.setTag(!visible);
showMoreButton.setText(visible ? R.string.show_more : R.string.show_less);
});
}
return bindings;
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/dnd/jon/spellbook/SpellbookViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class SpellbookViewModel extends ViewModel implements Filterable {
private CharSequence searchQuery;
private boolean filterNeeded = false;
private boolean sortNeeded = false;
private boolean sourceFilterRefreshNeeded = false;
private boolean spellTableVisible = true;
private boolean suspendSpellListModifications = false;
private final MutableLiveData<CharacterProfile> currentProfileLD;
Expand Down Expand Up @@ -753,6 +754,7 @@ boolean deleteSourceByNameOrCode(String identifier) {
if (success) {
removeSourceFromCreatedSpells(source);
source.delete();
this.setSourceFilterRefreshNeeded(true);
}
return success;
}
Expand Down Expand Up @@ -840,6 +842,7 @@ private boolean saveSource(Source source, File filepath) {
boolean addCreatedSource(Source source) {
final String filename = DisplayUtils.getCode(source, getContext()) + CREATED_SOURCE_EXTENSION;
final File filepath = new File(createdSourcesDir, filename);
this.setSourceFilterRefreshNeeded(true);
return saveSource(source, filepath);
}

Expand Down Expand Up @@ -1012,6 +1015,14 @@ void setSortNeeded() {
modifySpellsIfAppropriate();
}

boolean getSourceFilterRefreshNeeded() {
return this.sourceFilterRefreshNeeded;
}

void setSourceFilterRefreshNeeded(boolean needed) {
this.sourceFilterRefreshNeeded = needed;
}

void setSpellTableVisible(boolean visible) {
this.spellTableVisible = visible;
this.spellTableVisibleLD.setValue(visible);
Expand Down
Loading