diff options
author | Herbert Reiter <46045854+damoasda@users.noreply.github.com> | 2020-08-08 14:37:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-08 14:37:51 +0200 |
commit | 3c5e1138ca1c616dd7add9d567442cc0d9a510ac (patch) | |
tree | 1cc39726b5ac18cfe82636fdc895a81da22023d8 /core | |
parent | 9d76676421f8f422fa7559f3ca34d9557bf7f8a0 (diff) | |
download | AntennaPod-3c5e1138ca1c616dd7add9d567442cc0d9a510ac.zip |
Local feeds: Use default cover image if source folder doesn't contain a file like folder.png
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java | 30 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java | 4 | ||||
-rw-r--r-- | core/src/main/res/raw/local_feed_default_icon.png | bin | 0 -> 1240 bytes | |||
-rw-r--r-- | core/src/main/res/values/colors.xml | 1 |
4 files changed, 28 insertions, 7 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java index f9863b0a6..706aed2c3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java @@ -1,16 +1,14 @@ package de.danoeh.antennapod.core.feed; +import android.content.ContentResolver; import android.content.Context; import android.media.MediaMetadataRetriever; import android.net.Uri; import android.text.TextUtils; -import android.util.Log; + import androidx.documentfile.provider.DocumentFile; -import de.danoeh.antennapod.core.service.download.DownloadStatus; -import de.danoeh.antennapod.core.storage.DBTasks; -import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.util.DateUtils; -import de.danoeh.antennapod.core.util.DownloadError; + +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Arrays; @@ -21,6 +19,12 @@ import java.util.List; import java.util.Set; import java.util.UUID; +import de.danoeh.antennapod.core.R; +import de.danoeh.antennapod.core.service.download.DownloadStatus; +import de.danoeh.antennapod.core.storage.DBTasks; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.core.util.DownloadError; + public class LocalFeedUpdater { public static void updateFeed(Feed feed, Context context) { @@ -81,6 +85,10 @@ public class LocalFeedUpdater { break; } } + if (StringUtils.isBlank(feed.getImageUrl())) { + // set default feed image + feed.setImageUrl(getDefaultIconUrl(context)); + } // update items, delete items without existing file; // only delete items if the folder contains at least one element to avoid accidentally @@ -89,6 +97,16 @@ public class LocalFeedUpdater { DBTasks.updateFeed(context, feed, removeUnlistedItems); } + /** + * Returns the URL of the default icon for a local feed. The URL refers to an app resource file. + */ + public static String getDefaultIconUrl(Context context) { + String resourceEntryName = context.getResources().getResourceEntryName(R.raw.local_feed_default_icon); + return ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + + context.getPackageName() + "/raw/" + + resourceEntryName; + } + private static FeedItem feedContainsFile(Feed feed, String filename) { List<FeedItem> items = feed.getItems(); for (FeedItem i : items) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java index 963ce7596..8c80e9151 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java @@ -83,7 +83,9 @@ class ApOkHttpUrlLoader implements ModelLoader<String, InputStream> { @Override public boolean handles(@NonNull String model) { // Leave content URIs to Glide's default loaders - return !TextUtils.isEmpty(model) && !model.startsWith(ContentResolver.SCHEME_CONTENT); + return !TextUtils.isEmpty(model) + && !model.startsWith(ContentResolver.SCHEME_CONTENT) + && !model.startsWith(ContentResolver.SCHEME_ANDROID_RESOURCE); } private static class NetworkAllowanceInterceptor implements Interceptor { diff --git a/core/src/main/res/raw/local_feed_default_icon.png b/core/src/main/res/raw/local_feed_default_icon.png Binary files differnew file mode 100644 index 000000000..c1b24a729 --- /dev/null +++ b/core/src/main/res/raw/local_feed_default_icon.png diff --git a/core/src/main/res/values/colors.xml b/core/src/main/res/values/colors.xml index a86d61eba..b9c5eca0d 100644 --- a/core/src/main/res/values/colors.xml +++ b/core/src/main/res/values/colors.xml @@ -10,6 +10,7 @@ <color name="download_failed_red">#B00020</color> <color name="image_readability_tint">#80000000</color> <color name="feed_image_bg">#50000000</color> + <color name="feed_text_bg">#ccbfbfbf</color> <!-- Theme colors --> <color name="background_light">#FFFFFF</color> |