Add 'add to tag' option to multiselect menu (#5553)
This commit is contained in:
parent
71880c62d9
commit
b00e14545d
|
@ -27,7 +27,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class TagSettingsDialog extends DialogFragment {
|
public class TagSettingsDialog extends DialogFragment {
|
||||||
public static final String TAG = "TagSettingsDialog";
|
public static final String TAG = "TagSettingsDialog";
|
||||||
|
@ -36,10 +38,10 @@ public class TagSettingsDialog extends DialogFragment {
|
||||||
private EditTagsDialogBinding viewBinding;
|
private EditTagsDialogBinding viewBinding;
|
||||||
private TagSelectionAdapter adapter;
|
private TagSelectionAdapter adapter;
|
||||||
|
|
||||||
public static TagSettingsDialog newInstance(FeedPreferences preferences) {
|
public static TagSettingsDialog newInstance(List<FeedPreferences> preferencesList) {
|
||||||
TagSettingsDialog fragment = new TagSettingsDialog();
|
TagSettingsDialog fragment = new TagSettingsDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putSerializable(ARG_FEED_PREFERENCES, preferences);
|
args.putSerializable(ARG_FEED_PREFERENCES, new ArrayList<>(preferencesList));
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
@ -47,8 +49,14 @@ public class TagSettingsDialog extends DialogFragment {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||||
FeedPreferences preferences = (FeedPreferences) getArguments().getSerializable(ARG_FEED_PREFERENCES);
|
ArrayList<FeedPreferences> feedPreferencesList =
|
||||||
displayedTags = new ArrayList<>(preferences.getTags());
|
(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);
|
displayedTags.remove(FeedPreferences.TAG_ROOT);
|
||||||
|
|
||||||
viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater());
|
viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater());
|
||||||
|
@ -57,7 +65,7 @@ public class TagSettingsDialog extends DialogFragment {
|
||||||
adapter = new TagSelectionAdapter();
|
adapter = new TagSelectionAdapter();
|
||||||
adapter.setHasStableIds(true);
|
adapter.setHasStableIds(true);
|
||||||
viewBinding.tagsRecycler.setAdapter(adapter);
|
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 ->
|
viewBinding.newTagButton.setOnClickListener(v ->
|
||||||
addTag(viewBinding.newTagEditText.getText().toString().trim()));
|
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());
|
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
|
||||||
dialog.setView(viewBinding.getRoot());
|
dialog.setView(viewBinding.getRoot());
|
||||||
dialog.setTitle(R.string.feed_tags_label);
|
dialog.setTitle(R.string.feed_tags_label);
|
||||||
dialog.setPositiveButton(android.R.string.ok, (d, input) -> {
|
dialog.setPositiveButton(android.R.string.ok, (d, input) -> {
|
||||||
addTag(viewBinding.newTagEditText.getText().toString().trim());
|
addTag(viewBinding.newTagEditText.getText().toString().trim());
|
||||||
preferences.getTags().clear();
|
updatePreferencesTags(feedPreferencesList, commonTags);
|
||||||
preferences.getTags().addAll(displayedTags);
|
|
||||||
if (viewBinding.rootFolderCheckbox.isChecked()) {
|
|
||||||
preferences.getTags().add(FeedPreferences.TAG_ROOT);
|
|
||||||
}
|
|
||||||
DBWriter.setFeedPreferences(preferences);
|
|
||||||
});
|
});
|
||||||
dialog.setNegativeButton(R.string.cancel_label, null);
|
dialog.setNegativeButton(R.string.cancel_label, null);
|
||||||
return dialog.create();
|
return dialog.create();
|
||||||
|
@ -123,6 +130,17 @@ public class TagSettingsDialog extends DialogFragment {
|
||||||
adapter.notifyDataSetChanged();
|
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> {
|
public class TagSelectionAdapter extends RecyclerView.Adapter<TagSelectionAdapter.ViewHolder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,6 +38,7 @@ import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class FeedSettingsFragment extends Fragment {
|
public class FeedSettingsFragment extends Fragment {
|
||||||
|
@ -391,7 +392,8 @@ public class FeedSettingsFragment extends Fragment {
|
||||||
|
|
||||||
private void setupTags() {
|
private void setupTags() {
|
||||||
findPreference(PREF_TAGS).setOnPreferenceClickListener(preference -> {
|
findPreference(PREF_TAGS).setOnPreferenceClickListener(preference -> {
|
||||||
TagSettingsDialog.newInstance(feedPreferences).show(getChildFragmentManager(), TagSettingsDialog.TAG);
|
TagSettingsDialog.newInstance(Collections.singletonList(feedPreferences))
|
||||||
|
.show(getChildFragmentManager(), TagSettingsDialog.TAG);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -158,7 +159,8 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
||||||
removeAllNewFlagsConfirmationDialog.createNewDialog().show();
|
removeAllNewFlagsConfirmationDialog.createNewDialog().show();
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.edit_tags) {
|
} 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;
|
return true;
|
||||||
} else if (itemId == R.id.rename_item) {
|
} else if (itemId == R.id.rename_item) {
|
||||||
new RenameFeedDialog(getActivity(), feed).show();
|
new RenameFeedDialog(getActivity(), feed).show();
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
@ -345,7 +346,8 @@ public class SubscriptionFragment extends Fragment
|
||||||
() -> DBWriter.removeFeedNewFlag(feed.getId()));
|
() -> DBWriter.removeFeedNewFlag(feed.getId()));
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.edit_tags) {
|
} 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;
|
return true;
|
||||||
} else if (itemId == R.id.rename_item) {
|
} else if (itemId == R.id.rename_item) {
|
||||||
new RenameFeedDialog(getActivity(), feed).show();
|
new RenameFeedDialog(getActivity(), feed).show();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
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.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.databinding.PlaybackSpeedFeedSettingDialogBinding;
|
import de.danoeh.antennapod.databinding.PlaybackSpeedFeedSettingDialogBinding;
|
||||||
import de.danoeh.antennapod.dialog.RemoveFeedDialog;
|
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.PreferenceListDialog;
|
||||||
import de.danoeh.antennapod.fragment.preferences.dialog.PreferenceSwitchDialog;
|
import de.danoeh.antennapod.fragment.preferences.dialog.PreferenceSwitchDialog;
|
||||||
import de.danoeh.antennapod.model.feed.Feed;
|
import de.danoeh.antennapod.model.feed.Feed;
|
||||||
|
@ -44,6 +46,8 @@ public class FeedMultiSelectActionHandler {
|
||||||
autoDeleteEpisodesPrefHandler();
|
autoDeleteEpisodesPrefHandler();
|
||||||
} else if (id == R.id.playback_speed) {
|
} else if (id == R.id.playback_speed) {
|
||||||
playbackSpeedPrefHandler();
|
playbackSpeedPrefHandler();
|
||||||
|
} else if (id == R.id.edit_tags) {
|
||||||
|
editFeedPrefTags();
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Unrecognized speed dial action item. Do nothing. id=" + id);
|
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());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,16 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp">
|
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
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/tagsRecycler"
|
android:id="@+id/tagsRecycler"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -25,4 +25,9 @@
|
||||||
android:menuCategory="container"
|
android:menuCategory="container"
|
||||||
android:title="@string/playback_speed"
|
android:title="@string/playback_speed"
|
||||||
android:icon="@drawable/ic_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>
|
</menu>
|
||||||
|
|
|
@ -696,6 +696,7 @@
|
||||||
<string name="feed_tags_label">Tags</string>
|
<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_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="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="auto_download_settings_label">Auto Download Settings</string>
|
||||||
<string name="episode_filters_label">Episode Filter</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>
|
<string name="episode_filters_description">List of terms used to decide if an episode should be included or excluded when auto downloading</string>
|
||||||
|
|
Loading…
Reference in New Issue