Local feeds: Use default cover image if source folder doesn't contain a file like folder.png
This commit is contained in:
parent
9d76676421
commit
3c5e1138ca
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue