diff options
Diffstat (limited to 'app')
4 files changed, 64 insertions, 9 deletions
diff --git a/app/build.gradle b/app/build.gradle index f02372df9..6754614a0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -133,6 +133,7 @@ dependencies { implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01' implementation "androidx.work:work-runtime:$workManagerVersion" implementation "com.google.android.material:material:$googleMaterialVersion" + implementation 'androidx.palette:palette:1.0.0' implementation "org.apache.commons:commons-lang3:$commonslangVersion" implementation "commons-io:commons-io:$commonsioVersion" 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 5d7593564..34726e248 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/CoverLoader.java @@ -3,6 +3,9 @@ package de.danoeh.antennapod.adapter; import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.graphics.ColorUtils; +import androidx.palette.graphics.Palette; + import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -19,6 +22,9 @@ 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; +import de.danoeh.antennapod.core.glide.PaletteBitmap; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.ui.common.ThemeUtils; public class CoverLoader { private int resource = 0; @@ -77,7 +83,7 @@ public class CoverLoader { if (resource != 0) { Glide.with(activity).clear(coverTarget); imgvCover.setImageResource(resource); - CoverTarget.setPlaceholderVisibility(txtvPlaceholder, textAndImageCombined); + CoverTarget.setPlaceholderVisibility(txtvPlaceholder, textAndImageCombined, null); return; } @@ -86,12 +92,14 @@ public class CoverLoader { .fitCenter() .dontAnimate(); - RequestBuilder<Drawable> builder = Glide.with(activity) + RequestBuilder<PaletteBitmap> builder = Glide.with(activity) + .as(PaletteBitmap.class) .load(uri) .apply(options); if (fallbackUri != null && txtvPlaceholder != null && imgvCover != null) { builder = builder.error(Glide.with(activity) + .as(PaletteBitmap.class) .load(fallbackUri) .apply(options)); } @@ -99,7 +107,7 @@ public class CoverLoader { builder.into(coverTarget); } - static class CoverTarget extends CustomViewTarget<ImageView, Drawable> { + static class CoverTarget extends CustomViewTarget<ImageView, PaletteBitmap> { private final WeakReference<TextView> placeholder; private final WeakReference<ImageView> cover; private boolean textAndImageCombined; @@ -120,23 +128,38 @@ public class CoverLoader { } @Override - public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { - setPlaceholderVisibility(placeholder.get(), textAndImageCombined); + public void onResourceReady(@NonNull PaletteBitmap resource, + @Nullable Transition<? super PaletteBitmap> transition) { ImageView ivCover = cover.get(); - ivCover.setImageDrawable(resource); + ivCover.setImageBitmap(resource.bitmap); + setPlaceholderVisibility(placeholder.get(), textAndImageCombined, resource.palette); } @Override protected void onResourceCleared(@Nullable Drawable placeholder) { ImageView ivCover = cover.get(); ivCover.setImageDrawable(placeholder); + setPlaceholderVisibility(this.placeholder.get(), textAndImageCombined, null); } - static void setPlaceholderVisibility(TextView placeholder, boolean textAndImageCombined) { + static void setPlaceholderVisibility(TextView placeholder, boolean textAndImageCombined, Palette palette) { + boolean showTitle = UserPreferences.shouldShowSubscriptionTitle(); if (placeholder != null) { - if (textAndImageCombined) { + if (textAndImageCombined || showTitle) { int bgColor = placeholder.getContext().getResources().getColor(R.color.feed_text_bg); - placeholder.setBackgroundColor(bgColor); + if (palette == null || !showTitle) { + placeholder.setBackgroundColor(bgColor); + placeholder.setTextColor(ThemeUtils.getColorFromAttr(placeholder.getContext(), + android.R.attr.textColorPrimary)); + return; + } + int dominantColor = palette.getDominantColor(bgColor); + int textColor = placeholder.getContext().getResources().getColor(R.color.white); + if (ColorUtils.calculateLuminance(dominantColor) > 0.5) { + textColor = placeholder.getContext().getResources().getColor(R.color.black); + } + placeholder.setTextColor(textColor); + placeholder.setBackgroundColor(dominantColor); } else { placeholder.setVisibility(View.INVISIBLE); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java index b637eb31d..4bf787db5 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java @@ -13,6 +13,7 @@ import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -31,6 +32,7 @@ import java.util.Locale; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.feed.LocalFeedUpdater; +import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.NavDrawerData; import de.danoeh.antennapod.fragment.FeedItemlistFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; @@ -42,6 +44,8 @@ import jp.shts.android.library.TriangleLabelView; */ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<SubscriptionsRecyclerAdapter.SubscriptionViewHolder> implements View.OnCreateContextMenuListener { + private static final int COVER_WITH_TITLE = 1; + private final WeakReference<MainActivity> mainActivityRef; private List<NavDrawerData.DrawerItem> listItems; private Feed selectedFeed = null; @@ -66,6 +70,23 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription @Override public SubscriptionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(mainActivityRef.get()).inflate(R.layout.subscription_item, parent, false); + TextView feedTitle = itemView.findViewById(R.id.txtvTitle); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) feedTitle.getLayoutParams(); + int topAndBottomItemId = R.id.imgvCover; + int belowItemId = 0; + + if (viewType == COVER_WITH_TITLE) { + topAndBottomItemId = 0; + belowItemId = R.id.imgvCover; + feedTitle.setBackgroundColor(feedTitle.getContext().getResources().getColor(R.color.feed_text_bg)); + int padding = (int) convertDpToPixel(feedTitle.getContext(), 6); + feedTitle.setPadding(padding, padding, padding, padding); + } + params.addRule(RelativeLayout.BELOW, belowItemId); + params.addRule(RelativeLayout.ALIGN_TOP, topAndBottomItemId); + params.addRule(RelativeLayout.ALIGN_BOTTOM, topAndBottomItemId); + feedTitle.setLayoutParams(params); + feedTitle.setSingleLine(viewType == COVER_WITH_TITLE); return new SubscriptionViewHolder(itemView); } @@ -173,6 +194,11 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription } } + @Override + public int getItemViewType(int position) { + return UserPreferences.shouldShowSubscriptionTitle() ? COVER_WITH_TITLE : 0; + } + public class SubscriptionViewHolder extends RecyclerView.ViewHolder { private final TextView feedTitle; private final ImageView imageView; diff --git a/app/src/main/res/xml/preferences_user_interface.xml b/app/src/main/res/xml/preferences_user_interface.xml index 0b2707a18..59e7092a1 100644 --- a/app/src/main/res/xml/preferences_user_interface.xml +++ b/app/src/main/res/xml/preferences_user_interface.xml @@ -44,6 +44,11 @@ android:title="@string/pref_filter_feed_title" android:key="prefSubscriptionsFilter" android:summary="@string/pref_filter_feed_sum" /> + <SwitchPreferenceCompat + android:title="@string/pref_show_subscription_title" + android:key="prefSubscriptionTitle" + android:summary="@string/pref_show_subscription_title_summary" + android:defaultValue="false" /> </PreferenceCategory> <PreferenceCategory android:title="@string/external_elements"> <SwitchPreferenceCompat |