2012-07-13 12:23:47 +02:00
|
|
|
package de.danoeh.antennapod;
|
2011-12-23 19:22:06 +01:00
|
|
|
|
|
|
|
import android.app.Application;
|
2012-07-08 13:40:10 +02:00
|
|
|
import android.content.SharedPreferences;
|
2012-08-11 15:45:30 +02:00
|
|
|
import android.content.res.Configuration;
|
2012-07-08 13:40:10 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2012-07-06 15:55:20 +02:00
|
|
|
import android.util.Log;
|
2013-02-25 18:15:02 +01:00
|
|
|
import de.danoeh.antennapod.asynctask.ImageLoader;
|
2013-02-25 10:47:37 +01:00
|
|
|
import de.danoeh.antennapod.feed.EventDistributor;
|
2012-07-13 12:23:47 +02:00
|
|
|
import de.danoeh.antennapod.feed.FeedManager;
|
2012-09-22 15:59:21 +02:00
|
|
|
import de.danoeh.antennapod.feed.FeedMedia;
|
2013-02-24 10:46:10 +01:00
|
|
|
import de.danoeh.antennapod.preferences.UserPreferences;
|
2012-09-22 15:59:21 +02:00
|
|
|
import de.danoeh.antennapod.service.PlaybackService;
|
2012-07-08 13:40:10 +02:00
|
|
|
|
2012-08-07 13:56:33 +02:00
|
|
|
/** Main application class. */
|
2012-07-08 13:40:10 +02:00
|
|
|
public class PodcastApp extends Application implements
|
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
2011-12-23 19:22:06 +01:00
|
|
|
|
2012-07-07 23:37:52 +02:00
|
|
|
private static final String TAG = "PodcastApp";
|
2012-07-26 19:19:35 +02:00
|
|
|
public static final String EXPORT_DIR = "export/";
|
2012-07-07 23:37:52 +02:00
|
|
|
|
2012-07-21 19:35:07 +02:00
|
|
|
private static float LOGICAL_DENSITY;
|
2012-07-08 13:40:10 +02:00
|
|
|
|
2012-07-07 23:37:52 +02:00
|
|
|
private static PodcastApp singleton;
|
2012-10-30 21:03:59 +01:00
|
|
|
|
|
|
|
private static long currentlyPlayingMediaId;
|
2012-12-26 00:39:35 +01:00
|
|
|
|
2011-12-23 19:22:06 +01:00
|
|
|
public static PodcastApp getInstance() {
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
|
|
|
singleton = this;
|
2012-07-21 19:35:07 +02:00
|
|
|
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
|
2012-07-08 13:40:10 +02:00
|
|
|
SharedPreferences prefs = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(this);
|
2012-10-30 21:03:59 +01:00
|
|
|
currentlyPlayingMediaId = prefs.getLong(
|
|
|
|
PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA,
|
|
|
|
PlaybackService.NO_MEDIA_PLAYING);
|
2012-07-08 13:40:10 +02:00
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2013-02-24 10:46:10 +01:00
|
|
|
UserPreferences.createInstance(this);
|
2013-02-25 10:47:37 +01:00
|
|
|
EventDistributor.getInstance();
|
2012-07-22 18:25:15 +02:00
|
|
|
FeedManager manager = FeedManager.getInstance();
|
|
|
|
manager.loadDBData(getApplicationContext());
|
2011-12-23 19:22:06 +01:00
|
|
|
}
|
2012-08-07 13:56:33 +02:00
|
|
|
|
2012-07-06 15:55:20 +02:00
|
|
|
@Override
|
|
|
|
public void onLowMemory() {
|
|
|
|
super.onLowMemory();
|
|
|
|
Log.w(TAG, "Received onLowOnMemory warning. Cleaning image cache...");
|
2013-02-25 18:15:02 +01:00
|
|
|
ImageLoader.getInstance().wipeImageCache();
|
2012-07-06 15:55:20 +02:00
|
|
|
}
|
2011-12-23 19:22:06 +01:00
|
|
|
|
2012-08-07 13:56:33 +02:00
|
|
|
/**
|
|
|
|
* Listens for changes in the 'update intervall'-preference and changes the
|
|
|
|
* alarm if necessary.
|
|
|
|
*/
|
2012-07-08 13:40:10 +02:00
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
|
|
|
String key) {
|
2012-07-22 18:25:15 +02:00
|
|
|
if (AppConfig.DEBUG)
|
|
|
|
Log.d(TAG, "Registered change of application preferences");
|
2013-02-24 10:46:10 +01:00
|
|
|
|
|
|
|
if (key.equals(PlaybackService.PREF_LAST_PLAYED_ID)) {
|
2012-10-30 21:03:59 +01:00
|
|
|
if (AppConfig.DEBUG)
|
|
|
|
Log.d(TAG, "PREF_LAST_PLAYED_ID changed");
|
|
|
|
long mediaId = sharedPreferences.getLong(
|
|
|
|
PlaybackService.PREF_AUTODELETE_MEDIA_ID, -1);
|
2012-09-22 15:59:21 +02:00
|
|
|
if (mediaId != -1) {
|
|
|
|
FeedManager manager = FeedManager.getInstance();
|
|
|
|
FeedMedia media = manager.getFeedMedia(mediaId);
|
|
|
|
if (media != null) {
|
|
|
|
manager.autoDeleteIfPossible(this, media);
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 21:03:59 +01:00
|
|
|
} else if (key.equals(PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA)) {
|
|
|
|
long id = sharedPreferences.getLong(
|
|
|
|
PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA,
|
|
|
|
PlaybackService.NO_MEDIA_PLAYING);
|
|
|
|
if (AppConfig.DEBUG)
|
|
|
|
Log.d(TAG, "Currently playing media set to " + id);
|
|
|
|
if (id != currentlyPlayingMediaId) {
|
|
|
|
currentlyPlayingMediaId = id;
|
|
|
|
}
|
2012-07-08 13:40:10 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-22 18:25:15 +02:00
|
|
|
|
2012-07-21 19:35:07 +02:00
|
|
|
public static float getLogicalDensity() {
|
|
|
|
return LOGICAL_DENSITY;
|
|
|
|
}
|
2012-10-30 21:03:59 +01:00
|
|
|
|
|
|
|
public static long getCurrentlyPlayingMediaId() {
|
|
|
|
return currentlyPlayingMediaId;
|
2012-10-28 20:31:29 +01:00
|
|
|
}
|
2012-08-11 15:45:30 +02:00
|
|
|
|
|
|
|
public boolean isLargeScreen() {
|
2012-10-30 21:03:59 +01:00
|
|
|
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
|
|
|
|
|| (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
2012-08-11 15:45:30 +02:00
|
|
|
|
|
|
|
}
|
2012-12-26 00:39:35 +01:00
|
|
|
|
2011-12-23 19:22:06 +01:00
|
|
|
}
|