diff options
author | vbh <code@bindu.io> | 2021-11-21 20:27:23 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-21 21:27:23 +0100 |
commit | b00e14545d472ddd1f13f7467e973dc5365ac77f (patch) | |
tree | 2c6d3c829ea56b44221e8ccec3e973ae2db56381 | |
parent | 71880c62d9fc4bbe8553d57cd144d022d204b799 (diff) | |
download | AntennaPod-b00e14545d472ddd1f13f7467e973dc5365ac77f.zip |
Add 'add to tag' option to multiselect menu (#5553)
8 files changed, 67 insertions, 14 deletions
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<FeedPreferences> 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<FeedPreferences> feedPreferencesList = + (ArrayList<FeedPreferences>) getArguments().getSerializable(ARG_FEED_PREFERENCES); + Set<String> 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<FeedPreferences> feedPreferencesList, Set<String> 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<TagSelectionAdapter.ViewHolder> { @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<FeedPreferences> 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"> + <com.joanzapata.iconify.widget.IconTextView + android:id="@+id/commonTagsInfo" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:visibility="gone" + android:textSize="@dimen/text_size_micro" + android:paddingBottom="16dp" + android:text="@string/multi_feed_common_tags_info" /> + <androidx.recyclerview.widget.RecyclerView android:id="@+id/tagsRecycler" android:layout_width="match_parent" diff --git a/app/src/main/res/menu/nav_feed_action_speeddial.xml b/app/src/main/res/menu/nav_feed_action_speeddial.xml index 2dfa002bb..43bd25842 100644 --- a/app/src/main/res/menu/nav_feed_action_speeddial.xml +++ b/app/src/main/res/menu/nav_feed_action_speeddial.xml @@ -25,4 +25,9 @@ android:menuCategory="container" android:title="@string/playback_speed" android:icon="@drawable/ic_playback_speed"/> + <item + android:id="@+id/edit_tags" + android:menuCategory="container" + android:title="@string/add_to_folder" + android:icon="@drawable/ic_tag"/> </menu> 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 @@ <string name="feed_tags_label">Tags</string> <string name="feed_tags_summary">Change the tags of this podcast to help organize your subscriptions</string> <string name="feed_folders_include_root">Show in main list</string> + <string name="multi_feed_common_tags_info">{fa-info-circle} Only common tags from all selected subscriptions are shown. Other tags stay unaffected.</string> <string name="auto_download_settings_label">Auto Download Settings</string> <string name="episode_filters_label">Episode Filter</string> <string name="episode_filters_description">List of terms used to decide if an episode should be included or excluded when auto downloading</string> |