mirror of
https://github.com/playmusicexporter/playmusicexporter
synced 2024-04-28 19:16:42 +00:00
Fixed AutoExports running even when they were disabled.
This commit is contained in:
parent
6dcfb36482
commit
c52f99fbf0
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue