Merge pull request #1696 from mfietz/issue/1695-npe-context-null
Ensure initialization
This commit is contained in:
commit
0d114d172b
|
@ -8,11 +8,8 @@ import com.joanzapata.iconify.Iconify;
|
||||||
import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
||||||
import com.joanzapata.iconify.fonts.MaterialModule;
|
import com.joanzapata.iconify.fonts.MaterialModule;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
|
||||||
import de.danoeh.antennapod.spa.SPAUtil;
|
import de.danoeh.antennapod.spa.SPAUtil;
|
||||||
|
|
||||||
/** Main application class. */
|
/** Main application class. */
|
||||||
|
@ -56,11 +53,8 @@ public class PodcastApp extends Application {
|
||||||
|
|
||||||
singleton = this;
|
singleton = this;
|
||||||
|
|
||||||
PodDBAdapter.init(this);
|
ClientConfig.initialize(this);
|
||||||
UserPreferences.init(this);
|
|
||||||
UpdateManager.init(this);
|
|
||||||
PlaybackPreferences.init(this);
|
|
||||||
NetworkUtils.init(this);
|
|
||||||
EventDistributor.getInstance();
|
EventDistributor.getInstance();
|
||||||
Iconify.with(new FontAwesomeModule());
|
Iconify.with(new FontAwesomeModule());
|
||||||
Iconify.with(new MaterialModule());
|
Iconify.with(new MaterialModule());
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.net.NetworkInfo;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
|
@ -20,7 +21,8 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
|
||||||
if (TextUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) {
|
if (TextUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||||
Log.d(TAG, "Received intent");
|
Log.d(TAG, "Received intent");
|
||||||
|
|
||||||
if (NetworkUtils.autodownloadNetworkAvailable()) {
|
ClientConfig.initialize(context);
|
||||||
|
if (NetworkUtils.autodownloadNetworkAvailable()) {
|
||||||
Log.d(TAG, "auto-dl network available, starting auto-download");
|
Log.d(TAG, "auto-dl network available, starting auto-download");
|
||||||
DBTasks.autodownloadUndownloadedItems(context);
|
DBTasks.autodownloadUndownloadedItems(context);
|
||||||
} else { // if new network is Wi-Fi, finish ongoing downloads,
|
} else { // if new network is Wi-Fi, finish ongoing downloads,
|
||||||
|
|
|
@ -3,10 +3,9 @@ package de.danoeh.antennapod.receiver;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.BatteryManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.BuildConfig;
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
|
@ -25,6 +24,7 @@ public class PowerConnectionReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
Log.d(TAG, "charging intent: " + action);
|
Log.d(TAG, "charging intent: " + action);
|
||||||
|
|
||||||
|
ClientConfig.initialize(context);
|
||||||
if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
|
if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
|
||||||
Log.d(TAG, "charging, starting auto-download");
|
Log.d(TAG, "charging, starting auto-download");
|
||||||
// we're plugged in, this is a great time to auto-download if everything else is
|
// we're plugged in, this is a great time to auto-download if everything else is
|
||||||
|
|
|
@ -9,8 +9,8 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import de.danoeh.antennapod.BuildConfig;
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
|
@ -27,29 +27,30 @@ public class SPAReceiver extends BroadcastReceiver{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (TextUtils.equals(intent.getAction(), ACTION_SP_APPS_QUERY_FEEDS_REPSONSE)) {
|
if (!TextUtils.equals(intent.getAction(), ACTION_SP_APPS_QUERY_FEEDS_REPSONSE)) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Received SP_APPS_QUERY_RESPONSE");
|
return;
|
||||||
if (intent.hasExtra(ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA)) {
|
}
|
||||||
String[] feedUrls = intent.getStringArrayExtra(ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA);
|
Log.d(TAG, "Received SP_APPS_QUERY_RESPONSE");
|
||||||
if (feedUrls != null) {
|
if (!intent.hasExtra(ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA)) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Received feeds list: " + Arrays.toString(feedUrls));
|
Log.e(TAG, "Received invalid SP_APPS_QUERY_RESPONSE: Contains no extra");
|
||||||
for (String url : feedUrls) {
|
return;
|
||||||
Feed f = new Feed(url, null);
|
}
|
||||||
try {
|
String[] feedUrls = intent.getStringArrayExtra(ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA);
|
||||||
DownloadRequester.getInstance().downloadFeed(context, f);
|
if (feedUrls == null) {
|
||||||
} catch (DownloadRequestException e) {
|
Log.e(TAG, "Received invalid SP_APPS_QUERY_REPSONSE: extra was null");
|
||||||
Log.e(TAG, "Error while trying to add feed " + url);
|
return;
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
Log.d(TAG, "Received feeds list: " + Arrays.toString(feedUrls));
|
||||||
}
|
ClientConfig.initialize(context);
|
||||||
Toast.makeText(context, R.string.sp_apps_importing_feeds_msg, Toast.LENGTH_LONG).show();
|
for (String url : feedUrls) {
|
||||||
|
Feed f = new Feed(url, null);
|
||||||
} else {
|
try {
|
||||||
Log.e(TAG, "Received invalid SP_APPS_QUERY_REPSONSE: extra was null");
|
DownloadRequester.getInstance().downloadFeed(context, f);
|
||||||
}
|
} catch (DownloadRequestException e) {
|
||||||
} else {
|
Log.e(TAG, "Error while trying to add feed " + url);
|
||||||
Log.e(TAG, "Received invalid SP_APPS_QUERY_RESPONSE: Contains no extra");
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Toast.makeText(context, R.string.sp_apps_importing_feeds_msg, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
package de.danoeh.antennapod.core;
|
package de.danoeh.antennapod.core;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores callbacks for core classes like Services, DB classes etc. and other configuration variables.
|
* Stores callbacks for core classes like Services, DB classes etc. and other configuration variables.
|
||||||
* Apps using the core module of AntennaPod should register implementations of all interfaces here.
|
* Apps using the core module of AntennaPod should register implementations of all interfaces here.
|
||||||
|
@ -22,4 +29,19 @@ public class ClientConfig {
|
||||||
public static FlattrCallbacks flattrCallbacks;
|
public static FlattrCallbacks flattrCallbacks;
|
||||||
|
|
||||||
public static DBTasksCallbacks dbTasksCallbacks;
|
public static DBTasksCallbacks dbTasksCallbacks;
|
||||||
|
|
||||||
|
private static boolean initialized = false;
|
||||||
|
|
||||||
|
public static synchronized void initialize(Context context) {
|
||||||
|
if(initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PodDBAdapter.init(context);
|
||||||
|
UserPreferences.init(context);
|
||||||
|
UpdateManager.init(context);
|
||||||
|
PlaybackPreferences.init(context);
|
||||||
|
NetworkUtils.init(context);
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package de.danoeh.antennapod;
|
package de.danoeh.antennapod.core;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
|
@ -6,7 +6,7 @@ import android.content.Intent;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
|
||||||
/** Listens for events that make it necessary to reset the update alarm. */
|
/** Listens for events that make it necessary to reset the update alarm. */
|
||||||
|
@ -22,8 +22,7 @@ public class AlarmUpdateReceiver extends BroadcastReceiver {
|
||||||
} else if (TextUtils.equals(intent.getAction(), Intent.ACTION_PACKAGE_REPLACED)) {
|
} else if (TextUtils.equals(intent.getAction(), Intent.ACTION_PACKAGE_REPLACED)) {
|
||||||
Log.d(TAG, "Resetting update alarm after app upgrade");
|
Log.d(TAG, "Resetting update alarm after app upgrade");
|
||||||
}
|
}
|
||||||
PlaybackPreferences.init(context);
|
ClientConfig.initialize(context);
|
||||||
UserPreferences.init(context);
|
|
||||||
UserPreferences.restartUpdateAlarm(false);
|
UserPreferences.restartUpdateAlarm(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
|
@ -19,6 +20,7 @@ public class FeedUpdateReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.d(TAG, "Received intent");
|
Log.d(TAG, "Received intent");
|
||||||
|
ClientConfig.initialize(context);
|
||||||
if (NetworkUtils.isDownloadAllowed()) {
|
if (NetworkUtils.isDownloadAllowed()) {
|
||||||
DBTasks.refreshAllFeeds(context, null);
|
DBTasks.refreshAllFeeds(context, null);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,7 +5,8 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import de.danoeh.antennapod.core.BuildConfig;
|
|
||||||
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||||
|
|
||||||
/** Receives media button events. */
|
/** Receives media button events. */
|
||||||
|
@ -17,10 +18,10 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Received intent");
|
Log.d(TAG, "Received intent");
|
||||||
KeyEvent event = (KeyEvent) intent.getExtras().get(
|
KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
|
||||||
Intent.EXTRA_KEY_EVENT);
|
|
||||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
|
ClientConfig.initialize(context);
|
||||||
Intent serviceIntent = new Intent(context, PlaybackService.class);
|
Intent serviceIntent = new Intent(context, PlaybackService.class);
|
||||||
int keycode = event.getKeyCode();
|
int keycode = event.getKeyCode();
|
||||||
serviceIntent.putExtra(EXTRA_KEYCODE, keycode);
|
serviceIntent.putExtra(EXTRA_KEYCODE, keycode);
|
||||||
|
|
Loading…
Reference in New Issue