mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
no more conversion, cleanups
This commit is contained in:
parent
c1efa0e04f
commit
e4d541ab2b
@ -10,6 +10,7 @@ import com.fastaccess.R;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 10 Nov 2016, 3:43 PM
|
||||
@ -110,19 +111,19 @@ public class PrefGetter {
|
||||
return PrefHelper.getBoolean("recylerViewAnimation");
|
||||
}
|
||||
|
||||
public static int getNotificationTaskDuration(@NonNull Context context) {
|
||||
public static long getNotificationTaskDuration(@NonNull Context context) {
|
||||
String s = PrefHelper.getString("notificationTime");
|
||||
if (!InputHelper.isEmpty(s)) {
|
||||
if (s.equalsIgnoreCase(context.getString(R.string.thirty_minutes))) {
|
||||
return 30 * 60;
|
||||
return TimeUnit.MINUTES.toMillis(30);
|
||||
} else if (s.equalsIgnoreCase(context.getString(R.string.twenty_minutes))) {
|
||||
return 20 * 60;
|
||||
return TimeUnit.MINUTES.toMillis(20);
|
||||
} else if (s.equalsIgnoreCase(context.getString(R.string.ten_minutes))) {
|
||||
return 10 * 60;
|
||||
return TimeUnit.MINUTES.toMillis(10);
|
||||
} else if (s.equalsIgnoreCase(context.getString(R.string.five_minutes))) {
|
||||
return 5 * 60;
|
||||
return TimeUnit.MINUTES.toMillis(5);
|
||||
} else if (s.equalsIgnoreCase(context.getString(R.string.one_minute))) {
|
||||
return 60;
|
||||
return TimeUnit.MINUTES.toMillis(1);
|
||||
} else if (s.equalsIgnoreCase(context.getString(R.string.turn_off))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ import rx.schedulers.Schedulers;
|
||||
|
||||
public class NotificationSchedulerJobTask extends JobService {
|
||||
private final static int JOB_ID_EVERY_30_MINS = 1;
|
||||
private final static int THIRTY_MINUTES = 30 * 60;//in seconds
|
||||
private final static long THIRTY_MINUTES = TimeUnit.MINUTES.toMillis(30);
|
||||
private static final String NOTIFICATION_GROUP_ID = "FastHub";
|
||||
|
||||
@Override public boolean onStartJob(JobParameters job) {
|
||||
@ -52,7 +52,7 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
if (item != null) {
|
||||
onSave(item.getItems());
|
||||
}
|
||||
fastScheduleJob(getApplicationContext());
|
||||
scheduleJob(getApplicationContext());
|
||||
jobFinished(job, false);
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
@ -64,20 +64,11 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
}
|
||||
|
||||
public static void scheduleJob(@NonNull Context context) {
|
||||
int duration = PrefGetter.getNotificationTaskDuration(context);
|
||||
long duration = PrefGetter.getNotificationTaskDuration(context);
|
||||
scheduleJob(context, duration == 0 ? THIRTY_MINUTES : duration, false);
|
||||
}
|
||||
|
||||
public static void fastScheduleJob(@NonNull Context context) {
|
||||
int duration = PrefGetter.getNotificationTaskDuration(context);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
if (TimeUnit.SECONDS.toMillis(duration) < JobInfo.getMinPeriodMillis()) {
|
||||
scheduleJob(context, duration, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleJob(@NonNull Context context, int duration, boolean cancel) {
|
||||
public static void scheduleJob(@NonNull Context context, long duration, boolean cancel) {
|
||||
JobScheduler mJobScheduler = (JobScheduler)
|
||||
context.getSystemService( Context.JOB_SCHEDULER_SERVICE );
|
||||
if (cancel) mJobScheduler.cancel(JOB_ID_EVERY_30_MINS);
|
||||
@ -94,10 +85,10 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
|
||||
TimeUnit.SECONDS.toMillis(duration) < JobInfo.getMinPeriodMillis()) {
|
||||
builder.setMinimumLatency(TimeUnit.SECONDS.toMillis(duration));
|
||||
duration < JobInfo.getMinPeriodMillis()) {
|
||||
builder.setMinimumLatency(duration);
|
||||
} else {
|
||||
builder.setPeriodic(TimeUnit.SECONDS.toMillis(duration));
|
||||
builder.setPeriodic(duration);
|
||||
}
|
||||
|
||||
if (mJobScheduler.schedule(builder.build()) <= 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user