diff options
author | vbh <code@bindu.io> | 2021-12-19 16:28:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-19 17:28:45 +0100 |
commit | a399702da2e222c586f8f5697076d373b667929a (patch) | |
tree | eda5748c989952aa5f72ba73f980bb87566292ea /app | |
parent | 12be830f217fe9e179bf053665337af39f48aa9e (diff) | |
download | antennapod-a399702da2e222c586f8f5697076d373b667929a.zip |
Rename tags (#5601)
Diffstat (limited to 'app')
10 files changed, 139 insertions, 79 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index 7854f7aa9..34eb48b6b 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -194,10 +194,10 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder> bindListItem(item, (FeedHolder) holder); if (item.type == NavDrawerData.DrawerItem.Type.FEED) { bindFeedView((NavDrawerData.FeedDrawerItem) item, (FeedHolder) holder); - holder.itemView.setOnCreateContextMenuListener(itemAccess); } else { bindTagView((NavDrawerData.TagDrawerItem) item, (FeedHolder) holder); } + holder.itemView.setOnCreateContextMenuListener(itemAccess); } if (viewType != VIEW_TYPE_SECTION_DIVIDER) { TypedValue typedValue = new TypedValue(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java index eb2239177..21c5e1897 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java @@ -47,7 +47,7 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription private final WeakReference<MainActivity> mainActivityRef; private List<NavDrawerData.DrawerItem> listItems; - private Feed selectedFeed = null; + private NavDrawerData.DrawerItem selectedItem = null; int longPressedPosition = 0; // used to init actionMode public SubscriptionsRecyclerAdapter(MainActivity mainActivity) { @@ -61,8 +61,8 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription return listItems.get(position); } - public Feed getSelectedFeed() { - return selectedFeed; + public NavDrawerData.DrawerItem getSelectedItem() { + return selectedItem; } @NonNull @@ -113,11 +113,9 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription holder.itemView.setOnLongClickListener(v -> { if (!inActionMode()) { if (isFeed) { - selectedFeed = ((NavDrawerData.FeedDrawerItem) getItem(holder.getBindingAdapterPosition())).feed; longPressedPosition = holder.getBindingAdapterPosition(); - } else { - selectedFeed = null; } + selectedItem = (NavDrawerData.DrawerItem) getItem(holder.getBindingAdapterPosition()); } return false; }); @@ -151,12 +149,17 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - if (selectedFeed != null && !inActionMode()) { - MenuInflater inflater = mainActivityRef.get().getMenuInflater(); + if (inActionMode() || selectedItem == null) { + return; + } + MenuInflater inflater = mainActivityRef.get().getMenuInflater(); + if (selectedItem.type == NavDrawerData.DrawerItem.Type.FEED) { inflater.inflate(R.menu.nav_feed_context, menu); - menu.setHeaderTitle(selectedFeed.getTitle()); menu.findItem(R.id.multi_select).setVisible(true); + } else { + inflater.inflate(R.menu.nav_folder_context, menu); } + menu.setHeaderTitle(selectedItem.getTitle()); } public boolean onContextItemSelected(MenuItem item) { diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/RenameFeedDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/RenameFeedDialog.java deleted file mode 100644 index 42a854cd8..000000000 --- a/app/src/main/java/de/danoeh/antennapod/dialog/RenameFeedDialog.java +++ /dev/null @@ -1,50 +0,0 @@ -package de.danoeh.antennapod.dialog; - -import android.app.Activity; - -import java.lang.ref.WeakReference; - -import android.view.View; -import androidx.appcompat.app.AlertDialog; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.model.feed.Feed; -import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.databinding.EditTextDialogBinding; - -public class RenameFeedDialog { - - private final WeakReference<Activity> activityRef; - private final Feed feed; - - public RenameFeedDialog(Activity activity, Feed feed) { - this.activityRef = new WeakReference<>(activity); - this.feed = feed; - } - - public void show() { - Activity activity = activityRef.get(); - if(activity == null) { - return; - } - - View content = View.inflate(activity, R.layout.edit_text_dialog, null); - EditTextDialogBinding alertViewBinding = EditTextDialogBinding.bind(content); - - alertViewBinding.urlEditText.setText(feed.getTitle()); - AlertDialog dialog = new AlertDialog.Builder(activity) - .setView(content) - .setTitle(de.danoeh.antennapod.core.R.string.rename_feed_label) - .setPositiveButton(android.R.string.ok, (d, input) -> { - feed.setCustomTitle(alertViewBinding.urlEditText.getText().toString()); - DBWriter.setFeedCustomTitle(feed); - }) - .setNeutralButton(de.danoeh.antennapod.core.R.string.reset, null) - .setNegativeButton(de.danoeh.antennapod.core.R.string.cancel_label, null) - .show(); - - // To prevent cancelling the dialog on button click - dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener( - (view) -> alertViewBinding.urlEditText.setText(feed.getFeedTitle())); - } - -} diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/RenameItemDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/RenameItemDialog.java new file mode 100644 index 000000000..2f9516e0c --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/dialog/RenameItemDialog.java @@ -0,0 +1,81 @@ +package de.danoeh.antennapod.dialog; + +import android.app.Activity; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; + +import android.view.View; +import androidx.appcompat.app.AlertDialog; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.storage.NavDrawerData; +import de.danoeh.antennapod.model.feed.Feed; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.databinding.EditTextDialogBinding; +import de.danoeh.antennapod.model.feed.FeedPreferences; + +public class RenameItemDialog { + + private final WeakReference<Activity> activityRef; + private Feed feed = null; + private NavDrawerData.DrawerItem drawerItem = null; + + public RenameItemDialog(Activity activity, Feed feed) { + this.activityRef = new WeakReference<>(activity); + this.feed = feed; + } + + public RenameItemDialog(Activity activity, NavDrawerData.DrawerItem drawerItem) { + this.activityRef = new WeakReference<>(activity); + this.drawerItem = drawerItem; + } + + public void show() { + Activity activity = activityRef.get(); + if (activity == null) { + return; + } + + View content = View.inflate(activity, R.layout.edit_text_dialog, null); + EditTextDialogBinding alertViewBinding = EditTextDialogBinding.bind(content); + String title = feed != null ? feed.getTitle() : drawerItem.getTitle(); + + alertViewBinding.urlEditText.setText(title); + AlertDialog dialog = new AlertDialog.Builder(activity) + .setView(content) + .setTitle(feed != null ? R.string.rename_feed_label : R.string.rename_tag_label) + .setPositiveButton(android.R.string.ok, (d, input) -> { + String newTitle = alertViewBinding.urlEditText.getText().toString(); + if (feed != null) { + feed.setCustomTitle(newTitle); + DBWriter.setFeedCustomTitle(feed); + } else { + renameTag(newTitle); + } + }) + .setNeutralButton(de.danoeh.antennapod.core.R.string.reset, null) + .setNegativeButton(de.danoeh.antennapod.core.R.string.cancel_label, null) + .show(); + + // To prevent cancelling the dialog on button click + dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener( + (view) -> alertViewBinding.urlEditText.setText(title)); + } + + private void renameTag(String title) { + if (NavDrawerData.DrawerItem.Type.TAG == drawerItem.type) { + List<FeedPreferences> feedPreferences = new ArrayList<>(); + for (NavDrawerData.DrawerItem item : ((NavDrawerData.TagDrawerItem) drawerItem).children) { + feedPreferences.add(((NavDrawerData.FeedDrawerItem) item).feed.getPreferences()); + } + + for (FeedPreferences preferences : feedPreferences) { + preferences.getTags().remove(drawerItem.getTitle()); + preferences.getTags().add(title); + DBWriter.setFeedPreferences(preferences); + } + } + } + +} 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 d74981b7f..5df8e2ccf 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -72,7 +72,7 @@ import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil; import de.danoeh.antennapod.dialog.FilterDialog; import de.danoeh.antennapod.dialog.RemoveFeedDialog; -import de.danoeh.antennapod.dialog.RenameFeedDialog; +import de.danoeh.antennapod.dialog.RenameItemDialog; import de.danoeh.antennapod.fragment.swipeactions.SwipeActions; import de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; @@ -331,7 +331,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem } final int itemId = item.getItemId(); if (itemId == R.id.rename_item) { - new RenameFeedDialog(getActivity(), feed).show(); + new RenameItemDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_item) { ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null); 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 18defc545..a5cabeb29 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -39,7 +39,7 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.NavDrawerData; import de.danoeh.antennapod.dialog.RemoveFeedDialog; import de.danoeh.antennapod.dialog.SubscriptionsFilterDialog; -import de.danoeh.antennapod.dialog.RenameFeedDialog; +import de.danoeh.antennapod.dialog.RenameItemDialog; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -124,24 +124,28 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS @Override public void onCreateContextMenu(@NonNull ContextMenu menu, @NonNull View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - if (contextPressedItem.type != NavDrawerData.DrawerItem.Type.FEED) { - return; // Should actually never happen because the context menu is not set up for other items - } - MenuInflater inflater = getActivity().getMenuInflater(); - inflater.inflate(R.menu.nav_feed_context, menu); - menu.setHeaderTitle(((NavDrawerData.FeedDrawerItem) contextPressedItem).feed.getTitle()); - // episodes are not loaded, so we cannot check if the podcast has new or unplayed ones! + menu.setHeaderTitle(contextPressedItem.getTitle()); + if (contextPressedItem.type == NavDrawerData.DrawerItem.Type.FEED) { + inflater.inflate(R.menu.nav_feed_context, menu); + // episodes are not loaded, so we cannot check if the podcast has new or unplayed ones! + } else { + inflater.inflate(R.menu.nav_folder_context, menu); + } } @Override public boolean onContextItemSelected(@NonNull MenuItem item) { NavDrawerData.DrawerItem pressedItem = contextPressedItem; contextPressedItem = null; - if (pressedItem != null && pressedItem.type == NavDrawerData.DrawerItem.Type.FEED) { + if (pressedItem == null) { + return false; + } + if (pressedItem.type == NavDrawerData.DrawerItem.Type.FEED) { return onFeedContextMenuClicked(((NavDrawerData.FeedDrawerItem) pressedItem).feed, item); + } else { + return onTagContextMenuClicked(pressedItem, item); } - return false; } private boolean onFeedContextMenuClicked(Feed feed, MenuItem item) { @@ -163,7 +167,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS .show(getChildFragmentManager(), TagSettingsDialog.TAG); return true; } else if (itemId == R.id.rename_item) { - new RenameFeedDialog(getActivity(), feed).show(); + new RenameItemDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_item) { ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null); @@ -173,6 +177,15 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS return super.onContextItemSelected(item); } + private boolean onTagContextMenuClicked(NavDrawerData.DrawerItem drawerItem, MenuItem item) { + final int itemId = item.getItemId(); + if (itemId == R.id.rename_folder_item) { + new RenameItemDialog(getActivity(), drawerItem).show(); + return true; + } + return super.onContextItemSelected(item); + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) { loadData(); 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 c4ac25455..200f4dcd6 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -55,7 +55,7 @@ import de.danoeh.antennapod.core.storage.NavDrawerData; import de.danoeh.antennapod.core.util.download.AutoUpdateManager; import de.danoeh.antennapod.dialog.FeedSortDialog; import de.danoeh.antennapod.dialog.RemoveFeedDialog; -import de.danoeh.antennapod.dialog.RenameFeedDialog; +import de.danoeh.antennapod.dialog.RenameItemDialog; import de.danoeh.antennapod.dialog.SubscriptionsFilterDialog; import de.danoeh.antennapod.fragment.actions.FeedMultiSelectActionHandler; import de.danoeh.antennapod.model.feed.Feed; @@ -334,11 +334,17 @@ public class SubscriptionFragment extends Fragment @Override public boolean onContextItemSelected(MenuItem item) { - Feed feed = subscriptionAdapter.getSelectedFeed(); - if (feed == null) { + NavDrawerData.DrawerItem drawerItem = subscriptionAdapter.getSelectedItem(); + if (drawerItem == null) { return false; } int itemId = item.getItemId(); + if (drawerItem.type == NavDrawerData.DrawerItem.Type.TAG && itemId == R.id.rename_folder_item) { + new RenameItemDialog(getActivity(), drawerItem).show(); + return true; + } + + Feed feed = ((NavDrawerData.FeedDrawerItem) drawerItem).feed; if (itemId == R.id.remove_all_new_flags_item) { displayConfirmationDialog( R.string.remove_all_new_flags_label, @@ -350,7 +356,7 @@ public class SubscriptionFragment extends Fragment .show(getChildFragmentManager(), TagSettingsDialog.TAG); return true; } else if (itemId == R.id.rename_item) { - new RenameFeedDialog(getActivity(), feed).show(); + new RenameItemDialog(getActivity(), feed).show(); return true; } else if (itemId == R.id.remove_item) { RemoveFeedDialog.show(getContext(), feed); 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 43bd25842..d08aa645f 100644 --- a/app/src/main/res/menu/nav_feed_action_speeddial.xml +++ b/app/src/main/res/menu/nav_feed_action_speeddial.xml @@ -28,6 +28,6 @@ <item android:id="@+id/edit_tags" android:menuCategory="container" - android:title="@string/add_to_folder" + android:title="@string/edit_tags" android:icon="@drawable/ic_tag"/> </menu> diff --git a/app/src/main/res/menu/nav_feed_context.xml b/app/src/main/res/menu/nav_feed_context.xml index e45fe24e0..3f5127f36 100644 --- a/app/src/main/res/menu/nav_feed_context.xml +++ b/app/src/main/res/menu/nav_feed_context.xml @@ -9,7 +9,7 @@ <item android:id="@+id/edit_tags" android:menuCategory="container" - android:title="@string/add_to_folder" /> + android:title="@string/edit_tags" /> <item android:id="@+id/rename_item" diff --git a/app/src/main/res/menu/nav_folder_context.xml b/app/src/main/res/menu/nav_folder_context.xml new file mode 100644 index 000000000..eb6515bed --- /dev/null +++ b/app/src/main/res/menu/nav_folder_context.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:id="@+id/rename_folder_item" + android:menuCategory="container" + android:title="@string/rename_tag_label" /> +</menu>
\ No newline at end of file |