diff options
Diffstat (limited to 'core')
7 files changed, 107 insertions, 0 deletions
diff --git a/core/build.gradle b/core/build.gradle index b3954c879..32899cb5d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -42,6 +42,7 @@ dependencies { implementation "androidx.preference:preference:$preferenceVersion" 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/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java index 9b06d2138..797addcc1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.glide; import android.annotation.SuppressLint; import android.content.Context; +import android.graphics.Bitmap; import android.util.Log; import androidx.annotation.NonNull; @@ -45,5 +46,6 @@ public class ApGlideModule extends AppGlideModule { registry.append(String.class, InputStream.class, new NoHttpStringLoader.StreamFactory()); registry.append(EmbeddedChapterImage.class, ByteBuffer.class, new ChapterImageModelLoader.Factory()); + registry.register(Bitmap.class, PaletteBitmap.class, new PaletteBitmapTranscoder()); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmap.java b/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmap.java new file mode 100644 index 000000000..59ecd3d0d --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmap.java @@ -0,0 +1,20 @@ +/* + * Source: https://github.com/bumptech/glide/wiki/Custom-targets#palette-example + */ + +package de.danoeh.antennapod.core.glide; + +import android.graphics.Bitmap; + +import androidx.annotation.NonNull; +import androidx.palette.graphics.Palette; + +public class PaletteBitmap { + public final Palette palette; + public final Bitmap bitmap; + + public PaletteBitmap(@NonNull Bitmap bitmap, Palette palette) { + this.bitmap = bitmap; + this.palette = palette; + } +}
\ No newline at end of file diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmapResource.java b/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmapResource.java new file mode 100644 index 000000000..fef0bccd3 --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmapResource.java @@ -0,0 +1,40 @@ +/* + * Source: https://github.com/bumptech/glide/wiki/Custom-targets#palette-example + */ + +package de.danoeh.antennapod.core.glide; + +import androidx.annotation.NonNull; + +import com.bumptech.glide.load.engine.Resource; +import com.bumptech.glide.util.Util; + +public class PaletteBitmapResource implements Resource<PaletteBitmap> { + private final PaletteBitmap paletteBitmap; + + public PaletteBitmapResource(@NonNull PaletteBitmap paletteBitmap) { + this.paletteBitmap = paletteBitmap; + } + + @NonNull + @Override + public Class<PaletteBitmap> getResourceClass() { + return PaletteBitmap.class; + } + + @NonNull + @Override + public PaletteBitmap get() { + return paletteBitmap; + } + + @Override + public int getSize() { + return Util.getBitmapByteSize(paletteBitmap.bitmap); + } + + @Override + public void recycle() { + paletteBitmap.bitmap.recycle(); + } +}
\ No newline at end of file diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmapTranscoder.java b/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmapTranscoder.java new file mode 100644 index 000000000..a6a606cb8 --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/PaletteBitmapTranscoder.java @@ -0,0 +1,32 @@ +/* + * Source: https://github.com/bumptech/glide/wiki/Custom-targets#palette-example + */ + +package de.danoeh.antennapod.core.glide; + +import android.graphics.Bitmap; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.palette.graphics.Palette; + +import com.bumptech.glide.load.Options; +import com.bumptech.glide.load.engine.Resource; +import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; + +import de.danoeh.antennapod.core.preferences.UserPreferences; + +public class PaletteBitmapTranscoder implements ResourceTranscoder<Bitmap, PaletteBitmap> { + + @Nullable + @Override + public Resource<PaletteBitmap> transcode(@NonNull Resource<Bitmap> toTranscode, @NonNull Options options) { + Bitmap bitmap = toTranscode.get(); + Palette palette = null; + if (UserPreferences.shouldShowSubscriptionTitle()) { + palette = new Palette.Builder(bitmap).generate(); + } + PaletteBitmap result = new PaletteBitmap(bitmap, palette); + return new PaletteBitmapResource(result); + } +} diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index c61dafd1b..08daf01e2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -69,6 +69,7 @@ public class UserPreferences { public static final String PREF_BACK_BUTTON_BEHAVIOR = "prefBackButtonBehavior"; private static final String PREF_BACK_BUTTON_GO_TO_PAGE = "prefBackButtonGoToPage"; public static final String PREF_FILTER_FEED = "prefSubscriptionsFilter"; + public static final String PREF_SUBSCRIPTION_TITLE = "prefSubscriptionTitle"; public static final String PREF_QUEUE_KEEP_SORTED = "prefQueueKeepSorted"; public static final String PREF_QUEUE_KEEP_SORTED_ORDER = "prefQueueKeepSortedOrder"; @@ -1090,4 +1091,13 @@ public class UserPreferences { public static void unsetUsageCountingDate() { setUsageCountingDateMillis(-1); } + + public static boolean shouldShowSubscriptionTitle() { + return prefs.getBoolean(PREF_SUBSCRIPTION_TITLE, false); + } + + public static void setSubscriptionTitleSetting(boolean showTitle) { + prefs.edit().putBoolean(PREF_SUBSCRIPTION_TITLE, showTitle).apply(); + } + } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 59b335bc8..86b3443f3 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -539,6 +539,8 @@ <string name="new_episode_notification_disabled">Notification disabled</string> <string name="pref_feed_settings_dialog_msg">This setting is unique to each podcast. You can change it by opening the podcast page.</string> <string name="pref_contribute">Contribute</string> + <string name="pref_show_subscription_title">Show Subscription Title</string> + <string name="pref_show_subscription_title_summary">Display the subscription title below the cover image.</string> <!-- About screen --> <string name="about_pref">About</string> |