Add delete option to episode's context menu

This PR makes following changes:

 - Adds delete option to episode's context menus in queue and feed list

 - Adds a storage preference that allows episodes to be automatically removed from queue when they are deleted (by clicking delete in context menu,
or pressing trash can icon on `Completed` tab of `Downloads` page)

 - Adds a test for the aforementioned preference
This commit is contained in:
Petar Kukolj 2018-11-29 21:23:36 +01:00
parent e70a9001dc
commit a1f81d4144
8 changed files with 46 additions and 1 deletions

View File

@ -505,6 +505,20 @@ public class PreferencesTest {
Timeout.getLargeTimeout()));
}
@Test
public void testDeleteRemovesFromQueue() {
clickPreference(withText(R.string.storage_pref));
if (!UserPreferences.shouldDeleteRemoveFromQueue()) {
clickPreference(withText(R.string.pref_delete_removes_from_queue_title));
assertTrue(solo.waitForCondition(UserPreferences::shouldDeleteRemoveFromQueue, Timeout.getLargeTimeout()));
}
final boolean deleteRemovesFromQueue = UserPreferences.shouldDeleteRemoveFromQueue();
solo.clickOnText(solo.getString(R.string.pref_delete_removes_from_queue_title));
assertTrue(solo.waitForCondition(() -> deleteRemovesFromQueue != UserPreferences.shouldDeleteRemoveFromQueue(), Timeout.getLargeTimeout()));
solo.clickOnText(solo.getString(R.string.pref_delete_removes_from_queue_title));
assertTrue(solo.waitForCondition(() -> deleteRemovesFromQueue == UserPreferences.shouldDeleteRemoveFromQueue(), Timeout.getLargeTimeout()));
}
private void clickPreference(Matcher<View> matcher) {
onView(withId(R.id.list))
.perform(RecyclerViewActions.actionOnItem(hasDescendant(matcher), click()));

View File

@ -17,6 +17,7 @@ import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
@ -169,6 +170,9 @@ public class CompletedDownloadsFragment extends ListFragment {
@Override
public void onFeedItemSecondaryAction(FeedItem item) {
DBWriter.deleteFeedMediaOfItem(getActivity(), item.getMedia().getId());
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
DBWriter.removeQueueItem(getActivity(), item, false);
}
}
};

View File

@ -101,7 +101,8 @@ public class FeedItemMenuHandler {
mi.setItemVisibility(R.id.share_download_url_with_position_item, false);
}
mi.setItemVisibility(R.id.share_file, hasMedia && selectedItem.getMedia().fileExists());
boolean fileDownloaded = hasMedia && selectedItem.getMedia().fileExists();
mi.setItemVisibility(R.id.share_file, fileDownloaded);
if (selectedItem.isPlayed()) {
mi.setItemVisibility(R.id.mark_read_item, false);
@ -130,6 +131,8 @@ public class FeedItemMenuHandler {
mi.setItemVisibility(R.id.add_to_favorites_item, !isFavorite);
mi.setItemVisibility(R.id.remove_from_favorites_item, isFavorite);
mi.setItemVisibility(R.id.remove_item, fileDownloaded);
return true;
}
@ -162,6 +165,9 @@ public class FeedItemMenuHandler {
break;
case R.id.remove_item:
DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId());
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
DBWriter.removeQueueItem(context, selectedItem, false);
}
break;
case R.id.mark_read_item:
selectedItem.setPlayed(true);

View File

@ -47,6 +47,10 @@
android:id="@+id/deactivate_auto_download"
android:menuCategory="container"
android:title="@string/deactivate_auto_download" />
<item
android:id="@+id/remove_item"
android:menuCategory="container"
android:title="@string/delete_label" />
<item
android:id="@+id/visit_website_item"

View File

@ -48,6 +48,10 @@
android:id="@+id/deactivate_auto_download"
android:menuCategory="container"
android:title="@string/deactivate_auto_download" />
<item
android:id="@+id/remove_item"
android:menuCategory="container"
android:title="@string/delete_label" />
<item
android:id="@+id/visit_website_item"

View File

@ -25,6 +25,12 @@
android:key="prefFavoriteKeepsEpisode"
android:summary="@string/pref_favorite_keeps_episodes_sum"
android:title="@string/pref_favorite_keeps_episodes_title"/>
<SwitchPreference
android:defaultValue="false"
android:enabled="true"
android:key="prefDeleteRemovesFromQueue"
android:summary="@string/pref_delete_removes_from_queue_sum"
android:title="@string/pref_delete_removes_from_queue_title"/>
<PreferenceCategory android:title="@string/import_export_pref">
<Preference

View File

@ -100,6 +100,7 @@ public class UserPreferences {
// Other
private static final String PREF_DATA_FOLDER = "prefDataFolder";
public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize";
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
// Mediaplayer
public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer";
@ -309,6 +310,10 @@ public class UserPreferences {
return Integer.parseInt(prefs.getString(PREF_SMART_MARK_AS_PLAYED_SECS, "30"));
}
public static boolean shouldDeleteRemoveFromQueue() {
return prefs.getBoolean(PREF_DELETE_REMOVES_FROM_QUEUE, false);
}
public static boolean isAutoFlattr() {
return prefs.getBoolean(PREF_AUTO_FLATTR, false);
}

View File

@ -481,6 +481,8 @@
<string name="double_tap_toast">Tap back button again to exit</string>
<string name="back_button_go_to_page">Go to page</string>
<string name="back_button_go_to_page_title">Select page</string>
<string name="pref_delete_removes_from_queue_title">Delete Removes From Queue</string>
<string name="pref_delete_removes_from_queue_sum">Automatically remove an episode from queue when it is deleted.</string>
<!-- Auto-Flattr dialog -->
<string name="auto_flattr_enable">Enable automatic flattring</string>