summaryrefslogtreecommitdiff
path: root/core/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/de')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideModule.java13
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java15
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java108
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java8
4 files changed, 50 insertions, 94 deletions
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 b3adc567e..8ad04cb47 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
@@ -1,6 +1,8 @@
package de.danoeh.antennapod.core.glide;
+import android.annotation.SuppressLint;
import android.content.Context;
+import android.util.Log;
import androidx.annotation.NonNull;
import com.bumptech.glide.Glide;
@@ -16,7 +18,6 @@ import de.danoeh.antennapod.core.util.EmbeddedChapterImage;
import java.io.InputStream;
import com.bumptech.glide.request.RequestOptions;
-import de.danoeh.antennapod.core.preferences.UserPreferences;
import java.nio.ByteBuffer;
/**
@@ -24,12 +25,18 @@ import java.nio.ByteBuffer;
*/
@GlideModule
public class ApGlideModule extends AppGlideModule {
+ private static final String TAG = "ApGlideModule";
+ private static final long MEGABYTES = 1024 * 1024;
+ private static final long GIGABYTES = 1024 * 1024 * 1024;
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_ARGB_8888));
- builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
- UserPreferences.getImageCacheSize()));
+ @SuppressLint("UsableSpace")
+ long spaceAvailable = context.getCacheDir().getUsableSpace();
+ long imageCacheSize = (spaceAvailable > 2 * GIGABYTES) ? (250 * MEGABYTES) : (50 * MEGABYTES);
+ Log.d(TAG, "Free space on cache dir: " + spaceAvailable + ", using image cache size: " + imageCacheSize);
+ builder.setDiskCache(new InternalCacheDiskCacheFactory(context, imageCacheSize));
}
@Override
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 63414800d..76dfab169 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
@@ -114,7 +114,6 @@ public class UserPreferences {
// Other
private static final String PREF_DATA_FOLDER = "prefDataFolder";
- public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize";
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
public static final String PREF_USAGE_COUNTING_DATE = "prefUsageCounting";
@@ -127,8 +126,6 @@ public class UserPreferences {
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
private static final String PREF_REWIND_SECS = "prefRewindSecs";
private static final String PREF_QUEUE_LOCKED = "prefQueueLocked";
- private static final String IMAGE_CACHE_DEFAULT_VALUE = "100";
- private static final int IMAGE_CACHE_SIZE_MINIMUM = 20;
private static final String PREF_LEFT_VOLUME = "prefLeftVolume";
private static final String PREF_RIGHT_VOLUME = "prefRightVolume";
@@ -596,18 +593,6 @@ public class UserPreferences {
return Build.VERSION.SDK_INT < 29 && prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false);
}
- public static int getImageCacheSize() {
- String cacheSizeString = prefs.getString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE);
- int cacheSizeInt = Integer.parseInt(cacheSizeString);
- // if the cache size is too small the user won't get any images at all
- // that's bad, force it back to the default.
- if (cacheSizeInt < IMAGE_CACHE_SIZE_MINIMUM) {
- prefs.edit().putString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE).apply();
- cacheSizeInt = Integer.parseInt(IMAGE_CACHE_DEFAULT_VALUE);
- }
- return cacheSizeInt * 1024 * 1024;
- }
-
public static int getFastForwardSecs() {
return prefs.getInt(PREF_FAST_FORWARD_SECS, 30);
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index 679d8c3b6..2da06e226 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -13,7 +13,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
-import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
@@ -41,10 +40,6 @@ import android.view.SurfaceHolder;
import android.webkit.URLUtil;
import android.widget.Toast;
-import com.bumptech.glide.Glide;
-import com.bumptech.glide.request.RequestOptions;
-import com.bumptech.glide.request.target.Target;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -63,7 +58,6 @@ import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.model.feed.FeedPreferences;
import de.danoeh.antennapod.model.playback.MediaType;
-import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@@ -72,7 +66,6 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.FeedSearcher;
-import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
import de.danoeh.antennapod.core.sync.SyncService;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
@@ -1280,81 +1273,43 @@ public class PlaybackService extends MediaBrowserServiceCompat {
(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP));
}
- /**
- * Used by updateMediaSessionMetadata to load notification data in another thread.
- */
- private Thread mediaSessionSetupThread;
-
private void updateMediaSessionMetadata(final Playable p) {
if (p == null || mediaSession == null) {
return;
}
- if (mediaSessionSetupThread != null) {
- mediaSessionSetupThread.interrupt();
- }
-
- Runnable mediaSessionSetupTask = () -> {
- MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
- builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, p.getFeedTitle());
- builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, p.getEpisodeTitle());
- builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, p.getFeedTitle());
- builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, p.getDuration());
- builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, p.getEpisodeTitle());
- builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, p.getFeedTitle());
-
- String imageLocation = p.getImageLocation();
-
- if (!TextUtils.isEmpty(imageLocation)) {
- if (UserPreferences.setLockscreenBackground()) {
- Bitmap art;
- builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, imageLocation);
- try {
- art = Glide.with(this)
- .asBitmap()
- .load(imageLocation)
- .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
- .submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
- .get();
- builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art);
- } catch (Throwable tr1) {
- try {
- art = Glide.with(this)
- .asBitmap()
- .load(ImageResourceUtils.getFallbackImageLocation(p))
- .apply(RequestOptions.diskCacheStrategyOf(ApGlideSettings.AP_DISK_CACHE_STRATEGY))
- .submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
- .get();
- builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art);
- } catch (Throwable tr2) {
- Log.e(TAG, Log.getStackTraceString(tr2));
- }
- }
- } else if (isCasting) {
- // In the absence of metadata art, the controller dialog takes care of creating it.
- builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, imageLocation);
- }
- }
- if (!Thread.currentThread().isInterrupted() && stateManager.hasReceivedValidStartCommand()) {
- mediaSession.setSessionActivity(PendingIntent.getActivity(this, R.id.pending_intent_player_activity,
- PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT));
- try {
- mediaSession.setMetadata(builder.build());
- } catch (OutOfMemoryError e) {
- Log.e(TAG, "Setting media session metadata", e);
- builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, null);
- mediaSession.setMetadata(builder.build());
- }
- }
- };
- mediaSessionSetupThread = new Thread(mediaSessionSetupTask);
- mediaSessionSetupThread.start();
+ MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
+ builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, p.getFeedTitle());
+ builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, p.getEpisodeTitle());
+ builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, p.getFeedTitle());
+ builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, p.getDuration());
+ builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, p.getEpisodeTitle());
+ builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, p.getFeedTitle());
+
+ if (UserPreferences.setLockscreenBackground() && notificationBuilder.isIconCached()) {
+ builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, notificationBuilder.getCachedIcon());
+ } else if (isCasting && !TextUtils.isEmpty(p.getImageLocation())) {
+ // In the absence of metadata art, the controller dialog takes care of creating it.
+ builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, p.getImageLocation());
+ }
+
+ if (stateManager.hasReceivedValidStartCommand()) {
+ mediaSession.setSessionActivity(PendingIntent.getActivity(this, R.id.pending_intent_player_activity,
+ PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT));
+ try {
+ mediaSession.setMetadata(builder.build());
+ } catch (OutOfMemoryError e) {
+ Log.e(TAG, "Setting media session metadata", e);
+ builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, null);
+ mediaSession.setMetadata(builder.build());
+ }
+ }
}
/**
* Used by setupNotification to load notification data in another thread.
*/
- private Thread notificationSetupThread;
+ private Thread playableIconLoaderThread;
/**
* Prepares notification and starts the service in the foreground.
@@ -1365,8 +1320,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
private synchronized void setupNotification(final Playable playable) {
Log.d(TAG, "setupNotification");
- if (notificationSetupThread != null) {
- notificationSetupThread.interrupt();
+ if (playableIconLoaderThread != null) {
+ playableIconLoaderThread.interrupt();
}
if (playable == null || mediaPlayer == null) {
Log.d(TAG, "setupNotification: playable=" + playable);
@@ -1389,14 +1344,15 @@ public class PlaybackService extends MediaBrowserServiceCompat {
startForegroundIfPlaying(playerStatus);
if (!notificationBuilder.isIconCached()) {
- notificationSetupThread = new Thread(() -> {
+ playableIconLoaderThread = new Thread(() -> {
Log.d(TAG, "Loading notification icon");
notificationBuilder.loadIcon();
if (!Thread.currentThread().isInterrupted()) {
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
+ updateMediaSessionMetadata(playable);
}
});
- notificationSetupThread.start();
+ playableIconLoaderThread.start();
}
}
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 75ebf7e10..e7dea192a 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
@@ -89,14 +89,22 @@ public class PlaybackServiceNotificationBuilder {
.apply(new RequestOptions().centerCrop())
.submit(iconSize, iconSize)
.get();
+ } catch (InterruptedException ignore) {
+ Log.e(TAG, "Media icon loader was interrupted");
} catch (Throwable tr) {
Log.e(TAG, "Error loading the media icon for the notification", tr);
}
+ } catch (InterruptedException ignore) {
+ Log.e(TAG, "Media icon loader was interrupted");
} catch (Throwable tr) {
Log.e(TAG, "Error loading the media icon for the notification", tr);
}
}
+ public Bitmap getCachedIcon() {
+ return icon;
+ }
+
private Bitmap getDefaultIcon() {
if (defaultIcon == null) {
defaultIcon = getBitmap(context, R.mipmap.ic_launcher);