diff --git a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java index 2dc69717c..2608db59a 100644 --- a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java +++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java @@ -11,7 +11,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.LongList; diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java index ea484faca..0c4e59931 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java @@ -6,7 +6,7 @@ import androidx.test.annotation.UiThreadTest; import androidx.test.filters.LargeTest; import de.danoeh.antennapod.event.playback.SleepTimerUpdatedEvent; -import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; +import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; import de.danoeh.antennapod.core.widget.WidgetUpdater; import de.danoeh.antennapod.storage.database.PodDBAdapter; import org.greenrobot.eventbus.EventBus; diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/SleepTimerPreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/SleepTimerPreferencesTest.java index 4339d6cd7..90131434b 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/SleepTimerPreferencesTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/SleepTimerPreferencesTest.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; -import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; +import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; public class SleepTimerPreferencesTest { @Test 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 c48bb5995..0a9101322 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -41,7 +41,7 @@ import de.danoeh.antennapod.databinding.OnlinefeedviewHeaderBinding; import de.danoeh.antennapod.event.EpisodeDownloadEvent; import de.danoeh.antennapod.event.FeedListUpdateEvent; import de.danoeh.antennapod.event.PlayerStatusEvent; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.model.download.DownloadRequest; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java index 754e2b124..af573218c 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java @@ -12,7 +12,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; -import de.danoeh.antennapod.core.preferences.UsageStatistics; +import de.danoeh.antennapod.storage.preferences.UsageStatistics; import de.danoeh.antennapod.net.common.NetworkUtils; public class DownloadActionButton extends ItemActionButton { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java index afaca2bed..cbe8ef9e8 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java @@ -9,7 +9,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.playback.MediaType; -import de.danoeh.antennapod.core.preferences.UsageStatistics; +import de.danoeh.antennapod.storage.preferences.UsageStatistics; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index d77d1ac58..21e6057a6 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -27,7 +27,7 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.Locale; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; +import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.ui.common.Converter; import de.danoeh.antennapod.core.util.playback.PlaybackController; 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 b06ea90f8..10a064802 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -45,7 +45,7 @@ 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.preferences.UsageStatistics; +import de.danoeh.antennapod.storage.preferences.UsageStatistics; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java index fe97cb265..dcbd96d5b 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/PlaybackPreferencesFragment.java @@ -12,7 +12,7 @@ import androidx.preference.PreferenceFragmentCompat; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; -import de.danoeh.antennapod.core.preferences.UsageStatistics; +import de.danoeh.antennapod.storage.preferences.UsageStatistics; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.dialog.SkipPreferenceDialog; import de.danoeh.antennapod.dialog.VariableSpeedDialog; diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 48e43358f..4ffc72699 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -16,7 +16,7 @@ import java.util.Arrays; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.util.FeedUtil; import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.core.storage.DBWriter; diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java index 3a3063599..03355510d 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java @@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; +import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; import de.danoeh.antennapod.error.CrashReportWriter; import de.danoeh.antennapod.fragment.AllEpisodesFragment; import de.danoeh.antennapod.storage.preferences.UserPreferences; diff --git a/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java b/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java index 85ba7a3d5..64c9827d5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java @@ -3,9 +3,9 @@ package de.danoeh.antennapod.core; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; -import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; -import de.danoeh.antennapod.core.preferences.UsageStatistics; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; +import de.danoeh.antennapod.storage.preferences.UsageStatistics; import de.danoeh.antennapod.net.common.UserAgentInterceptor; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.net.common.AntennapodHttpClient; diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java b/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java index d532d9ba6..6e026c91d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/util/PlaybackSpeedUtils.java @@ -3,7 +3,7 @@ package de.danoeh.antennapod.core.feed.util; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.feed.FeedPreferences; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.model.playback.Playable; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/QuickSettingsTileService.java b/core/src/main/java/de/danoeh/antennapod/core/service/QuickSettingsTileService.java index ee593aa06..f5f096329 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/QuickSettingsTileService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/QuickSettingsTileService.java @@ -11,7 +11,7 @@ import android.view.KeyEvent; import androidx.annotation.RequiresApi; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.ui.appstartintent.MediaButtonStarter; 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 195f6b5a4..fc7ccd615 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 @@ -50,6 +50,7 @@ import androidx.core.app.NotificationManagerCompat; import androidx.core.content.ContextCompat; import androidx.media.MediaBrowserServiceCompat; +import de.danoeh.antennapod.event.PlayerStatusEvent; import de.danoeh.antennapod.ui.notifications.NotificationUtils; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -63,8 +64,8 @@ import java.util.List; import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.R; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; -import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.service.QuickSettingsTileService; import de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager.SleepTimer; @@ -452,9 +453,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { Feed feed = DBReader.getFeed(feedId); feedItems = DBReader.getFeedItemList(feed, FeedItemFilter.unfiltered(), feed.getSortOrder()); } else if (parentId.equals(getString(R.string.current_playing_episode))) { - Playable playable = PlaybackPreferences.createInstanceFromPreferences(this); - if (playable instanceof FeedMedia) { - feedItems = Collections.singletonList(((FeedMedia) playable).getItem()); + FeedMedia playable = DBReader.getFeedMedia(PlaybackPreferences.getCurrentlyPlayingFeedMediaId()); + if (playable != null) { + feedItems = Collections.singletonList(playable.getItem()); } else { return null; } @@ -734,7 +735,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } private void startPlayingFromPreferences() { - Observable.fromCallable(() -> PlaybackPreferences.createInstanceFromPreferences(getApplicationContext())) + Observable.fromCallable(() -> DBReader.getFeedMedia(PlaybackPreferences.getCurrentlyPlayingFeedMediaId())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( @@ -818,15 +819,13 @@ public class PlaybackService extends MediaBrowserServiceCompat { switch (newInfo.playerStatus) { case INITIALIZED: if (mediaPlayer.getPSMPInfo().playable != null) { - PlaybackPreferences.writeMediaPlaying(mediaPlayer.getPSMPInfo().playable, - mediaPlayer.getPSMPInfo().playerStatus); + PlaybackPreferences.writeMediaPlaying(mediaPlayer.getPSMPInfo().playable); } updateNotificationAndMediaSession(newInfo.playable); break; case PREPARED: if (mediaPlayer.getPSMPInfo().playable != null) { - PlaybackPreferences.writeMediaPlaying(mediaPlayer.getPSMPInfo().playable, - mediaPlayer.getPSMPInfo().playerStatus); + PlaybackPreferences.writeMediaPlaying(mediaPlayer.getPSMPInfo().playable); } taskManager.startChapterLoader(newInfo.playable); break; @@ -836,14 +835,12 @@ public class PlaybackService extends MediaBrowserServiceCompat { stateManager.stopForeground(!UserPreferences.isPersistNotify()); } cancelPositionObserver(); - PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus()); break; case STOPPED: //writePlaybackPreferencesNoMediaPlaying(); //stopService(); break; case PLAYING: - PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus()); saveCurrentPosition(true, null, Playable.INVALID_TIME); recreateMediaSessionIfNeeded(); updateNotificationAndMediaSession(newInfo.playable); @@ -886,6 +883,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { bluetoothNotifyChange(newInfo, AVRCP_ACTION_PLAYER_STATUS_CHANGED); bluetoothNotifyChange(newInfo, AVRCP_ACTION_META_CHANGED); taskManager.requestWidgetUpdate(); + EventBus.getDefault().post(new PlayerStatusEvent()); } @Override @@ -1034,7 +1032,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (!UserPreferences.isFollowQueue()) { Log.d(TAG, "getNextInQueue(), but follow queue is not enabled."); - PlaybackPreferences.writeMediaPlaying(nextItem.getMedia(), PlayerStatus.STOPPED); + PlaybackPreferences.writeMediaPlaying(nextItem.getMedia()); updateNotificationAndMediaSession(nextItem.getMedia()); return null; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java index 3d69dbdbc..c86d4a784 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java @@ -8,7 +8,7 @@ import androidx.annotation.NonNull; import android.util.Log; import de.danoeh.antennapod.event.playback.SleepTimerUpdatedEvent; -import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; +import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.widget.WidgetUpdater; import io.reactivex.disposables.Disposable; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index ae14afc69..389f2bf5a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -40,7 +40,7 @@ import de.danoeh.antennapod.event.playback.PlaybackHistoryEvent; import de.danoeh.antennapod.event.QueueEvent; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.core.feed.FeedEvent; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.model.download.DownloadResult; import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink; @@ -427,7 +427,7 @@ public class DBWriter { List updatedItems = new ArrayList<>(); ItemEnqueuePositionCalculator positionCalculator = new ItemEnqueuePositionCalculator(UserPreferences.getEnqueueLocation()); - Playable currentlyPlaying = PlaybackPreferences.createInstanceFromPreferences(context); + Playable currentlyPlaying = DBReader.getFeedMedia(PlaybackPreferences.getCurrentlyPlayingFeedMediaId()); int insertPosition = positionCalculator.calcPosition(queue, currentlyPlaying); for (long itemId : itemIds) { if (!itemListContains(queue, itemId)) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/PlaybackStatus.java b/core/src/main/java/de/danoeh/antennapod/core/util/PlaybackStatus.java index 3c07d325b..6fb7c487b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/PlaybackStatus.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/PlaybackStatus.java @@ -1,6 +1,6 @@ package de.danoeh.antennapod.core.util; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.model.feed.FeedMedia; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index f17bd7e31..807c869f9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -13,6 +13,7 @@ import android.util.Pair; import android.view.SurfaceHolder; import androidx.annotation.NonNull; import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; +import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.model.feed.FeedMedia; @@ -21,7 +22,7 @@ import de.danoeh.antennapod.event.playback.SpeedChangedEvent; import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer; @@ -341,7 +342,7 @@ public abstract class PlaybackController { public Playable getMedia() { if (media == null) { - media = PlaybackPreferences.createInstanceFromPreferences(activity); + media = DBReader.getFeedMedia(PlaybackPreferences.getCurrentlyPlayingFeedMediaId()); } return media; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdaterWorker.java b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdaterWorker.java index 11a573e1f..ddca49988 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdaterWorker.java +++ b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdaterWorker.java @@ -9,7 +9,8 @@ import androidx.work.WorkManager; import androidx.work.Worker; import androidx.work.WorkerParameters; import de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; +import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.playback.base.PlayerStatus; @@ -43,7 +44,7 @@ public class WidgetUpdaterWorker extends Worker { * Loads the current media from the database and updates the widget in a background job. */ private void updateWidget() { - final Playable media = PlaybackPreferences.createInstanceFromPreferences(getApplicationContext()); + final Playable media = DBReader.getFeedMedia(PlaybackPreferences.getCurrentlyPlayingFeedMediaId()); if (media != null) { WidgetUpdater.updateWidget(getApplicationContext(), new WidgetUpdater.WidgetState(media, PlayerStatus.STOPPED, diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java index d23ec8286..7bdf8aa10 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java @@ -9,7 +9,7 @@ import android.webkit.MimeTypeMap; import androidx.annotation.NonNull; import androidx.test.platform.app.InstrumentationRegistry; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterfaceStub; import de.danoeh.antennapod.core.util.FastDocumentFile; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java index 0369ad3b1..5ff09287d 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbCleanupTests.java @@ -18,7 +18,7 @@ import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.storage.database.PodDBAdapter; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java index 3eed90ea8..548e74e3a 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbTasksTest.java @@ -22,7 +22,7 @@ import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences; import static java.util.Collections.singletonList; diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java index 8e4cae855..76333d9b2 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbWriterTest.java @@ -33,7 +33,7 @@ import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.core.util.FeedItemUtil; diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java index 571cbc128..698cdf34e 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedMedia.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.model.feed; import android.content.Context; -import android.content.SharedPreferences.Editor; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; @@ -23,9 +22,6 @@ public class FeedMedia implements Playable { public static final int PLAYABLE_TYPE_FEEDMEDIA = 1; public static final String FILENAME_PREFIX_EMBEDDED_COVER = "metadata-retriever:"; - public static final String PREF_MEDIA_ID = "FeedMedia.PrefMediaId"; - private static final String PREF_FEED_ID = "FeedMedia.PrefFeedId"; - /** * Indicates we've checked on the size of the item via the network * and got an invalid response. Using Integer.MIN_VALUE because @@ -303,16 +299,6 @@ public class FeedMedia implements Playable { dest.writeLong(lastPlayedTime); } - @Override - public void writeToPreferences(Editor prefEditor) { - if (item != null && item.getFeed() != null) { - prefEditor.putLong(PREF_FEED_ID, item.getFeed().getId()); - } else { - prefEditor.putLong(PREF_FEED_ID, 0L); - } - prefEditor.putLong(PREF_MEDIA_ID, id); - } - @Override public String getEpisodeTitle() { if (item == null) { diff --git a/model/src/main/java/de/danoeh/antennapod/model/playback/Playable.java b/model/src/main/java/de/danoeh/antennapod/model/playback/Playable.java index e48be9aec..8bf1c4e20 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/playback/Playable.java +++ b/model/src/main/java/de/danoeh/antennapod/model/playback/Playable.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.model.playback; import android.content.Context; -import android.content.SharedPreferences; import android.os.Parcelable; import androidx.annotation.Nullable; @@ -17,14 +16,6 @@ import java.util.List; public interface Playable extends Parcelable, Serializable { int INVALID_TIME = -1; - /** - * Save information about the playable in a preference so that it can be - * restored later via PlaybackPreferences.createInstanceFromPreferences. - * Implementations must NOT call commit() after they have written the values - * to the preferences file. - */ - void writeToPreferences(SharedPreferences.Editor prefEditor); - /** * Returns the title of the episode that this playable represents */ diff --git a/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java b/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java index 8c3cd7ce4..b963f3de1 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java +++ b/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.model.playback; import android.content.Context; -import android.content.SharedPreferences; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; @@ -120,11 +119,6 @@ public class RemoteMedia implements Playable { return notes; } - @Override - public void writeToPreferences(SharedPreferences.Editor prefEditor) { - //it seems pointless to do it, since the session should be kept by the remote device. - } - @Override public String getEpisodeTitle() { return episodeTitle; diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/PlaybackPreferences.java similarity index 63% rename from core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java rename to storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/PlaybackPreferences.java index d6f6cdb43..d6d260446 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/PlaybackPreferences.java +++ b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/PlaybackPreferences.java @@ -1,29 +1,21 @@ -package de.danoeh.antennapod.core.preferences; +package de.danoeh.antennapod.storage.preferences; import android.content.Context; import android.content.SharedPreferences; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; import android.util.Log; -import de.danoeh.antennapod.core.storage.DBReader; -import de.danoeh.antennapod.event.PlayerStatusEvent; 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.model.playback.Playable; -import de.danoeh.antennapod.playback.base.PlayerStatus; -import org.greenrobot.eventbus.EventBus; - -import static de.danoeh.antennapod.model.feed.FeedPreferences.SPEED_USE_GLOBAL; /** * Provides access to preferences set by the playback service. A private * instance of this class must first be instantiated via createInstance() or * otherwise every public method will throw an Exception when called. */ -public class PlaybackPreferences implements SharedPreferences.OnSharedPreferenceChangeListener { +public abstract class PlaybackPreferences { private static final String TAG = "PlaybackPreferences"; @@ -92,22 +84,10 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference */ public static final int PLAYER_STATUS_OTHER = 3; - private static PlaybackPreferences instance; private static SharedPreferences prefs; - private PlaybackPreferences() { - } - public static void init(Context context) { - instance = new PlaybackPreferences(); prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.registerOnSharedPreferenceChangeListener(instance); - } - - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (PREF_CURRENT_PLAYER_STATUS.equals(key)) { - EventBus.getDefault().post(new PlayerStatusEvent()); - } } public static long getCurrentlyPlayingMediaType() { @@ -115,6 +95,9 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference } public static long getCurrentlyPlayingFeedMediaId() { + if (PlaybackPreferences.getCurrentlyPlayingMediaType() == NO_MEDIA_PLAYING) { + return NO_MEDIA_PLAYING; + } return prefs.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING); } @@ -127,7 +110,7 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference } public static float getCurrentlyPlayingTemporaryPlaybackSpeed() { - return prefs.getFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, SPEED_USE_GLOBAL); + return prefs.getFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, FeedPreferences.SPEED_USE_GLOBAL); } public static FeedPreferences.SkipSilence getCurrentlyPlayingTemporarySkipSilence() { @@ -144,7 +127,7 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference editor.apply(); } - public static void writeMediaPlaying(Playable playable, PlayerStatus playerStatus) { + public static void writeMediaPlaying(Playable playable) { Log.d(TAG, "Writing playback preferences"); SharedPreferences.Editor editor = prefs.edit(); @@ -161,18 +144,7 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING); editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING); } - playable.writeToPreferences(editor); } - editor.putInt(PREF_CURRENT_PLAYER_STATUS, getCurrentPlayerStatusAsInt(playerStatus)); - - editor.apply(); - } - - public static void writePlayerStatus(PlayerStatus playerStatus) { - Log.d(TAG, "Writing player status playback preferences"); - - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(PREF_CURRENT_PLAYER_STATUS, getCurrentPlayerStatusAsInt(playerStatus)); editor.apply(); } @@ -195,63 +167,4 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference editor.remove(PREF_CURRENTLY_PLAYING_TEMPORARY_SKIP_SILENCE); editor.apply(); } - - private static int getCurrentPlayerStatusAsInt(PlayerStatus playerStatus) { - int playerStatusAsInt; - switch (playerStatus) { - case PLAYING: - playerStatusAsInt = PLAYER_STATUS_PLAYING; - break; - case PAUSED: - playerStatusAsInt = PLAYER_STATUS_PAUSED; - break; - default: - playerStatusAsInt = PLAYER_STATUS_OTHER; - } - return playerStatusAsInt; - } - - /** - * Restores a playable object from a sharedPreferences file. This method might load data from the database, - * depending on the type of playable that was restored. - * - * @return The restored Playable object - */ - @Nullable - public static Playable createInstanceFromPreferences(@NonNull Context context) { - long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMediaType(); - if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); - return createInstanceFromPreferences((int) currentlyPlayingMedia, prefs); - } - return null; - } - - /** - * Restores a playable object from a sharedPreferences file. This method might load data from the database, - * depending on the type of playable that was restored. - * - * @param type An integer that represents the type of the Playable object - * that is restored. - * @param pref The SharedPreferences file from which the Playable object - * is restored - * @return The restored Playable object - */ - private static Playable createInstanceFromPreferences(int type, SharedPreferences pref) { - if (type == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA) { - return createFeedMediaInstance(pref); - } else { - Log.e(TAG, "Could not restore Playable object from preferences"); - return null; - } - } - - private static Playable createFeedMediaInstance(SharedPreferences pref) { - Playable result = null; - long mediaId = pref.getLong(FeedMedia.PREF_MEDIA_ID, -1); - if (mediaId != -1) { - result = DBReader.getFeedMedia(mediaId); - } - return result; - } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/SleepTimerPreferences.java b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/SleepTimerPreferences.java similarity index 98% rename from core/src/main/java/de/danoeh/antennapod/core/preferences/SleepTimerPreferences.java rename to storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/SleepTimerPreferences.java index 96ffe5cb6..5c2643c51 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/SleepTimerPreferences.java +++ b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/SleepTimerPreferences.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.core.preferences; +package de.danoeh.antennapod.storage.preferences; import android.content.Context; import android.content.SharedPreferences; diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UsageStatistics.java similarity index 98% rename from core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java rename to storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UsageStatistics.java index 9835f9894..e8da0d194 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UsageStatistics.java +++ b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UsageStatistics.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.core.preferences; +package de.danoeh.antennapod.storage.preferences; import android.content.Context; import android.content.SharedPreferences;