Review changes #2
This commit is contained in:
parent
f66e19845c
commit
a97b524a05
@ -807,11 +807,6 @@ public class UserPreferences {
|
||||
private static void restartUpdateIntervalAlarm(long triggerAtMillis, long intervalMillis) {
|
||||
Log.d(TAG, "Restarting update alarm.");
|
||||
|
||||
if (intervalMillis <= 0) {
|
||||
Log.d(TAG, "Automatic update was deactivated");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
|
||||
if (jobScheduler != null) {
|
||||
@ -820,6 +815,12 @@ public class UserPreferences {
|
||||
JobInfo.Builder builder = getFeedUpdateJobBuilder();
|
||||
builder.setPeriodic(intervalMillis);
|
||||
jobScheduler.cancel(JOB_ID_FEED_UPDATE);
|
||||
|
||||
if (intervalMillis <= 0) {
|
||||
Log.d(TAG, "Automatic update was deactivated");
|
||||
return;
|
||||
}
|
||||
|
||||
jobScheduler.schedule(builder.build());
|
||||
Log.d(TAG, "JobScheduler was set at interval " + intervalMillis);
|
||||
} else {
|
||||
@ -833,6 +834,12 @@ public class UserPreferences {
|
||||
Intent intent = new Intent(context, FeedUpdateReceiver.class);
|
||||
PendingIntent updateIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
alarmManager.cancel(updateIntent);
|
||||
|
||||
if (intervalMillis <= 0) {
|
||||
Log.d(TAG, "Automatic update was deactivated");
|
||||
return;
|
||||
}
|
||||
|
||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||
SystemClock.elapsedRealtime() + triggerAtMillis,
|
||||
updateIntent);
|
||||
|
@ -7,8 +7,7 @@ import android.util.Log;
|
||||
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.core.util.FeedUpdateUtils;
|
||||
|
||||
/**
|
||||
* Refreshes all feeds when it receives an intent
|
||||
@ -21,11 +20,7 @@ public class FeedUpdateReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "Received intent");
|
||||
ClientConfig.initialize(context);
|
||||
if (NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()) {
|
||||
DBTasks.refreshAllFeeds(context, null);
|
||||
} else {
|
||||
Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
|
||||
}
|
||||
FeedUpdateUtils.startAutoUpdate(context);
|
||||
UserPreferences.restartUpdateAlarm(false);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.util.FeedUpdateUtils;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public class FeedUpdateJobService extends JobService {
|
||||
@ -17,7 +17,7 @@ public class FeedUpdateJobService extends JobService {
|
||||
public boolean onStartJob(JobParameters params) {
|
||||
Log.d(TAG, "Job started");
|
||||
ClientConfig.initialize(getApplicationContext());
|
||||
DBTasks.refreshAllFeeds(getApplicationContext(), null);
|
||||
FeedUpdateUtils.startAutoUpdate(getApplicationContext());
|
||||
UserPreferences.restartUpdateAlarm(false);
|
||||
return true;
|
||||
}
|
||||
|
@ -124,6 +124,7 @@ public final class DBTasks {
|
||||
media);
|
||||
}
|
||||
}
|
||||
// Needs to be called even if the service is already running to deliver the new media intent
|
||||
PlaybackService.startService(context, media, startWhenPrepared, shouldStream);
|
||||
if (showPlayer) {
|
||||
// Launch media player
|
||||
|
@ -0,0 +1,21 @@
|
||||
package de.danoeh.antennapod.core.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
|
||||
public class FeedUpdateUtils {
|
||||
private static final String TAG = "FeedUpdateUtils";
|
||||
|
||||
private FeedUpdateUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static void startAutoUpdate(Context context) {
|
||||
if (NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()) {
|
||||
DBTasks.refreshAllFeeds(context, null);
|
||||
} else {
|
||||
Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user