From 6921d7162eaacc90c4522a3d9bf6d2d47d045ae7 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 1 Nov 2022 12:47:52 +0100 Subject: [PATCH] Apply default RequestOptions globally instead of locally --- .../antennapod/activity/OnlineFeedViewActivity.java | 3 --- .../antennapod/adapter/ChaptersListAdapter.java | 2 -- .../de/danoeh/antennapod/adapter/CoverLoader.java | 2 -- .../de/danoeh/antennapod/adapter/NavListAdapter.java | 2 -- .../de/danoeh/antennapod/fragment/CoverFragment.java | 2 -- .../antennapod/fragment/ExternalPlayerFragment.java | 2 -- .../danoeh/antennapod/fragment/FeedInfoFragment.java | 3 --- .../antennapod/fragment/FeedItemlistFragment.java | 3 --- .../de/danoeh/antennapod/fragment/ItemFragment.java | 2 -- .../danoeh/antennapod/core/glide/ApGlideModule.java | 5 ++++- .../antennapod/core/glide/ApGlideSettings.java | 12 ------------ .../service/download/NewEpisodesNotification.java | 5 +---- .../playback/PlaybackServiceNotificationBuilder.java | 5 +---- .../danoeh/antennapod/core/widget/WidgetUpdater.java | 4 ---- .../ui/statistics/StatisticsListAdapter.java | 2 -- 15 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index 67394018f..ff26b1b18 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -38,7 +38,6 @@ import de.danoeh.antennapod.core.feed.FeedUrlNotFoundException; import de.danoeh.antennapod.core.util.DownloadErrorLabel; import de.danoeh.antennapod.event.FeedListUpdateEvent; import de.danoeh.antennapod.event.PlayerStatusEvent; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.FastBlurTransformation; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -431,7 +430,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { .apply(new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .fitCenter() .dontAnimate()) .into(viewBinding.coverImage); @@ -440,7 +438,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { .apply(new RequestOptions() .placeholder(R.color.image_readability_tint) .error(R.color.image_readability_tint) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .transform(new FastBlurTransformation()) .dontAnimate()) .into(viewBinding.backgroundImage); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java index 20a50308f..2b11c5ff9 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java @@ -16,7 +16,6 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; import de.danoeh.antennapod.R; import de.danoeh.antennapod.model.feed.Chapter; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.model.feed.EmbeddedChapterImage; import de.danoeh.antennapod.core.util.IntentUtils; @@ -106,7 +105,6 @@ public class ChaptersListAdapter extends RecyclerView.Adapter .apply(new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .transform(new FitCenter(), new RoundedCorners((int) (4 * context.getResources().getDisplayMetrics().density))) .dontAnimate()) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index 94a697893..1632c1fb4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -32,7 +32,6 @@ import com.google.android.material.snackbar.Snackbar; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.util.DateFormatter; import de.danoeh.antennapod.core.util.playback.PlaybackController; @@ -268,7 +267,6 @@ public class CoverFragment extends Fragment { private void displayCoverImage() { RequestOptions options = new RequestOptions() - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .dontAnimate() .transform(new FitCenter(), new RoundedCorners((int) (16 * getResources().getDisplayMetrics().density))); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index 1e24d62f7..6b12f136e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -21,7 +21,6 @@ import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.event.playback.PlaybackServiceEvent; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; @@ -201,7 +200,6 @@ public class ExternalPlayerFragment extends Fragment { RequestOptions options = new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .fitCenter() .dontAnimate(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java index 29074567c..6012f89e5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java @@ -36,7 +36,6 @@ import com.google.android.material.snackbar.Snackbar; import com.joanzapata.iconify.Iconify; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.FastBlurTransformation; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; @@ -203,7 +202,6 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu .apply(new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .fitCenter() .dontAnimate()) .into(imgvCover); @@ -212,7 +210,6 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu .apply(new RequestOptions() .placeholder(R.color.image_readability_tint) .error(R.color.image_readability_tint) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .transform(new FastBlurTransformation()) .dontAnimate()) .into(imgvBackground); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index 8cd1b4909..9f3a39c22 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -32,7 +32,6 @@ import de.danoeh.antennapod.adapter.EpisodeItemListAdapter; import de.danoeh.antennapod.core.event.DownloadEvent; import de.danoeh.antennapod.core.event.DownloaderUpdate; import de.danoeh.antennapod.core.feed.FeedEvent; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.FastBlurTransformation; import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; import de.danoeh.antennapod.core.service.download.DownloadService; @@ -505,7 +504,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem .apply(new RequestOptions() .placeholder(R.color.image_readability_tint) .error(R.color.image_readability_tint) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .transform(new FastBlurTransformation()) .dontAnimate()) .into(viewBinding.imgvBackground); @@ -515,7 +513,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem .apply(new RequestOptions() .placeholder(R.color.light_gray) .error(R.color.light_gray) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .fitCenter() .dontAnimate()) .into(viewBinding.header.imgvCover); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index c80545bb2..17f8abf82 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -47,7 +47,6 @@ import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.preferences.UsageStatistics; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.Downloader; @@ -294,7 +293,6 @@ public class ItemFragment extends Fragment { RequestOptions options = new RequestOptions() .error(R.color.light_gray) - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .transform(new FitCenter(), new RoundedCorners((int) (8 * getResources().getDisplayMetrics().density))) .dontAnimate(); 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 3dfbb6f03..31f0e789f 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 @@ -11,6 +11,7 @@ import com.bumptech.glide.GlideBuilder; import com.bumptech.glide.Registry; import com.bumptech.glide.annotation.GlideModule; import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; import com.bumptech.glide.module.AppGlideModule; @@ -31,7 +32,9 @@ public class ApGlideModule extends AppGlideModule { @Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { - builder.setDefaultRequestOptions(RequestOptions.formatOf(DecodeFormat.PREFER_ARGB_8888)); + builder.setDefaultRequestOptions(new RequestOptions() + .format(DecodeFormat.PREFER_ARGB_8888) + .diskCacheStrategy(DiskCacheStrategy.ALL)); builder.setLogLevel(Log.WARN); @SuppressLint("UsableSpace") long spaceAvailable = context.getCacheDir().getUsableSpace(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java deleted file mode 100644 index d0061af99..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.danoeh.antennapod.core.glide; - -import com.bumptech.glide.load.engine.DiskCacheStrategy; - -/** - * The settings that AntennaPod will use for various Glide options - */ -public class ApGlideSettings { - private ApGlideSettings(){} - - public static final DiskCacheStrategy AP_DISK_CACHE_STRATEGY = DiskCacheStrategy.ALL; -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java index b6a1851fa..c0cf9e077 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/NewEpisodesNotification.java @@ -19,7 +19,6 @@ import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedCounter; import de.danoeh.antennapod.model.feed.FeedPreferences; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.storage.database.PodDBAdapter; @@ -119,9 +118,7 @@ public class NewEpisodesNotification { return Glide.with(context) .asBitmap() .load(feed.getImageUrl()) - .apply(new RequestOptions() - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) - .centerCrop()) + .apply(new RequestOptions().centerCrop()) .submit(iconSize, iconSize) .get(); } catch (Throwable tr) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java index 47b587d77..3d5b4224c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java @@ -20,7 +20,6 @@ import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import de.danoeh.antennapod.core.R; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.util.Converter; @@ -72,9 +71,7 @@ public class PlaybackServiceNotificationBuilder { public void loadIcon() { int iconSize = (int) (128 * context.getResources().getDisplayMetrics().density); - final RequestOptions options = new RequestOptions() - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) - .centerCrop(); + final RequestOptions options = new RequestOptions().centerCrop(); try { icon = Glide.with(context) .asBitmap() diff --git a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java index 11b0a29ca..820a31096 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java +++ b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java @@ -15,14 +15,12 @@ import android.view.View; import android.widget.RemoteViews; import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.model.playback.MediaType; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.receiver.PlayerWidget; import de.danoeh.antennapod.core.util.Converter; @@ -91,7 +89,6 @@ public abstract class WidgetUpdater { icon = Glide.with(context) .asBitmap() .load(widgetState.media.getImageLocation()) - .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY)) .submit(iconSize, iconSize) .get(500, TimeUnit.MILLISECONDS); views.setImageViewBitmap(R.id.imgvCover, icon); @@ -100,7 +97,6 @@ public abstract class WidgetUpdater { icon = Glide.with(context) .asBitmap() .load(ImageResourceUtils.getFallbackImageLocation(widgetState.media)) - .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY)) .submit(iconSize, iconSize) .get(500, TimeUnit.MILLISECONDS); views.setImageViewBitmap(R.id.imgvCover, icon); diff --git a/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsListAdapter.java b/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsListAdapter.java index d961659d7..cae58a38f 100644 --- a/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsListAdapter.java +++ b/ui/statistics/src/main/java/de/danoeh/antennapod/ui/statistics/StatisticsListAdapter.java @@ -12,7 +12,6 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; -import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.storage.StatisticsItem; import java.util.List; @@ -66,7 +65,6 @@ public abstract class StatisticsListAdapter extends RecyclerView.Adapter