Merge pull request #2921 from qkolj/delete-episodes
Add delete option to episode's context menu
This commit is contained in:
commit
cf477de365
|
@ -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'
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
@ -311,6 +312,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);
|
||||
}
|
||||
|
|
|
@ -74,13 +74,7 @@ public class DBWriter {
|
|||
private DBWriter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a downloaded FeedMedia file from the storage device.
|
||||
*
|
||||
* @param context A context that is used for opening a database connection.
|
||||
* @param mediaId ID of the FeedMedia object whose downloaded file should be deleted.
|
||||
*/
|
||||
public static Future<?> deleteFeedMediaOfItem(final Context context,
|
||||
private static Future<?> doDeleteFeedMediaOfItem(final Context context,
|
||||
final long mediaId) {
|
||||
return dbExec.submit(() -> {
|
||||
final FeedMedia media = DBReader.getFeedMedia(mediaId);
|
||||
|
@ -136,6 +130,21 @@ public class DBWriter {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a downloaded FeedMedia file from the storage device.
|
||||
*
|
||||
* @param context A context that is used for opening a database connection.
|
||||
* @param mediaId ID of the FeedMedia object whose downloaded file should be deleted.
|
||||
*/
|
||||
public static Future<?> deleteFeedMediaOfItem(final Context context,
|
||||
final long mediaId) {
|
||||
Future res = doDeleteFeedMediaOfItem(context, mediaId);
|
||||
if (UserPreferences.shouldDeleteRemoveFromQueue()) {
|
||||
DBWriter.removeQueueItem(context, DBReader.getFeedMedia(mediaId).getItem(), false);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a Feed and all downloaded files of its components like images and downloaded episodes.
|
||||
*
|
||||
|
|
|
@ -482,6 +482,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 the queue when it is deleted.</string>
|
||||
|
||||
<!-- Auto-Flattr dialog -->
|
||||
<string name="auto_flattr_enable">Enable automatic flattring</string>
|
||||
|
|
Loading…
Reference in New Issue