Add geofence and geofence api overloads

pull/935/head
Alex Baker 6 years ago
parent 84c83a9fac
commit a39e29a230

@ -7,7 +7,6 @@ import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform; import static com.google.common.collect.Lists.transform;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import android.annotation.SuppressLint;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -46,8 +45,11 @@ public class GeofenceApi {
register(locationDao.getActiveGeofences(taskId)); register(locationDao.getActiveGeofences(taskId));
} }
@SuppressLint("MissingPermission") public void register(Location location) {
public void register(final List<Location> locations) { register(singletonList(location));
}
private void register(final List<Location> locations) {
if (!permissionChecker.canAccessLocation()) { if (!permissionChecker.canAccessLocation()) {
return; return;
} }

@ -13,6 +13,8 @@ import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table; import com.todoroo.andlib.data.Table;
import java.io.Serializable; import java.io.Serializable;
import org.tasks.R;
import org.tasks.preferences.Preferences;
@Entity(tableName = TABLE_NAME, indices = @Index(name = "geo_task", value = "task")) @Entity(tableName = TABLE_NAME, indices = @Index(name = "geo_task", value = "task"))
public class Geofence implements Serializable, Parcelable { public class Geofence implements Serializable, Parcelable {
@ -63,6 +65,16 @@ public class Geofence implements Serializable, Parcelable {
this.task = task; this.task = task;
} }
@Ignore
public Geofence(String place, Preferences preferences) {
this.place = place;
int defaultReminders =
preferences.getIntegerFromString(R.string.p_default_location_reminder_key, 1);
arrival = defaultReminders == 1 || defaultReminders == 3;
departure = defaultReminders == 2 || defaultReminders == 3;
radius = preferences.getInt(R.string.p_default_location_radius, 250);
}
@Ignore @Ignore
public Geofence(String place, boolean arrival, boolean departure, int radius) { public Geofence(String place, boolean arrival, boolean departure, int radius) {
this.place = place; this.place = place;

@ -261,7 +261,7 @@ public class LocationControlSet extends TaskEditControlFragment {
geofence.setTask(task.getId()); geofence.setTask(task.getId());
geofence.setPlace(place.getUid()); geofence.setPlace(place.getUid());
geofence.setId(locationDao.insert(geofence)); geofence.setId(locationDao.insert(geofence));
geofenceApi.register(Collections.singletonList(location)); geofenceApi.register(location);
} }
task.setModificationDate(DateUtilities.now()); task.setModificationDate(DateUtilities.now());
} }
@ -281,14 +281,7 @@ public class LocationControlSet extends TaskEditControlFragment {
Place place = data.getParcelableExtra(EXTRA_PLACE); Place place = data.getParcelableExtra(EXTRA_PLACE);
Geofence geofence; Geofence geofence;
if (location == null) { if (location == null) {
int defaultReminders = geofence = new Geofence(place.getUid(), preferences);
preferences.getIntegerFromString(R.string.p_default_location_reminder_key, 1);
geofence =
new Geofence(
place.getUid(),
defaultReminders == 1 || defaultReminders == 3,
defaultReminders == 2 || defaultReminders == 3,
preferences.getInt(R.string.p_default_location_radius, 250));
} else { } else {
Geofence existing = location.geofence; Geofence existing = location.geofence;
geofence = geofence =

Loading…
Cancel
Save