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) {
|
||||
displayedChapterIndex = chapter;
|
||||
|
||||
RequestBuilder<Drawable> cover = Glide.with(this)
|
||||
.load(ImageResourceUtils.getImageLocation(media))
|
||||
.apply(new RequestOptions()
|
||||
RequestOptions options = new RequestOptions()
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.dontAnimate()
|
||||
.transforms(new FitCenter(),
|
||||
new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density))));
|
||||
new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density)));
|
||||
|
||||
RequestBuilder<Drawable> cover = Glide.with(this)
|
||||
.load(ImageResourceUtils.getImageLocation(media))
|
||||
.error(Glide.with(this)
|
||||
.load(ImageResourceUtils.getFallbackImageLocation(media))
|
||||
.apply(options))
|
||||
.apply(options);
|
||||
|
||||
if (chapter == -1 || TextUtils.isEmpty(media.getChapters().get(chapter).getImageUrl())) {
|
||||
cover.into(imgvCover);
|
||||
} else {
|
||||
Glide.with(this)
|
||||
.load(EmbeddedChapterImage.getModelFor(media, chapter))
|
||||
.apply(new RequestOptions()
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.dontAnimate()
|
||||
.transforms(new FitCenter(),
|
||||
new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density))))
|
||||
.apply(options)
|
||||
.thumbnail(cover)
|
||||
.error(cover)
|
||||
.into(imgvCover);
|
||||
|
|
|
@ -198,14 +198,19 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
feedName.setText(media.getFeedTitle());
|
||||
onPositionObserverUpdate();
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(ImageResourceUtils.getImageLocation(media))
|
||||
.apply(new RequestOptions()
|
||||
RequestOptions options = new RequestOptions()
|
||||
.placeholder(R.color.light_gray)
|
||||
.error(R.color.light_gray)
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.fitCenter()
|
||||
.dontAnimate())
|
||||
.dontAnimate();
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(ImageResourceUtils.getImageLocation(media))
|
||||
.error(Glide.with(getActivity())
|
||||
.load(ImageResourceUtils.getFallbackImageLocation(media))
|
||||
.apply(options))
|
||||
.apply(options)
|
||||
.into(imgvCover);
|
||||
|
||||
if (controller != null && controller.isPlayingVideoLocally()) {
|
||||
|
|
|
@ -291,14 +291,19 @@ public class ItemFragment extends Fragment {
|
|||
txtvPublished.setContentDescription(DateUtils.formatForAccessibility(getContext(), item.getPubDate()));
|
||||
}
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(ImageResourceUtils.getImageLocation(item))
|
||||
.apply(new RequestOptions()
|
||||
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())
|
||||
.dontAnimate();
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(ImageResourceUtils.getImageLocation(item))
|
||||
.error(Glide.with(getActivity())
|
||||
.load(ImageResourceUtils.getFallbackImageLocation(item))
|
||||
.apply(options))
|
||||
.apply(options)
|
||||
.into(imgvCover);
|
||||
updateButtons();
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,10 +131,20 @@ 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);
|
||||
} 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());
|
||||
views.setViewVisibility(R.id.txtvTitle, View.VISIBLE);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue