Warn when local folder is empty instead of silently ignoring (#6366)

This commit is contained in:
ByteHamster 2023-03-06 21:41:05 +01:00 committed by GitHub
parent 24d1a06662
commit 95b97b6f49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -77,7 +77,7 @@ public class LocalFeedUpdater {
@VisibleForTesting
static void tryUpdateFeed(Feed feed, Context context, Uri folderUri,
UpdaterProgressListener updaterProgressListener) {
UpdaterProgressListener updaterProgressListener) throws IOException {
if (feed.getItems() == null) {
feed.setItems(new ArrayList<>());
}
@ -128,11 +128,10 @@ public class LocalFeedUpdater {
feed.setDescription(context.getString(R.string.local_feed_description));
feed.setAuthor(context.getString(R.string.local_folder));
// update items, delete items without existing file;
// only delete items if the folder contains at least one element to avoid accidentally
// deleting played state or position in case the folder is temporarily unavailable.
boolean removeUnlistedItems = (newItems.size() >= 1);
DBTasks.updateFeed(context, feed, removeUnlistedItems);
if (newItems.isEmpty()) {
throw new IOException("Empty folder. Make sure that the folder is accessible and contains media files.");
}
DBTasks.updateFeed(context, feed, true);
}
/**

View File

@ -26,6 +26,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowMediaMetadataRetriever;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -262,7 +263,11 @@ public class LocalFeedUpdaterTest {
// call method to test
Feed feed = new Feed(FEED_URL, null);
LocalFeedUpdater.tryUpdateFeed(feed, context, null, null);
try {
LocalFeedUpdater.tryUpdateFeed(feed, context, null, null);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}