summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2018-05-26 23:30:06 +0200
committerByteHamster <info@bytehamster.com>2018-05-26 23:30:06 +0200
commit443f6315fa2935c413dcfdf2c6cbc96a7a330f84 (patch)
tree60efad1e615e31816a597fa55790dcb03832e69d /core/src
parentb3e02e215cadafa3d76120f92a022d5f714bcd7e (diff)
downloadAntennaPod-443f6315fa2935c413dcfdf2c6cbc96a7a330f84.zip
Moved methods into AutoUpdateManager
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java41
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java43
2 files changed, 41 insertions, 43 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
index 48efdc84c..44b2fa2b2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
@@ -2,7 +2,6 @@ package de.danoeh.antennapod.core.preferences;
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
@@ -25,7 +24,6 @@ import java.io.IOException;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Calendar;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -776,49 +774,14 @@ public class UserPreferences {
int[] timeOfDay = getUpdateTimeOfDay();
Log.d(TAG, "timeOfDay: " + Arrays.toString(timeOfDay));
if (timeOfDay.length == 2) {
- restartUpdateTimeOfDayAlarm(timeOfDay[0], timeOfDay[1]);
+ AutoUpdateManager.restartUpdateTimeOfDayAlarm(context, timeOfDay[0], timeOfDay[1]);
} else {
long milliseconds = getUpdateInterval();
long startTrigger = milliseconds;
if (now) {
startTrigger = TimeUnit.SECONDS.toMillis(10);
}
- restartUpdateIntervalAlarm(startTrigger, milliseconds);
- }
- }
-
- /**
- * Sets the interval in which the feeds are refreshed automatically
- */
- private static void restartUpdateIntervalAlarm(long triggerAtMillis, long intervalMillis) {
- Log.d(TAG, "Restarting update alarm.");
-
- if (Build.VERSION.SDK_INT >= 24) {
- AutoUpdateManager.restartJobServiceInterval(context, intervalMillis);
- } else {
- AutoUpdateManager.restartAlarmManagerInterval(context, triggerAtMillis, intervalMillis);
- }
- }
-
- /**
- * Sets time of day the feeds are refreshed automatically
- */
- private static void restartUpdateTimeOfDayAlarm(int hoursOfDay, int minute) {
- Log.d(TAG, "Restarting update alarm.");
-
- Calendar now = Calendar.getInstance();
- Calendar alarm = (Calendar)now.clone();
- alarm.set(Calendar.HOUR_OF_DAY, hoursOfDay);
- alarm.set(Calendar.MINUTE, minute);
- if (alarm.before(now) || alarm.equals(now)) {
- alarm.add(Calendar.DATE, 1);
- }
-
- if (Build.VERSION.SDK_INT >= 24) {
- long triggerAtMillis = alarm.getTimeInMillis() - now.getTimeInMillis();
- AutoUpdateManager.restartJobServiceTriggerAt(context, triggerAtMillis);
- } else {
- AutoUpdateManager.restartAlarmManagerTimeOfDay(context, alarm);
+ AutoUpdateManager.restartUpdateIntervalAlarm(context, startTrigger, milliseconds);
}
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java
index 83fe8f137..ad723c685 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java
@@ -25,6 +25,41 @@ public class AutoUpdateManager {
}
+ /**
+ * Sets the interval in which the feeds are refreshed automatically
+ */
+ public static void restartUpdateIntervalAlarm(Context context, long triggerAtMillis, long intervalMillis) {
+ Log.d(TAG, "Restarting update alarm.");
+
+ if (Build.VERSION.SDK_INT >= 24) {
+ restartJobServiceInterval(context, intervalMillis);
+ } else {
+ restartAlarmManagerInterval(context, triggerAtMillis, intervalMillis);
+ }
+ }
+
+ /**
+ * Sets time of day the feeds are refreshed automatically
+ */
+ public static void restartUpdateTimeOfDayAlarm(Context context, int hoursOfDay, int minute) {
+ Log.d(TAG, "Restarting update alarm.");
+
+ Calendar now = Calendar.getInstance();
+ Calendar alarm = (Calendar)now.clone();
+ alarm.set(Calendar.HOUR_OF_DAY, hoursOfDay);
+ alarm.set(Calendar.MINUTE, minute);
+ if (alarm.before(now) || alarm.equals(now)) {
+ alarm.add(Calendar.DATE, 1);
+ }
+
+ if (Build.VERSION.SDK_INT >= 24) {
+ long triggerAtMillis = alarm.getTimeInMillis() - now.getTimeInMillis();
+ restartJobServiceTriggerAt(context, triggerAtMillis);
+ } else {
+ restartAlarmManagerTimeOfDay(context, alarm);
+ }
+ }
+
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static JobInfo.Builder getFeedUpdateJobBuilder(Context context) {
ComponentName serviceComponent = new ComponentName(context, FeedUpdateJobService.class);
@@ -35,7 +70,7 @@ public class AutoUpdateManager {
}
@RequiresApi(api = Build.VERSION_CODES.N)
- public static void restartJobServiceInterval(Context context, long intervalMillis) {
+ private static void restartJobServiceInterval(Context context, long intervalMillis) {
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
if (jobScheduler == null) {
Log.d(TAG, "JobScheduler was null.");
@@ -61,7 +96,7 @@ public class AutoUpdateManager {
Log.d(TAG, "JobScheduler was set at interval " + intervalMillis);
}
- public static void restartAlarmManagerInterval(Context context, long triggerAtMillis, long intervalMillis) {
+ private static void restartAlarmManagerInterval(Context context, long triggerAtMillis, long intervalMillis) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (alarmManager == null) {
@@ -85,7 +120,7 @@ public class AutoUpdateManager {
}
@RequiresApi(api = Build.VERSION_CODES.N)
- public static void restartJobServiceTriggerAt(Context context, long triggerAtMillis) {
+ private static void restartJobServiceTriggerAt(Context context, long triggerAtMillis) {
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
if (jobScheduler == null) {
Log.d(TAG, "JobScheduler was null.");
@@ -99,7 +134,7 @@ public class AutoUpdateManager {
Log.d(TAG, "JobScheduler was set for " + triggerAtMillis);
}
- public static void restartAlarmManagerTimeOfDay(Context context, Calendar alarm) {
+ private static void restartAlarmManagerTimeOfDay(Context context, Calendar alarm) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (alarmManager == null) {