summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/fragment
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2022-04-22 20:53:29 +0200
committerByteHamster <info@bytehamster.com>2022-04-22 22:17:24 +0200
commit0b431a331128bfcf7af3a6512623df74e38b5776 (patch)
treea513f8882398875124aa48874d30d139910bad0d /app/src/main/java/de/danoeh/antennapod/fragment
parent8775031b20cbb10876b36541f346e0a0efdad1cb (diff)
downloadAntennaPod-0b431a331128bfcf7af3a6512623df74e38b5776.zip
Update filter dialog to Fragment
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/fragment')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java41
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java27
2 files changed, 22 insertions, 46 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java
index f65c6fdc6..706e47135 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java
@@ -10,14 +10,14 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.joanzapata.iconify.Iconify;
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.core.storage.DBReader;
+import de.danoeh.antennapod.dialog.AllEpisodesFilterDialog;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
-import de.danoeh.antennapod.core.storage.DBReader;
-import de.danoeh.antennapod.dialog.FilterDialog;
import org.apache.commons.lang3.StringUtils;
+import org.greenrobot.eventbus.Subscribe;
import java.util.List;
-import java.util.Set;
/**
* Like 'EpisodesFragment' except that it only shows new episodes and
@@ -43,15 +43,22 @@ public class AllEpisodesFragment extends EpisodesListFragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if (!super.onOptionsItemSelected(item)) {
- if (item.getItemId() == R.id.filter_items) {
- showFilterDialog();
- return true;
- }
- return false;
- } else {
+ if (super.onOptionsItemSelected(item)) {
+ return true;
+ }
+ if (item.getItemId() == R.id.filter_items) {
+ AllEpisodesFilterDialog.newInstance(feedItemFilter).show(getChildFragmentManager(), null);
return true;
}
+ return false;
+ }
+
+ @Subscribe
+ public void onFilterChanged(AllEpisodesFilterDialog.AllEpisodesFilterChangedEvent event) {
+ feedItemFilter = new FeedItemFilter(event.filterValues.toArray(new String[0]));
+ SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+ prefs.edit().putString(PREF_FILTER, StringUtils.join(event.filterValues, ",")).apply();
+ loadItems();
}
@Override
@@ -75,20 +82,6 @@ public class AllEpisodesFragment extends EpisodesListFragment {
}
}
- private void showFilterDialog() {
- FilterDialog filterDialog = new FilterDialog(getContext(), feedItemFilter) {
- @Override
- protected void updateFilter(Set<String> filterValues) {
- feedItemFilter = new FeedItemFilter(filterValues.toArray(new String[0]));
- SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- prefs.edit().putString(PREF_FILTER, StringUtils.join(filterValues, ",")).apply();
- loadItems();
- }
- };
-
- filterDialog.openDialog();
- }
-
@Override
protected boolean shouldUpdatedItemRemainInList(FeedItem item) {
SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java
index 4b367fe42..bb20cb4bc 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java
@@ -39,14 +39,13 @@ import de.danoeh.antennapod.core.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
-import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemPermutors;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil;
import de.danoeh.antennapod.databinding.FeedItemListFragmentBinding;
import de.danoeh.antennapod.databinding.MultiSelectSpeedDialBinding;
import de.danoeh.antennapod.dialog.DownloadLogDetailsDialog;
-import de.danoeh.antennapod.dialog.FilterDialog;
+import de.danoeh.antennapod.dialog.FeedItemFilterDialog;
import de.danoeh.antennapod.dialog.RemoveFeedDialog;
import de.danoeh.antennapod.dialog.RenameItemDialog;
import de.danoeh.antennapod.event.FavoritesEvent;
@@ -77,7 +76,6 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.List;
-import java.util.Set;
/**
* Displays a list of FeedItems.
@@ -469,17 +467,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
viewBinding.header.txtvInformation.setText("{md-info-outline} "
+ this.getString(R.string.filtered_label));
Iconify.addIcons(viewBinding.header.txtvInformation);
- viewBinding.header.txtvInformation.setOnClickListener((l) -> {
- FilterDialog filterDialog = new FilterDialog(requireContext(), feed.getItemFilter()) {
- @Override
- protected void updateFilter(Set<String> filterValues) {
- feed.setItemFilter(filterValues.toArray(new String[0]));
- DBWriter.setFeedItemsFilter(feed.getId(), filterValues);
- }
- };
-
- filterDialog.openDialog();
- });
+ viewBinding.header.txtvInformation.setOnClickListener(l ->
+ FeedItemFilterDialog.newInstance(feed).show(getChildFragmentManager(), null));
viewBinding.header.txtvInformation.setVisibility(View.VISIBLE);
} else {
viewBinding.header.txtvInformation.setVisibility(View.GONE);
@@ -504,14 +493,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
((MainActivity) getActivity()).loadChildFragment(fragment, TransitionEffect.SLIDE);
}
});
- viewBinding.header.butFilter.setOnClickListener(
- v -> new FilterDialog(getContext(), feed.getItemFilter()) {
- @Override
- protected void updateFilter(Set<String> filterValues) {
- feed.setItemFilter(filterValues.toArray(new String[0]));
- DBWriter.setFeedItemsFilter(feed.getId(), filterValues);
- }
- }.openDialog());
+ viewBinding.header.butFilter.setOnClickListener(v ->
+ FeedItemFilterDialog.newInstance(feed).show(getChildFragmentManager(), null));
viewBinding.header.txtvFailure.setOnClickListener(v -> showErrorDetails());
headerCreated = true;
}