diff options
7 files changed, 60 insertions, 12 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java b/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java index 5acc25bee..d782d4ed5 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java @@ -15,6 +15,8 @@ import com.bumptech.glide.request.target.CustomViewTarget; import java.lang.ref.WeakReference; import com.bumptech.glide.request.transition.Transition; + +import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.glide.ApGlideSettings; @@ -23,6 +25,7 @@ public class CoverLoader { private String fallbackUri; private TextView txtvPlaceholder; private ImageView imgvCover; + private boolean textAndImageCombined; private MainActivity activity; public CoverLoader(MainActivity activity) { @@ -49,6 +52,19 @@ public class CoverLoader { return this; } + /** + * Set cover text and if it should be shown even if there is a cover image. + * + * @param placeholderView Cover text. + * @param textAndImageCombined Show cover text even if there is a cover image? + */ + @NonNull + public CoverLoader withPlaceholderView(@NonNull TextView placeholderView, boolean textAndImageCombined) { + this.txtvPlaceholder = placeholderView; + this.textAndImageCombined = textAndImageCombined; + return this; + } + public void load() { RequestOptions options = new RequestOptions() .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) @@ -65,20 +81,22 @@ public class CoverLoader { .apply(options)); } - builder.into(new CoverTarget(txtvPlaceholder, imgvCover)); + builder.into(new CoverTarget(txtvPlaceholder, imgvCover, textAndImageCombined)); } static class CoverTarget extends CustomViewTarget<ImageView, Drawable> { private final WeakReference<TextView> placeholder; private final WeakReference<ImageView> cover; + private boolean textAndImageCombined; - public CoverTarget(TextView txtvPlaceholder, ImageView imgvCover) { + public CoverTarget(TextView txtvPlaceholder, ImageView imgvCover, boolean textAndImageCombined) { super(imgvCover); if (txtvPlaceholder != null) { txtvPlaceholder.setVisibility(View.VISIBLE); } placeholder = new WeakReference<>(txtvPlaceholder); cover = new WeakReference<>(imgvCover); + this.textAndImageCombined = textAndImageCombined; } @Override @@ -90,7 +108,12 @@ public class CoverLoader { public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { TextView txtvPlaceholder = placeholder.get(); if (txtvPlaceholder != null) { - txtvPlaceholder.setVisibility(View.INVISIBLE); + if (textAndImageCombined) { + int bgColor = txtvPlaceholder.getContext().getResources().getColor(R.color.feed_text_bg); + txtvPlaceholder.setBackgroundColor(bgColor); + } else { + txtvPlaceholder.setVisibility(View.INVISIBLE); + } } ImageView ivCover = cover.get(); ivCover.setImageDrawable(resource); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java index fdda526ff..8c294a9c9 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -22,6 +22,7 @@ import java.util.Locale; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.LocalFeedUpdater; import de.danoeh.antennapod.fragment.AddFeedFragment; import de.danoeh.antennapod.fragment.FeedItemlistFragment; import jp.shts.android.library.TriangleLabelView; @@ -107,9 +108,11 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI holder.count.setVisibility(View.GONE); } + boolean textAndImageCombined = feed.isLocalFeed() + && LocalFeedUpdater.getDefaultIconUrl(convertView.getContext()).equals(feed.getImageUrl()); new CoverLoader(mainActivityRef.get()) .withUri(feed.getImageLocation()) - .withPlaceholderView(holder.feedTitle) + .withPlaceholderView(holder.feedTitle, textAndImageCombined) .withCoverView(holder.imageView) .load(); diff --git a/app/src/main/res/layout/subscription_item.xml b/app/src/main/res/layout/subscription_item.xml index 29f94a7e6..e0c821868 100644 --- a/app/src/main/res/layout/subscription_item.xml +++ b/app/src/main/res/layout/subscription_item.xml @@ -21,7 +21,7 @@ android:id="@+id/txtvTitle" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/light_gray" + android:background="@color/non_square_icon_background" android:layout_alignLeft="@+id/imgvCover" android:layout_alignRight="@+id/imgvCover" android:layout_alignStart="@+id/imgvCover" @@ -30,6 +30,7 @@ android:layout_alignBottom="@+id/imgvCover" android:ellipsize="end" android:gravity="center" + android:textColor="?android:attr/textColorPrimary" tools:text="@string/app_name" /> <jp.shts.android.library.TriangleLabelView diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java index f9863b0a6..706aed2c3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java @@ -1,16 +1,14 @@ package de.danoeh.antennapod.core.feed; +import android.content.ContentResolver; import android.content.Context; import android.media.MediaMetadataRetriever; import android.net.Uri; import android.text.TextUtils; -import android.util.Log; + import androidx.documentfile.provider.DocumentFile; -import de.danoeh.antennapod.core.service.download.DownloadStatus; -import de.danoeh.antennapod.core.storage.DBTasks; -import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.util.DateUtils; -import de.danoeh.antennapod.core.util.DownloadError; + +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Arrays; @@ -21,6 +19,12 @@ import java.util.List; import java.util.Set; import java.util.UUID; +import de.danoeh.antennapod.core.R; +import de.danoeh.antennapod.core.service.download.DownloadStatus; +import de.danoeh.antennapod.core.storage.DBTasks; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.core.util.DownloadError; + public class LocalFeedUpdater { public static void updateFeed(Feed feed, Context context) { @@ -81,6 +85,10 @@ public class LocalFeedUpdater { break; } } + if (StringUtils.isBlank(feed.getImageUrl())) { + // set default feed image + feed.setImageUrl(getDefaultIconUrl(context)); + } // update items, delete items without existing file; // only delete items if the folder contains at least one element to avoid accidentally @@ -89,6 +97,16 @@ public class LocalFeedUpdater { DBTasks.updateFeed(context, feed, removeUnlistedItems); } + /** + * Returns the URL of the default icon for a local feed. The URL refers to an app resource file. + */ + public static String getDefaultIconUrl(Context context) { + String resourceEntryName = context.getResources().getResourceEntryName(R.raw.local_feed_default_icon); + return ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + + context.getPackageName() + "/raw/" + + resourceEntryName; + } + private static FeedItem feedContainsFile(Feed feed, String filename) { List<FeedItem> items = feed.getItems(); for (FeedItem i : items) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java index 963ce7596..8c80e9151 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApOkHttpUrlLoader.java @@ -83,7 +83,9 @@ class ApOkHttpUrlLoader implements ModelLoader<String, InputStream> { @Override public boolean handles(@NonNull String model) { // Leave content URIs to Glide's default loaders - return !TextUtils.isEmpty(model) && !model.startsWith(ContentResolver.SCHEME_CONTENT); + return !TextUtils.isEmpty(model) + && !model.startsWith(ContentResolver.SCHEME_CONTENT) + && !model.startsWith(ContentResolver.SCHEME_ANDROID_RESOURCE); } private static class NetworkAllowanceInterceptor implements Interceptor { diff --git a/core/src/main/res/raw/local_feed_default_icon.png b/core/src/main/res/raw/local_feed_default_icon.png Binary files differnew file mode 100644 index 000000000..c1b24a729 --- /dev/null +++ b/core/src/main/res/raw/local_feed_default_icon.png diff --git a/core/src/main/res/values/colors.xml b/core/src/main/res/values/colors.xml index a86d61eba..b9c5eca0d 100644 --- a/core/src/main/res/values/colors.xml +++ b/core/src/main/res/values/colors.xml @@ -10,6 +10,7 @@ <color name="download_failed_red">#B00020</color> <color name="image_readability_tint">#80000000</color> <color name="feed_image_bg">#50000000</color> + <color name="feed_text_bg">#ccbfbfbf</color> <!-- Theme colors --> <color name="background_light">#FFFFFF</color> |