diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-01-15 11:23:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-15 11:23:44 +0100 |
commit | cf477de365e44664fe4dd224c6c53cd8af680cc4 (patch) | |
tree | 48426e30285131a50995cbff0775bf597c6a8d0e /app | |
parent | 6d50be18dbe310c0665ef7179929420408856841 (diff) | |
parent | dfcb16d77b5e9b7ea3f5d19e528c9f4950eb4520 (diff) | |
download | AntennaPod-cf477de365e44664fe4dd224c6c53cd8af680cc4.zip |
Merge pull request #2921 from qkolj/delete-episodes
Add delete option to episode's context menu
Diffstat (limited to 'app')
7 files changed, 85 insertions, 1 deletions
diff --git a/app/build.gradle b/app/build.gradle index 7ba2ef441..104fd247f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -186,6 +186,7 @@ dependencies { implementation 'com.github.mfietz:fyydlin:v0.4.1' implementation 'com.github.ByteHamster:SearchPreference:v1.0.8' + implementation "org.awaitility:awaitility:$awaitilityVersion" androidTestImplementation "com.jayway.android.robotium:robotium-solo:$robotiumSoloVersion" androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java index 427cc8ddd..b80482c53 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java @@ -1,7 +1,9 @@ package de.test.antennapod.storage; import android.content.Context; +import android.content.SharedPreferences; import android.database.Cursor; +import android.preference.PreferenceManager; import android.test.InstrumentationTestCase; import android.util.Log; @@ -18,10 +20,13 @@ import java.util.concurrent.TimeoutException; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +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.storage.PodDBAdapter; +import org.awaitility.Awaitility; + /** * Test class for DBWriter */ @@ -55,6 +60,12 @@ public class DBWriterTest extends InstrumentationTestCase { PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); adapter.close(); + + Context context = getInstrumentation().getTargetContext(); + SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit(); + prefEdit.putBoolean(UserPreferences.PREF_DELETE_REMOVES_FROM_QUEUE, true).commit(); + + UserPreferences.init(context); } public void testSetFeedMediaPlaybackInformation() @@ -121,6 +132,47 @@ public class DBWriterTest extends InstrumentationTestCase { assertNull(media.getFile_url()); } + public void testDeleteFeedMediaOfItemRemoveFromQueue() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + assertTrue(UserPreferences.shouldDeleteRemoveFromQueue()); + + File dest = new File(getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER), "testFile"); + + assertTrue(dest.createNewFile()); + + Feed feed = new Feed("url", null, "title"); + List<FeedItem> items = new ArrayList<>(); + List<FeedItem> queue = new ArrayList<>(); + feed.setItems(items); + FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.UNPLAYED, feed); + + FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", dest.getAbsolutePath(), "download_url", true, null, 0, 0); + item.setMedia(media); + + items.add(item); + queue.add(item); + + PodDBAdapter adapter = PodDBAdapter.getInstance(); + adapter.open(); + adapter.setCompleteFeed(feed); + adapter.setQueue(queue); + adapter.close(); + assertTrue(media.getId() != 0); + assertTrue(item.getId() != 0); + queue = DBReader.getQueue(); + assertTrue(queue.size() != 0); + + DBWriter.deleteFeedMediaOfItem(getInstrumentation().getTargetContext(), media.getId()); + Awaitility.await().until(() -> dest.exists() == false); + media = DBReader.getFeedMedia(media.getId()); + assertNotNull(media); + assertFalse(dest.exists()); + assertFalse(media.isDownloaded()); + assertNull(media.getFile_url()); + queue = DBReader.getQueue(); + assertTrue(queue.size() == 0); + } + public void testDeleteFeed() throws ExecutionException, InterruptedException, IOException, TimeoutException { File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER); assertNotNull(destFolder); diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java index f217ecffa..d37242f98 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java @@ -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())); diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index ffdfa9516..321b9c7bb 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -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; } diff --git a/app/src/main/res/menu/feeditemlist_context.xml b/app/src/main/res/menu/feeditemlist_context.xml index d3ec88bc7..1f4f09faa 100644 --- a/app/src/main/res/menu/feeditemlist_context.xml +++ b/app/src/main/res/menu/feeditemlist_context.xml @@ -24,6 +24,10 @@ android:id="@+id/remove_from_queue_item" android:menuCategory="container" android:title="@string/remove_from_queue_label" /> + <item + android:id="@+id/remove_item" + android:menuCategory="container" + android:title="@string/delete_label" /> <item android:id="@+id/add_to_favorites_item" diff --git a/app/src/main/res/menu/queue_context.xml b/app/src/main/res/menu/queue_context.xml index e93d808c1..c88620665 100644 --- a/app/src/main/res/menu/queue_context.xml +++ b/app/src/main/res/menu/queue_context.xml @@ -26,6 +26,10 @@ android:id="@+id/remove_from_queue_item" android:menuCategory="container" android:title="@string/remove_from_queue_label" /> + <item + android:id="@+id/remove_item" + android:menuCategory="container" + android:title="@string/delete_label" /> <item android:id="@+id/add_to_favorites_item" diff --git a/app/src/main/res/xml/preferences_storage.xml b/app/src/main/res/xml/preferences_storage.xml index fe48cc99c..989bb68d7 100644 --- a/app/src/main/res/xml/preferences_storage.xml +++ b/app/src/main/res/xml/preferences_storage.xml @@ -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 |