Rename tags (#5601)
This commit is contained in:
parent
12be830f21
commit
a399702da2
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
inflater.inflate(R.menu.nav_feed_context, menu);
|
||||
menu.setHeaderTitle(selectedFeed.getTitle());
|
||||
menu.findItem(R.id.multi_select).setVisible(true);
|
||||
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.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) {
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
return onFeedContextMenuClicked(((NavDrawerData.FeedDrawerItem) pressedItem).feed, item);
|
||||
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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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>
|
|
@ -186,7 +186,8 @@
|
|||
<item quantity="one">%d subscription updated.</item>
|
||||
<item quantity="other">%d subscriptions updated.</item>
|
||||
</plurals>
|
||||
<string name="add_to_folder">Add to folder</string>
|
||||
<string name="edit_tags">Edit tags</string>
|
||||
<string name="rename_tag_label">Rename tag</string>
|
||||
<string name="confirm_mobile_feed_refresh_dialog_message">Downloading episodes over mobile data connection is disabled in the settings.\n\nDo you still want to refresh all podcasts over mobile data?</string>
|
||||
|
||||
<!-- actions on feeditems -->
|
||||
|
|
Loading…
Reference in New Issue