Wakeful broadcasts for reminders

Downgrading AS to punt on some proguard issues
pull/529/merge
Alex Baker 7 years ago
parent 7292cd2c05
commit 6a8be52c78

@ -7,13 +7,10 @@ task wrapper(type: Wrapper) {
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
classpath 'com.android.tools.build:gradle:2.3.2'
}
}
@ -37,6 +34,9 @@ android {
versionName "4.9.13"
targetSdkVersion 25
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
signingConfigs {
@ -46,6 +46,7 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
incremental false
}
buildTypes {
@ -114,9 +115,7 @@ dependencies {
annotationProcessor "com.jakewharton:butterknife-compiler:${BUTTERKNIFE_VERSION}"
compile "com.jakewharton:butterknife:${BUTTERKNIFE_VERSION}"
debugCompile ("com.facebook.stetho:stetho:${STETHO_VERSION}") {
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}
debugCompile "com.facebook.stetho:stetho:${STETHO_VERSION}"
debugCompile "com.facebook.stetho:stetho-timber:${STETHO_VERSION}@aar"
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
//noinspection GradleCompatible

@ -461,6 +461,14 @@
android:name=".jobs.ReminderJob"
android:exported="false" />
<receiver
android:name=".jobs.AlarmJobBroadcast"
android:exported="false" />
<receiver
android:name=".jobs.ReminderJobBroadcast"
android:exported="false" />
<!-- Uses Library -->
<uses-library
android:name="com.google.android.maps"

@ -1,5 +1,7 @@
package org.tasks.jobs;
import android.content.Intent;
import com.todoroo.astrid.alarms.AlarmService;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
@ -11,7 +13,7 @@ import org.tasks.preferences.Preferences;
import javax.inject.Inject;
public class AlarmJob extends Job {
public class AlarmJob extends WakefulJob {
public static final String TAG = "job_alarm";
@ -45,4 +47,9 @@ public class AlarmJob extends Job {
protected void inject(IntentServiceComponent component) {
component.inject(this);
}
@Override
protected void completeWakefulIntent(Intent intent) {
AlarmJobBroadcast.completeWakefulIntent(intent);
}
}

@ -0,0 +1,12 @@
package org.tasks.jobs;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
public class AlarmJobBroadcast extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
startWakefulService(context, new Intent(context, AlarmJob.class));
}
}

@ -35,19 +35,19 @@ public class JobManager {
public void scheduleRefresh(long time) {
Timber.d("%s: %s", RefreshJob.TAG, printTimestamp(time));
alarmManager.noWakeup(adjust(time), getPendingIntent(RefreshJob.class));
alarmManager.noWakeup(adjust(time), getPendingService(RefreshJob.class));
}
public void scheduleMidnightRefresh() {
long time = nextMidnight();
Timber.d("%s: %s", MidnightRefreshJob.TAG, printTimestamp(time));
alarmManager.noWakeup(adjust(time), getPendingIntent(MidnightRefreshJob.class));
alarmManager.noWakeup(adjust(time), getPendingService(MidnightRefreshJob.class));
}
public void scheduleMidnightBackup() {
long time = nextMidnight();
Timber.d("%s: %s", BackupJob.TAG, printTimestamp(time));
alarmManager.wakeup(adjust(time), getPendingIntent(BackupJob.class));
alarmManager.noWakeup(adjust(time), getPendingService(BackupJob.class));
}
public void cancel(String tag) {
@ -62,17 +62,21 @@ public class JobManager {
private PendingIntent getPendingIntent(String tag) {
switch (tag) {
case ReminderJob.TAG:
return getPendingIntent(ReminderJob.class);
return getPendingBroadcast(ReminderJobBroadcast.class);
case AlarmJob.TAG:
return getPendingIntent(AlarmJob.class);
return getPendingBroadcast(AlarmJobBroadcast.class);
case RefreshJob.TAG:
return getPendingIntent(RefreshJob.class);
return getPendingService(RefreshJob.class);
default:
throw new RuntimeException("Unexpected tag: " + tag);
}
}
private <T> PendingIntent getPendingIntent(Class<T> c) {
private <T> PendingIntent getPendingBroadcast(Class<T> c) {
return PendingIntent.getBroadcast(context, 0, new Intent(context, c), 0);
}
private <T> PendingIntent getPendingService(Class<T> c) {
return PendingIntent.getService(context, 0, new Intent(context, c), 0);
}
}

@ -1,5 +1,7 @@
package org.tasks.jobs;
import android.content.Intent;
import com.todoroo.astrid.reminders.ReminderService;
import org.tasks.Notifier;
@ -8,7 +10,7 @@ import org.tasks.preferences.Preferences;
import javax.inject.Inject;
public class ReminderJob extends Job {
public class ReminderJob extends WakefulJob {
public static final String TAG = "job_reminder";
@ -38,4 +40,9 @@ public class ReminderJob extends Job {
protected void scheduleNext() {
reminderService.scheduleNextJob();
}
@Override
protected void completeWakefulIntent(Intent intent) {
ReminderJobBroadcast.completeWakefulIntent(intent);
}
}

@ -0,0 +1,12 @@
package org.tasks.jobs;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
public class ReminderJobBroadcast extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
startWakefulService(context, new Intent(context, ReminderJob.class));
}
}

@ -0,0 +1,18 @@
package org.tasks.jobs;
import android.content.Intent;
public abstract class WakefulJob extends Job {
public WakefulJob(String name) {
super(name);
}
@Override
protected void onHandleIntent(Intent intent) {
super.onHandleIntent(intent);
completeWakefulIntent(intent);
}
protected abstract void completeWakefulIntent(Intent intent);
}
Loading…
Cancel
Save