@Override public void filter() { boolean remove = true; if (filteredMonsters.size() > 0) { for (int i = 0; i < filteredMonsters.size(); i++) { monsterList.add(filteredMonsters.get(i)); } filteredMonsters.clear(); } Iterator<BaseMonster> iter = monsterList.iterator(); if (Singleton.getInstance().getFilterElement1().size() != 0 || Singleton.getInstance().getFilterElement2().size() != 0 || Singleton.getInstance().getFilterTypes().size() != 0 || Singleton.getInstance().getFilterAwakenings().size() != 0 || Singleton.getInstance().getFilterLatents().size() != 0) { while (iter.hasNext()) { BaseMonster monster = iter.next(); if (Singleton.getInstance().getFilterElement1().size() != 0) { if (Singleton.getInstance().getFilterElement1().contains(monster.getElement1())) { remove = false; } } if (Singleton.getInstance().getFilterElement2().size() != 0 && remove) { if (Singleton.getInstance().getFilterElement2().contains(monster.getElement2())) { remove = false; } } if (Singleton.getInstance().getFilterTypes().size() != 0 && remove) { for (int i = 0; i < monster.getTypes().size(); i++) { if (Singleton.getInstance().getFilterTypes().contains(monster.getTypes().get(i)) && remove) { remove = false; } } } if (Singleton.getInstance().getFilterAwakenings().size() != 0 && remove) { for (int i = 0; i < monster.getAwokenSkills().size(); i++) { if (Singleton.getInstance() .getFilterAwakenings() .contains(monster.getAwokenSkills(i).getValue()) && remove) { remove = false; } } } if (remove) { filteredMonsters.add(monster); iter.remove(); } remove = true; } } sortArrayList(Singleton.getInstance().getBaseSortMethod()); monsterPortraitListRecycler.notifyDataSetChanged(); if (monsterList.size() == 0) { noResults.setVisibility(View.VISIBLE); } else { noResults.setVisibility(View.INVISIBLE); } }
public void reverseArrayList() { switch (Singleton.getInstance().getBaseSortMethod()) { case 202: element2Reverse(); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 302: type2Reverse(); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 303: type3Reverse(); monsterPortraitListRecycler.notifyDataSetChanged(); break; default: defaultReverse(); monsterPortraitListRecycler.notifyDataSetChanged(); break; } }
@Override public void filterRequirements() { boolean match = true; int counter = 0; if (filteredMonsters.size() > 0) { for (int i = 0; i < filteredMonsters.size(); i++) { monsterList.add(filteredMonsters.get(i)); } filteredMonsters.clear(); } Iterator<BaseMonster> iter = monsterList.iterator(); if (Singleton.getInstance().getFilterElement1().size() != 0 || Singleton.getInstance().getFilterElement2().size() != 0 || Singleton.getInstance().getFilterTypes().size() != 0 || Singleton.getInstance().getFilterAwakenings().size() != 0 || Singleton.getInstance().getFilterLatents().size() != 0) { while (iter.hasNext()) { BaseMonster monster = iter.next(); if (Singleton.getInstance().getFilterElement1().size() != 0) { if (!Singleton.getInstance().getFilterElement1().contains(monster.getElement1())) { match = false; } } if (Singleton.getInstance().getFilterElement2().size() != 0 && match) { if (!Singleton.getInstance().getFilterElement2().contains(monster.getElement2())) { match = false; } } if (Singleton.getInstance().getFilterTypes().size() != 0 && match) { for (int i = 0; i < monster.getTypes().size(); i++) { if (Singleton.getInstance() .getFilterTypes() .contains(monster.getTypes().get(i))) { counter++; } } if (counter != Singleton.getInstance().getFilterTypes().size()) { match = false; } counter = 0; } if (Singleton.getInstance().getFilterAwakenings().size() != 0 && match) { ArrayList<Integer> trimmedAwakenings = new ArrayList<>(); for (int i = 0; i < monster.getAwokenSkills().size(); i++) { if (!trimmedAwakenings.contains(monster.getAwokenSkills(i).getValue())) { trimmedAwakenings.add(monster.getAwokenSkills(i).getValue()); } } for (int i = 0; i < trimmedAwakenings.size(); i++) { if (Singleton.getInstance() .getFilterAwakenings() .contains(trimmedAwakenings.get(i))) { counter++; } } if (counter != Singleton.getInstance().getFilterAwakenings().size()) { match = false; } counter = 0; } if (!match) { filteredMonsters.add(monster); iter.remove(); } match = true; } } sortArrayList(Singleton.getInstance().getBaseSortMethod()); monsterPortraitListRecycler.notifyDataSetChanged(); if (monsterList.size() == 0) { noResults.setVisibility(View.VISIBLE); } else { noResults.setVisibility(View.INVISIBLE); } }
public void sortArrayList(int sortMethod) { switch (sortMethod) { case 0: Singleton.getInstance().setBaseSortMethod(sortMethod); Collections.sort(monsterList, monsterAlphabeticalComparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 1: Singleton.getInstance().setBaseSortMethod(sortMethod); Collections.sort(monsterList, monsterNumberComparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 2: if (sortElementDialogFragment == null) { sortElementDialogFragment = SortElementDialogFragment.newInstance(sortByElement); } if (!sortElementDialogFragment.isAdded() && !firstRun) { sortElementDialogFragment.show(getChildFragmentManager(), "Sort by Element"); } break; case 3: if (sortTypeDialogFragment == null) { sortTypeDialogFragment = SortTypeDialogFragment.newInstance(sortByType); } if (!sortTypeDialogFragment.isAdded() && !firstRun) { sortTypeDialogFragment.show(getChildFragmentManager(), "Sort by Type"); } break; case 4: if (sortStatsDialogFragment == null) { sortStatsDialogFragment = SortStatsDialogFragment.newInstance(sortByStats); } if (!sortStatsDialogFragment.isAdded() && !firstRun) { sortStatsDialogFragment.show(getChildFragmentManager(), "Sort by Stats"); } break; case 5: Singleton.getInstance().setBaseSortMethod(sortMethod); Collections.sort(monsterList, monsterRarityComparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 6: Singleton.getInstance().setBaseSortMethod(sortMethod); Collections.sort(monsterList, monsterAwakeningComparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 201: Collections.sort(monsterList, monsterElement1Comparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 202: Collections.sort(monsterList, monsterElement2Comparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 301: Collections.sort(monsterList, monsterType1Comparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 302: Collections.sort(monsterList, monsterType2Comparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 303: Collections.sort(monsterList, monsterType3Comparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 401: Collections.sort(monsterList, monsterHpComparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 402: Collections.sort(monsterList, monsterAtkComparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; case 403: Collections.sort(monsterList, monsterRcvComparator); monsterPortraitListRecycler.notifyDataSetChanged(); break; } }
@Override public void sortRcv() { Singleton.getInstance().setBaseSortMethod(403); Collections.sort(monsterList, monsterRcvComparator); monsterPortraitListRecycler.notifyDataSetChanged(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.toggleCoop: monsterPortraitListRecycler.notifyDataSetChanged(); break; case R.id.reverseList: reverseArrayList(); break; case R.id.sortAlphabetical: sortArrayList(0); break; case R.id.sortId: sortArrayList(1); break; case R.id.sortElement: sortArrayList(2); break; case R.id.sortType: sortArrayList(3); break; case R.id.sortStat: sortArrayList(4); break; case R.id.sortRarity: sortArrayList(5); break; case R.id.sortAwakenings: sortArrayList(6); break; case R.id.sortPlus: sortArrayList(7); break; case R.id.sortFavorite: sortArrayList(8); break; case R.id.sortLevel: sortArrayList(9); break; case R.id.sortLead: sortArrayList(10); break; case R.id.sortHelper: sortArrayList(11); break; case R.id.filterList: if (filterDialogFragment == null) { filterDialogFragment = FilterDialogFragment.newInstance(saveTeam, false); } if (!filterDialogFragment.isAdded() && !firstRun) { filterDialogFragment.show(getChildFragmentManager(), false, "Filter"); } break; case R.id.toggleGrid: preferences.edit().putBoolean("isGrid", !isGrid).apply(); isGrid = preferences.getBoolean("isGrid", true); if (isGrid) { monsterListView.setLayoutManager( new StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL)); } else { monsterListView.setLayoutManager( new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)); } monsterPortraitListRecycler.notifyDataSetChanged(isGrid); break; } return super.onOptionsItemSelected(item); }