Fixed AutoExports running even when they were disabled.

This commit is contained in:
Jan Christian Grünhage 2017-01-30 20:45:13 +01:00
parent 6dcfb36482
commit c52f99fbf0
Signed by: jcgruenhage
GPG key ID: 321A67D9EE8BC3E1
2 changed files with 11 additions and 5 deletions

View file

@ -12,6 +12,7 @@ import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences;
public class ExportAllJob extends JobService {
public static final String TAG = "AutoGPME_ExportJob";
public static final int AUTO_EXPORT_JOB_ID = 0;
/**
@ -21,27 +22,33 @@ public class ExportAllJob extends JobService {
*/
public static void scheduleExport(final Context pContext) {
PlayMusicExporterPreferences.init(pContext);
JobScheduler lJobScheduler = (JobScheduler) pContext.getSystemService(JOB_SCHEDULER_SERVICE);
if (PlayMusicExporterPreferences.getAutoExportEnabled()) {
long lInterval = PlayMusicExporterPreferences.getAutoExportFrequency();
boolean lRequireUnmeteredNetwork = PlayMusicExporterPreferences.getAutoExportRequireUnmetered();
boolean lRequireCharging = PlayMusicExporterPreferences.getAutoExportRequireCharging();
JobScheduler lJobScheduler = (JobScheduler) pContext.getSystemService(JOB_SCHEDULER_SERVICE);
ComponentName lComponentName = new ComponentName(pContext, ExportAllJob.class);
JobInfo.Builder lBuilder = new JobInfo.Builder(42, lComponentName);
JobInfo.Builder lBuilder = new JobInfo.Builder(AUTO_EXPORT_JOB_ID, lComponentName);
lBuilder.setPeriodic(lInterval);
lBuilder.setPersisted(true);
if (lRequireUnmeteredNetwork)
lBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
lBuilder.setRequiresCharging(lRequireCharging);
lJobScheduler.schedule(lBuilder.build());
} else {
lJobScheduler.cancel(AUTO_EXPORT_JOB_ID);
}
}
@Override
public boolean onStartJob(JobParameters params) {
PlayMusicExporterPreferences.init(this.getApplicationContext());
Log.i(TAG, "Started Job: " + params.toString());
ExportAllService.startExport(this);
if (PlayMusicExporterPreferences.getAutoExportEnabled()) {
ExportAllService.startExport(this);
} else {
scheduleExport(getApplicationContext());
}
return true;
}

View file

@ -5,7 +5,6 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.PowerManager;
import android.support.v4.provider.DocumentFile;
import android.util.Log;
import java.util.List;