diff options
author | ByteHamster <info@bytehamster.com> | 2021-04-22 22:27:39 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-04-22 22:27:39 +0200 |
commit | 2a47f49fde3327ee3a1b3c2d66b2c950cda7e14e (patch) | |
tree | ae0534de797fe227d456ea15cbbe9b5aea084413 /core | |
parent | 09d402a945b42e86001f12325e00395487ac76b4 (diff) | |
download | AntennaPod-2a47f49fde3327ee3a1b3c2d66b2c950cda7e14e.zip |
Remove dependency of FeedMedia to DbWriter
Diffstat (limited to 'core')
5 files changed, 31 insertions, 37 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java index 969bbd0f6..3483522ed 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.core.feed; import android.content.Context; -import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.media.MediaMetadataRetriever; import android.net.Uri; @@ -14,7 +13,6 @@ import android.support.v4.media.MediaDescriptionCompat; import java.util.Date; import java.util.List; -import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.playback.Playable; public class FeedMedia extends FeedFile implements Playable { @@ -171,6 +169,10 @@ public class FeedMedia extends FeedFile implements Playable { return played_duration; } + public int getPlayedDurationWhenStarted() { + return playedDurationWhenStarted; + } + public void setPlayedDuration(int played_duration) { this.played_duration = played_duration; } @@ -374,19 +376,6 @@ public class FeedMedia extends FeedFile implements Playable { } @Override - public void saveCurrentPosition(SharedPreferences pref, int newPosition, long timeStamp) { - if(item != null && item.isNew()) { - DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId()); - } - setPosition(newPosition); - setLastPlayedTime(timeStamp); - if(startPosition>=0 && position > startPosition) { - setPlayedDuration(playedDurationWhenStarted + position - startPosition); - } - DBWriter.setFeedMediaPlaybackInformation(this); - } - - @Override public void onPlaybackStart() { startPosition = Math.max(position, 0); playedDurationWhenStarted = played_duration; 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 37b173d5c..145590db2 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 @@ -1450,10 +1450,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } if (position != INVALID_TIME && duration != INVALID_TIME && playable != null) { Log.d(TAG, "Saving current position to " + position); - playable.saveCurrentPosition( - PreferenceManager.getDefaultSharedPreferences(getApplicationContext()), - position, - System.currentTimeMillis()); + PlayableUtils.saveCurrentPosition(playable, position, System.currentTimeMillis()); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java index 683515d6f..2c4b93d38 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java @@ -101,17 +101,6 @@ public interface Playable extends Parcelable { */ boolean localFileAvailable(); - /** - * Saves the current position of this object. Implementations can use the - * provided SharedPreference to save this information and retrieve it later - * via PlayableUtils.createInstanceFromPreferences. - * - * @param pref shared prefs that might be used to store this object - * @param newPosition new playback position in ms - * @param timestamp current time in ms - */ - void saveCurrentPosition(SharedPreferences pref, int newPosition, long timestamp); - void setPosition(int newPosition); void setDuration(int newDuration); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlayableUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlayableUtils.java index 861d42c1b..47a8e6a1d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlayableUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlayableUtils.java @@ -8,9 +8,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; +import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.DBWriter; /** * Provides utility methods for Playable objects. @@ -70,4 +72,28 @@ public abstract class PlayableUtils { } return result; } + + /** + * Saves the current position of this object. + * + * @param newPosition new playback position in ms + * @param timestamp current time in ms + */ + public static void saveCurrentPosition(Playable playable, int newPosition, long timestamp) { + playable.setPosition(newPosition); + playable.setLastPlayedTime(timestamp); + + if (playable instanceof FeedMedia) { + FeedMedia media = (FeedMedia) playable; + FeedItem item = media.getItem(); + if (item != null && item.isNew()) { + DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId()); + } + if (media.getStartPosition() >= 0 && playable.getPosition() > media.getStartPosition()) { + media.setPlayedDuration(media.getPlayedDurationWhenStarted() + + playable.getPosition() - media.getStartPosition()); + } + DBWriter.setFeedMediaPlaybackInformation(media); + } + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/RemoteMedia.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/RemoteMedia.java index 5941e8f24..8585e3110 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/RemoteMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/RemoteMedia.java @@ -189,13 +189,6 @@ public class RemoteMedia implements Playable { } @Override - public void saveCurrentPosition(SharedPreferences pref, int newPosition, long timestamp) { - //we're not saving playback information for this kind of items on preferences - setPosition(newPosition); - setLastPlayedTime(timestamp); - } - - @Override public void setPosition(int newPosition) { position = newPosition; } |