Simplify playback preferences and move to :storage:preferences (#7024)

This commit is contained in:
ByteHamster 2024-03-24 21:08:06 +01:00 committed by GitHub
parent 7b390f1c92
commit 4078b3475e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 50 additions and 166 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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<FeedItem> 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)) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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
*/

View File

@ -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;

View File

@ -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;
}
}

View File

@ -1,4 +1,4 @@
package de.danoeh.antennapod.core.preferences;
package de.danoeh.antennapod.storage.preferences;
import android.content.Context;
import android.content.SharedPreferences;

View File

@ -1,4 +1,4 @@
package de.danoeh.antennapod.core.preferences;
package de.danoeh.antennapod.storage.preferences;
import android.content.Context;
import android.content.SharedPreferences;