Moved 'last played media' preference into default shared preference

This commit is contained in:
daniel oeh 2012-09-22 14:30:36 +02:00
parent ca9fab8330
commit b54eab8dfc
3 changed files with 18 additions and 11 deletions

View File

@ -23,7 +23,6 @@ public class PodcastApp extends Application implements
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "PodcastApp"; private static final String TAG = "PodcastApp";
public static final String PREF_NAME = "AntennapodPrefs";
public static final String EXPORT_DIR = "export/"; public static final String EXPORT_DIR = "export/";
public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect"; public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect";

View File

@ -159,8 +159,9 @@ public class PlaybackService extends Service {
return new Intent(context, AudioplayerActivity.class); return new Intent(context, AudioplayerActivity.class);
} }
} else { } else {
SharedPreferences pref = context.getApplicationContext() SharedPreferences pref = PreferenceManager
.getSharedPreferences(PodcastApp.PREF_NAME, 0); .getDefaultSharedPreferences(context
.getApplicationContext());
boolean isVideo = pref.getBoolean(PREF_LAST_IS_VIDEO, false); boolean isVideo = pref.getBoolean(PREF_LAST_IS_VIDEO, false);
if (isVideo) { if (isVideo) {
return new Intent(context, VideoplayerActivity.class); return new Intent(context, VideoplayerActivity.class);
@ -511,12 +512,17 @@ public class PlaybackService extends Service {
@Override @Override
public void run() { public void run() {
if (AppConfig.DEBUG) Log.d(TAG, "Starting chapterLoader thread"); if (AppConfig.DEBUG)
ChapterUtils.readID3ChaptersFromFeedMediaDownloadUrl(media.getItem()); Log.d(TAG, "Starting chapterLoader thread");
ChapterUtils
.readID3ChaptersFromFeedMediaDownloadUrl(media
.getItem());
if (media.getItem().getChapters() != null) { if (media.getItem().getChapters() != null) {
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0); sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD,
0);
} }
if (AppConfig.DEBUG) Log.d(TAG, "ChapterLoaderThread has finished"); if (AppConfig.DEBUG)
Log.d(TAG, "ChapterLoaderThread has finished");
} }
}; };
@ -690,8 +696,9 @@ public class PlaybackService extends Service {
Log.d(TAG, "Audiofocus successfully requested"); Log.d(TAG, "Audiofocus successfully requested");
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Resuming/Starting playback"); Log.d(TAG, "Resuming/Starting playback");
SharedPreferences.Editor editor = getApplicationContext() SharedPreferences.Editor editor = PreferenceManager
.getSharedPreferences(PodcastApp.PREF_NAME, 0).edit(); .getDefaultSharedPreferences(getApplicationContext())
.edit();
editor.putLong(PREF_LAST_PLAYED_ID, media.getId()); editor.putLong(PREF_LAST_PLAYED_ID, media.getId());
editor.putLong(PREF_LAST_PLAYED_FEED_ID, feed.getId()); editor.putLong(PREF_LAST_PLAYED_FEED_ID, feed.getId());
editor.putBoolean(PREF_LAST_IS_STREAM, shouldStream); editor.putBoolean(PREF_LAST_IS_STREAM, shouldStream);

View File

@ -16,6 +16,7 @@ import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.View; import android.view.View;
@ -163,8 +164,8 @@ public abstract class PlaybackController {
private Intent getPlayLastPlayedMediaIntent() { private Intent getPlayLastPlayedMediaIntent() {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Trying to restore last played media"); Log.d(TAG, "Trying to restore last played media");
SharedPreferences prefs = activity.getApplicationContext() SharedPreferences prefs = PreferenceManager
.getSharedPreferences(PodcastApp.PREF_NAME, 0); .getDefaultSharedPreferences(activity.getApplicationContext());
long mediaId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_ID, -1); long mediaId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_ID, -1);
long feedId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID, long feedId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID,
-1); -1);