summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorJonas Burian <jonas.burian@protonmail.com>2021-01-23 13:03:53 +0100
committerGitHub <noreply@github.com>2021-01-23 13:03:53 +0100
commit35d010caa23124d12d8487fefadf6ad64beb50dc (patch)
tree458e380fc53c4fd81f17da47408e53249eaf0036 /core/src/main
parent12a98e53701bf48e6d8232e9e8926abc4539b372 (diff)
downloadAntennaPod-35d010caa23124d12d8487fefadf6ad64beb50dc.zip
Use podcast image as fallback when episode image returns 404 (#4861)
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/util/ImageResourceUtils.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java20
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java17
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java14
4 files changed, 48 insertions, 8 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/util/ImageResourceUtils.java b/core/src/main/java/de/danoeh/antennapod/core/feed/util/ImageResourceUtils.java
index 674663a6d..22ab03c6d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/util/ImageResourceUtils.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/util/ImageResourceUtils.java
@@ -14,6 +14,7 @@ public final class ImageResourceUtils {
}
public static String getImageLocation(ImageResource resource) {
+
if (UserPreferences.getUseEpisodeCoverSetting()) {
return resource.getImageLocation();
} else {
@@ -21,6 +22,10 @@ public final class ImageResourceUtils {
}
}
+ public static String getFallbackImageLocation(ImageResource resource) {
+ return getShowImageLocation(resource);
+ }
+
private static String getShowImageLocation(ImageResource resource) {
if (resource instanceof FeedItem) {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java
index 65bd8afe4..2ed887fbb 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java
@@ -118,12 +118,12 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
}
if (media != null) {
+ Bitmap icon;
+ int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer);
views.setOnClickPendingIntent(R.id.imgvCover, startMediaPlayer);
try {
- Bitmap icon;
- int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
icon = Glide.with(PlayerWidgetJobService.this)
.asBitmap()
.load(ImageResourceUtils.getImageLocation(media))
@@ -131,9 +131,19 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
.submit(iconSize, iconSize)
.get(500, TimeUnit.MILLISECONDS);
views.setImageViewBitmap(R.id.imgvCover, icon);
- } catch (Throwable tr) {
- Log.e(TAG, "Error loading the media icon for the widget", tr);
- views.setImageViewResource(R.id.imgvCover, R.mipmap.ic_launcher_round);
+ } catch (Throwable tr1) {
+ try {
+ icon = Glide.with(PlayerWidgetJobService.this)
+ .asBitmap()
+ .load(ImageResourceUtils.getFallbackImageLocation(media))
+ .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
+ .submit(iconSize, iconSize)
+ .get(500, TimeUnit.MILLISECONDS);
+ views.setImageViewBitmap(R.id.imgvCover, icon);
+ } catch (Throwable tr2) {
+ Log.e(TAG, "Error loading the media icon for the widget", tr2);
+ views.setImageViewResource(R.id.imgvCover, R.mipmap.ic_launcher_round);
+ }
}
views.setTextViewText(R.id.txtvTitle, media.getEpisodeTitle());
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index c1500d78b..4e26f12e5 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -1307,17 +1307,28 @@ public class PlaybackService extends MediaBrowserServiceCompat {
if (!TextUtils.isEmpty(imageLocation)) {
if (UserPreferences.setLockscreenBackground()) {
+ Bitmap art;
builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, imageLocation);
try {
- Bitmap art = Glide.with(this)
+ art = Glide.with(this)
.asBitmap()
.load(imageLocation)
.apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
.submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get();
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art);
- } catch (Throwable tr) {
- Log.e(TAG, Log.getStackTraceString(tr));
+ } catch (Throwable tr1) {
+ try {
+ art = Glide.with(this)
+ .asBitmap()
+ .load(ImageResourceUtils.getFallbackImageLocation(p))
+ .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
+ .submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
+ .get();
+ builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art);
+ } catch (Throwable tr2) {
+ Log.e(TAG, Log.getStackTraceString(tr2));
+ }
}
} else if (isCasting) {
// In the absence of metadata art, the controller dialog takes care of creating it.
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java
index 9d249620d..b4c38d1c3 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java
@@ -29,6 +29,8 @@ import de.danoeh.antennapod.core.util.TimeSpeedConverter;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
import de.danoeh.antennapod.core.util.playback.Playable;
import java.util.ArrayList;
+import java.util.concurrent.ExecutionException;
+
import org.apache.commons.lang3.ArrayUtils;
public class PlaybackServiceNotificationBuilder {
@@ -78,6 +80,18 @@ public class PlaybackServiceNotificationBuilder {
.apply(new RequestOptions().centerCrop())
.submit(iconSize, iconSize)
.get();
+ } catch (ExecutionException e) {
+ try {
+ icon = Glide.with(context)
+ .asBitmap()
+ .load(ImageResourceUtils.getFallbackImageLocation(playable))
+ .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
+ .apply(new RequestOptions().centerCrop())
+ .submit(iconSize, iconSize)
+ .get();
+ } catch (Throwable tr) {
+ Log.e(TAG, "Error loading the media icon for the notification", tr);
+ }
} catch (Throwable tr) {
Log.e(TAG, "Error loading the media icon for the notification", tr);
}