diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index f8507ba74..7c8943f36 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -337,7 +337,7 @@ public class NavListAdapter extends BaseAdapter } Glide.with(context) - .load(feed.getImageLocation()) + .load(feed.getImageUrl()) .apply(new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java index 72482b06d..23b5cfdce 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java @@ -66,7 +66,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter cover = Glide.with(this) - .load(ImageResourceUtils.getEpisodeImageLocation(media)) + .load(media.getImageLocation()) .error(Glide.with(this) .load(ImageResourceUtils.getFallbackImageLocation(media)) .apply(options)) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java index dd8a02893..25ab925eb 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java @@ -203,7 +203,7 @@ public class FeedInfoFragment extends Fragment implements Toolbar.OnMenuItemClic Log.d(TAG, "Author is " + feed.getAuthor()); Log.d(TAG, "URL is " + feed.getDownload_url()); Glide.with(getContext()) - .load(feed.getImageLocation()) + .load(feed.getImageUrl()) .apply(new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) @@ -212,7 +212,7 @@ public class FeedInfoFragment extends Fragment implements Toolbar.OnMenuItemClic .dontAnimate()) .into(imgvCover); Glide.with(getContext()) - .load(feed.getImageLocation()) + .load(feed.getImageUrl()) .apply(new RequestOptions() .placeholder(R.color.image_readability_tint) .error(R.color.image_readability_tint) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index 9e9bd2ca8..c86fdc070 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -521,7 +521,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem private void loadFeedImage() { Glide.with(getActivity()) - .load(feed.getImageLocation()) + .load(feed.getImageUrl()) .apply(new RequestOptions() .placeholder(R.color.image_readability_tint) .error(R.color.image_readability_tint) @@ -531,7 +531,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem .into(imgvBackground); Glide.with(getActivity()) - .load(feed.getImageLocation()) + .load(feed.getImageUrl()) .apply(new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index fa2c82623..48eae9583 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -304,7 +304,7 @@ public class ItemFragment extends Fragment { .dontAnimate(); Glide.with(getActivity()) - .load(ImageResourceUtils.getEpisodeImageLocation(item)) + .load(item.getImageLocation()) .error(Glide.with(getActivity()) .load(ImageResourceUtils.getFallbackImageLocation(item)) .apply(options)) diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java index 0510de968..8b46a781f 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java +++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java @@ -122,7 +122,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { if (coverHolder.getVisibility() == View.VISIBLE) { new CoverLoader(activity) .withUri(ImageResourceUtils.getEpisodeListImageLocation(item)) - .withFallbackUri(item.getFeed().getImageLocation()) + .withFallbackUri(item.getFeed().getImageUrl()) .withPlaceholderView(placeholder) .withCoverView(cover) .load(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/asynctask/ImageResource.java b/core/src/main/java/de/danoeh/antennapod/core/asynctask/ImageResource.java deleted file mode 100644 index b01e3f3ba..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/asynctask/ImageResource.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.danoeh.antennapod.core.asynctask; - -/** - * Classes that implement this interface provide access to an image resource that can - * be loaded by the Picasso library. - */ -public interface ImageResource { - - /** - * Returns the location of the image or null if no image is available. - *

- * The location can either be an URL or a local path - */ - String getImageLocation(); -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java index a3b66c951..51138e407 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import de.danoeh.antennapod.core.asynctask.ImageResource; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.SortOrder; @@ -19,7 +18,7 @@ import de.danoeh.antennapod.core.util.SortOrder; * * @author daniel */ -public class Feed extends FeedFile implements ImageResource { +public class Feed extends FeedFile { public static final int FEEDFILETYPE_FEED = 0; public static final String TYPE_RSS2 = "rss"; @@ -491,11 +490,6 @@ public class Feed extends FeedFile implements ImageResource { } } - @Override - public String getImageLocation() { - return imageUrl; - } - public int getPageNr() { return pageNr; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java index c35e17cdc..b2a89d452 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java @@ -17,7 +17,6 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; -import de.danoeh.antennapod.core.asynctask.ImageResource; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.ShownotesProvider; @@ -27,7 +26,7 @@ import de.danoeh.antennapod.core.util.ShownotesProvider; * * @author daniel */ -public class FeedItem extends FeedComponent implements ShownotesProvider, ImageResource, Serializable { +public class FeedItem extends FeedComponent implements ShownotesProvider, Serializable { /** tag that indicates this item is in the queue */ public static final String TAG_QUEUE = "Queue"; @@ -376,14 +375,13 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, ImageR }; } - @Override public String getImageLocation() { if (imageUrl != null) { return imageUrl; } else if (media != null && media.hasEmbeddedPicture()) { return FeedMedia.FILENAME_PREFIX_EMBEDDED_COVER + media.getLocalMediaUrl(); } else if (feed != null) { - return feed.getImageLocation(); + return feed.getImageUrl(); } else { return null; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java index 0af70061e..dfb0370fc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java @@ -175,8 +175,8 @@ public class FeedMedia extends FeedFile implements Playable { // getImageLocation() also loads embedded images, which we can not send to external devices if (item.getImageUrl() != null) { builder.setIconUri(Uri.parse(item.getImageUrl())); - } else if (item.getFeed() != null && item.getFeed().getImageLocation() != null) { - builder.setIconUri(Uri.parse(item.getFeed().getImageLocation())); + } else if (item.getFeed() != null && item.getFeed().getImageUrl() != null) { + builder.setIconUri(Uri.parse(item.getFeed().getImageUrl())); } } return new MediaBrowserCompat.MediaItem(builder.build(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE); 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 9d478b676..b0aee3d77 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 @@ -1,12 +1,15 @@ package de.danoeh.antennapod.core.feed.util; -import de.danoeh.antennapod.core.asynctask.ImageResource; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.util.playback.Playable; /** - * Utility class to use the appropriate image resource based on {@link UserPreferences} + * Utility class to use the appropriate image resource based on {@link UserPreferences}. */ public final class ImageResourceUtils { @@ -14,48 +17,50 @@ public final class ImageResourceUtils { } /** - * returns the image location, does prefer the episode cover if available. + * returns the image location, does prefer the episode cover if available and enabled in settings. */ - public static String getEpisodeImageLocation(ImageResource resource) { - return resource.getImageLocation(); + @Nullable + public static String getEpisodeListImageLocation(@NonNull Playable playable) { + if (UserPreferences.getUseEpisodeCoverSetting()) { + return playable.getImageLocation(); + } else { + return getFallbackImageLocation(playable); + } } - /** * returns the image location, does prefer the episode cover if available and enabled in settings. */ - public static String getEpisodeListImageLocation(ImageResource resource) { - + @Nullable + public static String getEpisodeListImageLocation(@NonNull FeedItem feedItem) { if (UserPreferences.getUseEpisodeCoverSetting()) { - return resource.getImageLocation(); + return feedItem.getImageLocation(); } else { - return getShowImageLocation(resource); + return getFallbackImageLocation(feedItem); } } - public static String getFallbackImageLocation(ImageResource resource) { - return getShowImageLocation(resource); - } - - private static String getShowImageLocation(ImageResource resource) { - - if (resource instanceof FeedItem) { - FeedItem item = (FeedItem) resource; - if (item.getFeed() != null) { - return item.getFeed().getImageLocation(); - } else { - return null; - } - } else if (resource instanceof FeedMedia) { - FeedMedia media = (FeedMedia) resource; + @Nullable + public static String getFallbackImageLocation(@NonNull Playable playable) { + if (playable instanceof FeedMedia) { + FeedMedia media = (FeedMedia) playable; FeedItem item = media.getItem(); if (item != null && item.getFeed() != null) { - return item.getFeed().getImageLocation(); + return item.getFeed().getImageUrl(); } else { return null; } } else { - return resource.getImageLocation(); + return playable.getImageLocation(); + } + } + + @Nullable + public static String getFallbackImageLocation(@NonNull FeedItem feedItem) { + if (feedItem.getFeed() != null) { + return feedItem.getFeed().getImageUrl(); + } else { + return null; } } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java index a172c40cb..799a68037 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java @@ -17,7 +17,6 @@ import com.bumptech.glide.request.RequestOptions; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedPreferences; -import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.PodDBAdapter; @@ -113,7 +112,7 @@ public class NewEpisodesNotification { try { return Glide.with(context) .asBitmap() - .load(ImageResourceUtils.getEpisodeListImageLocation(feed)) + .load(feed.getImageUrl()) .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY)) .apply(new RequestOptions().centerCrop()) .submit(iconSize, iconSize) 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 0c4e391a0..597d73b29 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 @@ -409,8 +409,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { .setTitle(feed.getTitle()) .setDescription(feed.getDescription()) .setSubtitle(feed.getCustomTitle()); - if (feed.getImageLocation() != null) { - builder.setIconUri(Uri.parse(feed.getImageLocation())); + if (feed.getImageUrl() != null) { + builder.setIconUri(Uri.parse(feed.getImageUrl())); } if (feed.getLink() != null) { builder.setMediaUri(Uri.parse(feed.getLink())); @@ -1306,7 +1306,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, p.getEpisodeTitle()); builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, p.getFeedTitle()); - String imageLocation = ImageResourceUtils.getEpisodeImageLocation(p); + String imageLocation = p.getImageLocation(); if (!TextUtils.isEmpty(imageLocation)) { if (UserPreferences.setLockscreenBackground()) { 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 b4b91178b..cbfc36266 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 @@ -75,7 +75,7 @@ public class PlaybackServiceNotificationBuilder { try { icon = Glide.with(context) .asBitmap() - .load(ImageResourceUtils.getEpisodeImageLocation(playable)) + .load(playable.getImageLocation()) .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY)) .apply(new RequestOptions().centerCrop()) .submit(iconSize, iconSize) diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java index e2ce86ceb..3e886d33f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java @@ -6,7 +6,6 @@ import android.os.Parcelable; import androidx.preference.PreferenceManager; import android.util.Log; import androidx.annotation.Nullable; -import de.danoeh.antennapod.core.asynctask.ImageResource; import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; @@ -19,8 +18,7 @@ import java.util.List; /** * Interface for objects that can be played by the PlaybackService. */ -public interface Playable extends Parcelable, - ShownotesProvider, ImageResource { +public interface Playable extends Parcelable, ShownotesProvider { public static final int INVALID_TIME = -1; /** @@ -177,6 +175,14 @@ public interface Playable extends Parcelable, void setChapters(List chapters); + /** + * Returns the location of the image or null if no image is available. + * This can be the feed item image URL, the local embedded media image path, the feed image URL, + * or the remote media image URL, depending on what's available. + */ + @Nullable + String getImageLocation(); + /** * Provides utility methods for Playable objects. */ diff --git a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java index 8521d5980..afbe6526b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java +++ b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java @@ -90,7 +90,7 @@ public abstract class WidgetUpdater { try { icon = Glide.with(context) .asBitmap() - .load(ImageResourceUtils.getEpisodeImageLocation(widgetState.media)) + .load(widgetState.media.getImageLocation()) .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY)) .submit(iconSize, iconSize) .get(500, TimeUnit.MILLISECONDS);