blob: f9c10041eec6f02a2d6fe31ee324b02fbacf359f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package de.danoeh.antennapod.spa;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import android.util.Log;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.receiver.SPAReceiver;
/**
* Provides methods related to AntennaPodSP (https://github.com/danieloeh/AntennaPodSP)
*/
public class SPAUtil {
private static final String TAG = "SPAUtil";
private static final String PREF_HAS_QUERIED_SP_APPS = "prefSPAUtil.hasQueriedSPApps";
private SPAUtil() {
}
/**
* Sends an ACTION_SP_APPS_QUERY_FEEDS intent to all AntennaPod Single Purpose apps.
* The receiving single purpose apps will then send their feeds back to AntennaPod via an
* ACTION_SP_APPS_QUERY_FEEDS_RESPONSE intent.
* This intent will only be sent once.
*
* @return True if an intent was sent, false otherwise (for example if the intent has already been
* sent before.
*/
public static synchronized boolean sendSPAppsQueryFeedsIntent(Context context) {
assert context != null : "context = null";
final Context appContext = context.getApplicationContext();
if (appContext == null) {
Log.wtf(TAG, "Unable to get application context");
return false;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
if (!prefs.getBoolean(PREF_HAS_QUERIED_SP_APPS, false)) {
appContext.sendBroadcast(new Intent(SPAReceiver.ACTION_SP_APPS_QUERY_FEEDS));
if (BuildConfig.DEBUG) Log.d(TAG, "Sending SP_APPS_QUERY_FEEDS intent");
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PREF_HAS_QUERIED_SP_APPS, true);
editor.apply();
return true;
} else {
return false;
}
}
}
|