Skip to content

Commit

Permalink
Merge pull request #100 from Carifio24/hide-duplicates-with-options
Browse files Browse the repository at this point in the history
Make hide duplicates respect search text options
  • Loading branch information
Carifio24 authored Oct 1, 2024
2 parents 192d86a + a73b37f commit 9f3d23e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/dnd/jon/spellbook/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,8 @@ private void openSpellWindow(Spell spell) {
if (onTablet || spell == null) { return; }
final Bundle args = new Bundle();
args.putParcelable(SpellWindowFragment.SPELL_KEY, spell);
args.putBoolean(SpellWindowFragment.USE_EXPANDED_KEY, viewModel.getUseExpanded());
final boolean useExpanded = viewModel != null && viewModel.getUseExpanded();
args.putBoolean(SpellWindowFragment.USE_EXPANDED_KEY, useExpanded);
final FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(anim.right_to_left_enter, anim.identity);
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/dnd/jon/spellbook/SortFilterFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ private void setupFilterOptions() {
filterOptions.filterSearchLayout.optionChooser.setOnCheckedChangeListener((chooser, isChecked) -> sortFilterStatus.setApplyFiltersToSearch(isChecked));
filterOptions.useExpandedLayout.optionChooser.setOnCheckedChangeListener((chooser, isChecked) -> sortFilterStatus.setUseTashasExpandedLists(isChecked));
filterOptions.hideDuplicatesLayout.optionChooser.setOnCheckedChangeListener((chooser, isChecked) -> {
sortFilterStatus.setHideDuplicateSpells(isChecked);
filterOptions.prefer2024Layout.optionChooser.setEnabled(isChecked);
try {
sortFilterStatus.setHideDuplicateSpells(isChecked);
filterOptions.prefer2024Layout.optionChooser.setEnabled(isChecked);
} catch (Exception e) {
e.printStackTrace();
}
});
filterOptions.prefer2024Layout.optionChooser.setOnCheckedChangeListener((chooser, isChecked) -> sortFilterStatus.setPrefer2024Duplicates(isChecked));

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/dnd/jon/spellbook/SpellFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ protected FilterResults performFiltering(CharSequence constraint) {
// I'd rather avoid a second pass, but since linked spells won't necessarily
// have the same data, we can't generally know whether we need to filter a spell
// as a duplicate on the first pass
if (hideDuplicates) {
final boolean searchTextOnly = isText && !sortFilterStatus.getApplyFiltersToSearch();
final boolean doDuplicatesFilter = hideDuplicates && !searchTextOnly;
if (doDuplicatesFilter) {
final Ruleset rulesetToIgnore = sortFilterStatus.getPrefer2024Duplicates() ? Ruleset.RULES_2014 : Ruleset.RULES_2024;
filteredSpellList.removeIf((spell) -> {
if (spell.getRuleset() != rulesetToIgnore) {
Expand Down

0 comments on commit 9f3d23e

Please sign in to comment.