Added intent to set poll interval

pull/197/head
M66B 5 years ago
parent 3d632fd900
commit a7ec00e6ea

@ -2259,6 +2259,14 @@ To enable/disable a specific account:
Note that disabling an account will hide the account and all associated folders and messages. Note that disabling an account will hide the account and all associated folders and messages.
To set the poll interval:
```
(adb shell) adb shell am start-foreground-service -a eu.faircode.email.INTERVAL --ei minutes nnn
```
Where *nnn* is one of 0, 15, 30, 60, 120, 240, 480, 1440.
You can automatically send commands with for example [Tasker](https://tasker.joaoapps.com/userguide/en/intents.html): You can automatically send commands with for example [Tasker](https://tasker.joaoapps.com/userguide/en/intents.html):
``` ```

@ -355,6 +355,7 @@
<action android:name="${applicationId}.POLL" /> <action android:name="${applicationId}.POLL" />
<action android:name="${applicationId}.ENABLE" /> <action android:name="${applicationId}.ENABLE" />
<action android:name="${applicationId}.DISABLE" /> <action android:name="${applicationId}.DISABLE" />
<action android:name="${applicationId}.INTERVAL" />
<action android:name="${applicationId}.DISCONNECT.ME" /> <action android:name="${applicationId}.DISCONNECT.ME" />
</intent-filter> </intent-filter>
</service> </service>

@ -41,6 +41,7 @@ public class ServiceExternal extends Service {
private static final String ACTION_POLL = BuildConfig.APPLICATION_ID + ".POLL"; private static final String ACTION_POLL = BuildConfig.APPLICATION_ID + ".POLL";
private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE"; private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE";
private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE"; private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE";
private static final String ACTION_INTERVAL = BuildConfig.APPLICATION_ID + ".INTERVAL";
private static final String ACTION_DISCONNECT_ME = BuildConfig.APPLICATION_ID + ".DISCONNECT.ME"; private static final String ACTION_DISCONNECT_ME = BuildConfig.APPLICATION_ID + ".DISCONNECT.ME";
static final int PI_WIDGET_ENABLE = 1; static final int PI_WIDGET_ENABLE = 1;
@ -48,6 +49,7 @@ public class ServiceExternal extends Service {
// adb shell am start-foreground-service -a eu.faircode.email.POLL --es account Gmail // adb shell am start-foreground-service -a eu.faircode.email.POLL --es account Gmail
// adb shell am start-foreground-service -a eu.faircode.email.ENABLE --es account Gmail // adb shell am start-foreground-service -a eu.faircode.email.ENABLE --es account Gmail
// adb shell am start-foreground-service -a eu.faircode.email.DISABLE --es account Gmail // adb shell am start-foreground-service -a eu.faircode.email.DISABLE --es account Gmail
// adb shell am start-foreground-service -a eu.faircode.email.INTERVAL --ei minutes {0, 15, 30, 60, 120, 240, 480, 1440}
// adb shell am start-foreground-service -a eu.faircode.email.DISCONNECT // adb shell am start-foreground-service -a eu.faircode.email.DISCONNECT
private static final ExecutorService executor = private static final ExecutorService executor =
@ -96,6 +98,9 @@ public class ServiceExternal extends Service {
case ACTION_DISABLE: case ACTION_DISABLE:
set(context, intent); set(context, intent);
break; break;
case ACTION_INTERVAL:
interval(context, intent);
break;
case ACTION_DISCONNECT_ME: case ACTION_DISCONNECT_ME:
disconnect(context, intent); disconnect(context, intent);
break; break;
@ -163,6 +168,17 @@ public class ServiceExternal extends Service {
ServiceSynchronize.eval(context, "external poll account=" + accountName); ServiceSynchronize.eval(context, "external poll account=" + accountName);
} }
private static void interval(Context context, Intent intent) {
int minutes = intent.getIntExtra("minutes", 0);
int[] values = context.getResources().getIntArray(R.array.pollIntervalValues);
for (int value : values)
if (value >= minutes) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt("poll_interval", value).apply();
break;
}
}
private static void set(Context context, Intent intent) { private static void set(Context context, Intent intent) {
String accountName = intent.getStringExtra("account"); String accountName = intent.getStringExtra("account");
boolean enabled = ACTION_ENABLE.equals(intent.getAction()); boolean enabled = ACTION_ENABLE.equals(intent.getAction());

Loading…
Cancel
Save