Use podcast image as fallback when episode image returns 404 (#4861)
This commit is contained in:
parent
12a98e5370
commit
35d010caa2
|
@ -151,23 +151,25 @@ public class CoverFragment extends Fragment {
|
||||||
if (chapter != displayedChapterIndex) {
|
if (chapter != displayedChapterIndex) {
|
||||||
displayedChapterIndex = chapter;
|
displayedChapterIndex = chapter;
|
||||||
|
|
||||||
|
RequestOptions options = new RequestOptions()
|
||||||
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
|
.dontAnimate()
|
||||||
|
.transforms(new FitCenter(),
|
||||||
|
new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density)));
|
||||||
|
|
||||||
RequestBuilder<Drawable> cover = Glide.with(this)
|
RequestBuilder<Drawable> cover = Glide.with(this)
|
||||||
.load(ImageResourceUtils.getImageLocation(media))
|
.load(ImageResourceUtils.getImageLocation(media))
|
||||||
.apply(new RequestOptions()
|
.error(Glide.with(this)
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
.load(ImageResourceUtils.getFallbackImageLocation(media))
|
||||||
.dontAnimate()
|
.apply(options))
|
||||||
.transforms(new FitCenter(),
|
.apply(options);
|
||||||
new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density))));
|
|
||||||
if (chapter == -1 || TextUtils.isEmpty(media.getChapters().get(chapter).getImageUrl())) {
|
if (chapter == -1 || TextUtils.isEmpty(media.getChapters().get(chapter).getImageUrl())) {
|
||||||
cover.into(imgvCover);
|
cover.into(imgvCover);
|
||||||
} else {
|
} else {
|
||||||
Glide.with(this)
|
Glide.with(this)
|
||||||
.load(EmbeddedChapterImage.getModelFor(media, chapter))
|
.load(EmbeddedChapterImage.getModelFor(media, chapter))
|
||||||
.apply(new RequestOptions()
|
.apply(options)
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
|
||||||
.dontAnimate()
|
|
||||||
.transforms(new FitCenter(),
|
|
||||||
new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density))))
|
|
||||||
.thumbnail(cover)
|
.thumbnail(cover)
|
||||||
.error(cover)
|
.error(cover)
|
||||||
.into(imgvCover);
|
.into(imgvCover);
|
||||||
|
|
|
@ -198,14 +198,19 @@ public class ExternalPlayerFragment extends Fragment {
|
||||||
feedName.setText(media.getFeedTitle());
|
feedName.setText(media.getFeedTitle());
|
||||||
onPositionObserverUpdate();
|
onPositionObserverUpdate();
|
||||||
|
|
||||||
|
RequestOptions options = new RequestOptions()
|
||||||
|
.placeholder(R.color.light_gray)
|
||||||
|
.error(R.color.light_gray)
|
||||||
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
|
.fitCenter()
|
||||||
|
.dontAnimate();
|
||||||
|
|
||||||
Glide.with(getActivity())
|
Glide.with(getActivity())
|
||||||
.load(ImageResourceUtils.getImageLocation(media))
|
.load(ImageResourceUtils.getImageLocation(media))
|
||||||
.apply(new RequestOptions()
|
.error(Glide.with(getActivity())
|
||||||
.placeholder(R.color.light_gray)
|
.load(ImageResourceUtils.getFallbackImageLocation(media))
|
||||||
.error(R.color.light_gray)
|
.apply(options))
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
.apply(options)
|
||||||
.fitCenter()
|
|
||||||
.dontAnimate())
|
|
||||||
.into(imgvCover);
|
.into(imgvCover);
|
||||||
|
|
||||||
if (controller != null && controller.isPlayingVideoLocally()) {
|
if (controller != null && controller.isPlayingVideoLocally()) {
|
||||||
|
|
|
@ -291,14 +291,19 @@ public class ItemFragment extends Fragment {
|
||||||
txtvPublished.setContentDescription(DateUtils.formatForAccessibility(getContext(), item.getPubDate()));
|
txtvPublished.setContentDescription(DateUtils.formatForAccessibility(getContext(), item.getPubDate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestOptions options = new RequestOptions()
|
||||||
|
.error(R.color.light_gray)
|
||||||
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
|
.transforms(new FitCenter(),
|
||||||
|
new RoundedCorners((int) (4 * getResources().getDisplayMetrics().density)))
|
||||||
|
.dontAnimate();
|
||||||
|
|
||||||
Glide.with(getActivity())
|
Glide.with(getActivity())
|
||||||
.load(ImageResourceUtils.getImageLocation(item))
|
.load(ImageResourceUtils.getImageLocation(item))
|
||||||
.apply(new RequestOptions()
|
.error(Glide.with(getActivity())
|
||||||
.error(R.color.light_gray)
|
.load(ImageResourceUtils.getFallbackImageLocation(item))
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
.apply(options))
|
||||||
.transforms(new FitCenter(),
|
.apply(options)
|
||||||
new RoundedCorners((int) (4 * getResources().getDisplayMetrics().density)))
|
|
||||||
.dontAnimate())
|
|
||||||
.into(imgvCover);
|
.into(imgvCover);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ public final class ImageResourceUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getImageLocation(ImageResource resource) {
|
public static String getImageLocation(ImageResource resource) {
|
||||||
|
|
||||||
if (UserPreferences.getUseEpisodeCoverSetting()) {
|
if (UserPreferences.getUseEpisodeCoverSetting()) {
|
||||||
return resource.getImageLocation();
|
return resource.getImageLocation();
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,6 +22,10 @@ public final class ImageResourceUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFallbackImageLocation(ImageResource resource) {
|
||||||
|
return getShowImageLocation(resource);
|
||||||
|
}
|
||||||
|
|
||||||
private static String getShowImageLocation(ImageResource resource) {
|
private static String getShowImageLocation(ImageResource resource) {
|
||||||
|
|
||||||
if (resource instanceof FeedItem) {
|
if (resource instanceof FeedItem) {
|
||||||
|
|
|
@ -118,12 +118,12 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (media != null) {
|
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.layout_left, startMediaPlayer);
|
||||||
views.setOnClickPendingIntent(R.id.imgvCover, startMediaPlayer);
|
views.setOnClickPendingIntent(R.id.imgvCover, startMediaPlayer);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Bitmap icon;
|
|
||||||
int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
|
|
||||||
icon = Glide.with(PlayerWidgetJobService.this)
|
icon = Glide.with(PlayerWidgetJobService.this)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(ImageResourceUtils.getImageLocation(media))
|
.load(ImageResourceUtils.getImageLocation(media))
|
||||||
|
@ -131,9 +131,19 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
|
||||||
.submit(iconSize, iconSize)
|
.submit(iconSize, iconSize)
|
||||||
.get(500, TimeUnit.MILLISECONDS);
|
.get(500, TimeUnit.MILLISECONDS);
|
||||||
views.setImageViewBitmap(R.id.imgvCover, icon);
|
views.setImageViewBitmap(R.id.imgvCover, icon);
|
||||||
} catch (Throwable tr) {
|
} catch (Throwable tr1) {
|
||||||
Log.e(TAG, "Error loading the media icon for the widget", tr);
|
try {
|
||||||
views.setImageViewResource(R.id.imgvCover, R.mipmap.ic_launcher_round);
|
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());
|
views.setTextViewText(R.id.txtvTitle, media.getEpisodeTitle());
|
||||||
|
|
|
@ -1307,17 +1307,28 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(imageLocation)) {
|
if (!TextUtils.isEmpty(imageLocation)) {
|
||||||
if (UserPreferences.setLockscreenBackground()) {
|
if (UserPreferences.setLockscreenBackground()) {
|
||||||
|
Bitmap art;
|
||||||
builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, imageLocation);
|
builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, imageLocation);
|
||||||
try {
|
try {
|
||||||
Bitmap art = Glide.with(this)
|
art = Glide.with(this)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(imageLocation)
|
.load(imageLocation)
|
||||||
.apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
|
.apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
|
||||||
.submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
|
.submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
|
||||||
.get();
|
.get();
|
||||||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art);
|
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art);
|
||||||
} catch (Throwable tr) {
|
} catch (Throwable tr1) {
|
||||||
Log.e(TAG, Log.getStackTraceString(tr));
|
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) {
|
} else if (isCasting) {
|
||||||
// In the absence of metadata art, the controller dialog takes care of creating it.
|
// In the absence of metadata art, the controller dialog takes care of creating it.
|
||||||
|
|
|
@ -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.gui.NotificationUtils;
|
||||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
public class PlaybackServiceNotificationBuilder {
|
public class PlaybackServiceNotificationBuilder {
|
||||||
|
@ -78,6 +80,18 @@ public class PlaybackServiceNotificationBuilder {
|
||||||
.apply(new RequestOptions().centerCrop())
|
.apply(new RequestOptions().centerCrop())
|
||||||
.submit(iconSize, iconSize)
|
.submit(iconSize, iconSize)
|
||||||
.get();
|
.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) {
|
} catch (Throwable tr) {
|
||||||
Log.e(TAG, "Error loading the media icon for the notification", tr);
|
Log.e(TAG, "Error loading the media icon for the notification", tr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue