Remove interface ImageResource (#4911)

This commit is contained in:
Herbert Reiter 2021-02-24 15:44:40 +01:00 committed by GitHub
parent bbbf9cdf23
commit 1cd680a2af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 62 additions and 75 deletions

View File

@ -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)

View File

@ -66,7 +66,7 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter<Recycle
StatisticsHolder holder = (StatisticsHolder) h;
StatisticsItem statsItem = statisticsData.get(position - 1);
Glide.with(context)
.load(statsItem.feed.getImageLocation())
.load(statsItem.feed.getImageUrl())
.apply(new RequestOptions()
.placeholder(R.color.light_gray)
.error(R.color.light_gray)

View File

@ -108,7 +108,7 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
boolean textAndImageCombined = feed.isLocalFeed()
&& LocalFeedUpdater.getDefaultIconUrl(convertView.getContext()).equals(feed.getImageUrl());
new CoverLoader(mainActivityRef.get())
.withUri(feed.getImageLocation())
.withUri(feed.getImageUrl())
.withPlaceholderView(holder.feedTitle, textAndImageCombined)
.withCoverView(holder.imageView)
.load();

View File

@ -158,7 +158,7 @@ public class CoverFragment extends Fragment {
new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density)));
RequestBuilder<Drawable> cover = Glide.with(this)
.load(ImageResourceUtils.getEpisodeImageLocation(media))
.load(media.getImageLocation())
.error(Glide.with(this)
.load(ImageResourceUtils.getFallbackImageLocation(media))
.apply(options))

View File

@ -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)

View File

@ -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)

View File

@ -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))

View File

@ -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();

View File

@ -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.
* <p/>
* The location can either be an URL or a local path
*/
String getImageLocation();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}
}
}

View File

@ -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)

View File

@ -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()) {

View File

@ -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)

View File

@ -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<Chapter> 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.
*/

View File

@ -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);