diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java index 0ff6fb79f..8f5f1b802 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java @@ -27,7 +27,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class TagSettingsDialog extends DialogFragment { public static final String TAG = "TagSettingsDialog"; @@ -36,10 +38,10 @@ public class TagSettingsDialog extends DialogFragment { private EditTagsDialogBinding viewBinding; private TagSelectionAdapter adapter; - public static TagSettingsDialog newInstance(FeedPreferences preferences) { + public static TagSettingsDialog newInstance(List preferencesList) { TagSettingsDialog fragment = new TagSettingsDialog(); Bundle args = new Bundle(); - args.putSerializable(ARG_FEED_PREFERENCES, preferences); + args.putSerializable(ARG_FEED_PREFERENCES, new ArrayList<>(preferencesList)); fragment.setArguments(args); return fragment; } @@ -47,8 +49,14 @@ public class TagSettingsDialog extends DialogFragment { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { - FeedPreferences preferences = (FeedPreferences) getArguments().getSerializable(ARG_FEED_PREFERENCES); - displayedTags = new ArrayList<>(preferences.getTags()); + ArrayList feedPreferencesList = + (ArrayList) getArguments().getSerializable(ARG_FEED_PREFERENCES); + Set commonTags = new HashSet<>(feedPreferencesList.get(0).getTags()); + + for (FeedPreferences preference : feedPreferencesList) { + commonTags.retainAll(preference.getTags()); + } + displayedTags = new ArrayList<>(commonTags); displayedTags.remove(FeedPreferences.TAG_ROOT); viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater()); @@ -57,7 +65,7 @@ public class TagSettingsDialog extends DialogFragment { adapter = new TagSelectionAdapter(); adapter.setHasStableIds(true); viewBinding.tagsRecycler.setAdapter(adapter); - viewBinding.rootFolderCheckbox.setChecked(preferences.getTags().contains(FeedPreferences.TAG_ROOT)); + viewBinding.rootFolderCheckbox.setChecked(commonTags.contains(FeedPreferences.TAG_ROOT)); viewBinding.newTagButton.setOnClickListener(v -> addTag(viewBinding.newTagEditText.getText().toString().trim())); @@ -73,17 +81,16 @@ public class TagSettingsDialog extends DialogFragment { } }); + if (feedPreferencesList.size() > 1) { + viewBinding.commonTagsInfo.setVisibility(View.VISIBLE); + } + AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()); dialog.setView(viewBinding.getRoot()); dialog.setTitle(R.string.feed_tags_label); dialog.setPositiveButton(android.R.string.ok, (d, input) -> { addTag(viewBinding.newTagEditText.getText().toString().trim()); - preferences.getTags().clear(); - preferences.getTags().addAll(displayedTags); - if (viewBinding.rootFolderCheckbox.isChecked()) { - preferences.getTags().add(FeedPreferences.TAG_ROOT); - } - DBWriter.setFeedPreferences(preferences); + updatePreferencesTags(feedPreferencesList, commonTags); }); dialog.setNegativeButton(R.string.cancel_label, null); return dialog.create(); @@ -123,6 +130,17 @@ public class TagSettingsDialog extends DialogFragment { adapter.notifyDataSetChanged(); } + private void updatePreferencesTags(List feedPreferencesList, Set commonTags) { + if (viewBinding.rootFolderCheckbox.isChecked()) { + displayedTags.add(FeedPreferences.TAG_ROOT); + } + for (FeedPreferences preferences : feedPreferencesList) { + preferences.getTags().removeAll(commonTags); + preferences.getTags().addAll(displayedTags); + DBWriter.setFeedPreferences(preferences); + } + } + public class TagSelectionAdapter extends RecyclerView.Adapter { @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java index 44493c64e..0c2103d25 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -38,6 +38,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import org.greenrobot.eventbus.EventBus; +import java.util.Collections; import java.util.Locale; public class FeedSettingsFragment extends Fragment { @@ -391,7 +392,8 @@ public class FeedSettingsFragment extends Fragment { private void setupTags() { findPreference(PREF_TAGS).setOnPreferenceClickListener(preference -> { - TagSettingsDialog.newInstance(feedPreferences).show(getChildFragmentManager(), TagSettingsDialog.TAG); + TagSettingsDialog.newInstance(Collections.singletonList(feedPreferences)) + .show(getChildFragmentManager(), TagSettingsDialog.TAG); return true; }); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java index 85de99766..18defc545 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -50,6 +50,7 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -158,7 +159,8 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS removeAllNewFlagsConfirmationDialog.createNewDialog().show(); return true; } else if (itemId == R.id.edit_tags) { - TagSettingsDialog.newInstance(feed.getPreferences()).show(getChildFragmentManager(), TagSettingsDialog.TAG); + TagSettingsDialog.newInstance(Collections.singletonList(feed.getPreferences())) + .show(getChildFragmentManager(), TagSettingsDialog.TAG); return true; } else if (itemId == R.id.rename_item) { new RenameFeedDialog(getActivity(), feed).show(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index a87575681..c4ac25455 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -33,6 +33,7 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.concurrent.Callable; @@ -345,7 +346,8 @@ public class SubscriptionFragment extends Fragment () -> DBWriter.removeFeedNewFlag(feed.getId())); return true; } else if (itemId == R.id.edit_tags) { - TagSettingsDialog.newInstance(feed.getPreferences()).show(getChildFragmentManager(), TagSettingsDialog.TAG); + TagSettingsDialog.newInstance(Collections.singletonList(feed.getPreferences())) + .show(getChildFragmentManager(), TagSettingsDialog.TAG); return true; } else if (itemId == R.id.rename_item) { new RenameFeedDialog(getActivity(), feed).show(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java b/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java index 04a19df4a..e3dfe8ade 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/actions/FeedMultiSelectActionHandler.java @@ -10,6 +10,7 @@ import com.google.android.material.snackbar.Snackbar; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -18,6 +19,7 @@ import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.databinding.PlaybackSpeedFeedSettingDialogBinding; import de.danoeh.antennapod.dialog.RemoveFeedDialog; +import de.danoeh.antennapod.dialog.TagSettingsDialog; import de.danoeh.antennapod.fragment.preferences.dialog.PreferenceListDialog; import de.danoeh.antennapod.fragment.preferences.dialog.PreferenceSwitchDialog; import de.danoeh.antennapod.model.feed.Feed; @@ -44,6 +46,8 @@ public class FeedMultiSelectActionHandler { autoDeleteEpisodesPrefHandler(); } else if (id == R.id.playback_speed) { playbackSpeedPrefHandler(); + } else if (id == R.id.edit_tags) { + editFeedPrefTags(); } else { Log.e(TAG, "Unrecognized speed dial action item. Do nothing. id=" + id); } @@ -139,4 +143,13 @@ public class FeedMultiSelectActionHandler { } showMessage(R.plurals.updated_feeds_batch_label, selectedItems.size()); } + + private void editFeedPrefTags() { + ArrayList preferencesList = new ArrayList<>(); + for (Feed feed : selectedItems) { + preferencesList.add(feed.getPreferences()); + } + TagSettingsDialog.newInstance(preferencesList).show(activity.getSupportFragmentManager(), + TagSettingsDialog.TAG); + } } diff --git a/app/src/main/res/layout/edit_tags_dialog.xml b/app/src/main/res/layout/edit_tags_dialog.xml index 57e3c412f..9ac0b60d3 100644 --- a/app/src/main/res/layout/edit_tags_dialog.xml +++ b/app/src/main/res/layout/edit_tags_dialog.xml @@ -7,6 +7,16 @@ android:orientation="vertical" android:padding="16dp"> + + + diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 4333929c4..011a9fe52 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -696,6 +696,7 @@ Tags Change the tags of this podcast to help organize your subscriptions Show in main list + {fa-info-circle} Only common tags from all selected subscriptions are shown. Other tags stay unaffected. Auto Download Settings Episode Filter List of terms used to decide if an episode should be included or excluded when auto downloading