mirror of https://github.com/tasks/tasks
Applying intellij-java-google-style
parent
d1bdd60a9c
commit
da10291b04
@ -1,21 +1,22 @@
|
|||||||
package org.tasks;
|
package org.tasks;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.tasks.caldav.CaldavAccountManager;
|
import org.tasks.caldav.CaldavAccountManager;
|
||||||
import org.tasks.preferences.Preferences;
|
import org.tasks.preferences.Preferences;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
public class FlavorSetup {
|
public class FlavorSetup {
|
||||||
private final CaldavAccountManager caldavAccountManager;
|
|
||||||
private final Preferences preferences;
|
|
||||||
|
|
||||||
@Inject
|
private final CaldavAccountManager caldavAccountManager;
|
||||||
public FlavorSetup(CaldavAccountManager caldavAccountManager, Preferences preferences) {
|
private final Preferences preferences;
|
||||||
this.caldavAccountManager = caldavAccountManager;
|
|
||||||
this.preferences = preferences;
|
@Inject
|
||||||
}
|
public FlavorSetup(CaldavAccountManager caldavAccountManager, Preferences preferences) {
|
||||||
|
this.caldavAccountManager = caldavAccountManager;
|
||||||
|
this.preferences = preferences;
|
||||||
|
}
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
caldavAccountManager.setBackgroundSynchronization(preferences.getBoolean(R.string.p_background_sync, true));
|
caldavAccountManager
|
||||||
}
|
.setBackgroundSynchronization(preferences.getBoolean(R.string.p_background_sync, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,97 +1,94 @@
|
|||||||
package org.tasks.analytics;
|
package org.tasks.analytics;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.google.android.gms.analytics.ExceptionParser;
|
import com.google.android.gms.analytics.ExceptionParser;
|
||||||
import com.google.android.gms.analytics.ExceptionReporter;
|
import com.google.android.gms.analytics.ExceptionReporter;
|
||||||
import com.google.android.gms.analytics.GoogleAnalytics;
|
import com.google.android.gms.analytics.GoogleAnalytics;
|
||||||
import com.google.android.gms.analytics.HitBuilders;
|
import com.google.android.gms.analytics.HitBuilders;
|
||||||
import com.google.android.gms.analytics.StandardExceptionParser;
|
import com.google.android.gms.analytics.StandardExceptionParser;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.tasks.BuildConfig;
|
import org.tasks.BuildConfig;
|
||||||
import org.tasks.R;
|
import org.tasks.R;
|
||||||
import org.tasks.injection.ApplicationScope;
|
import org.tasks.injection.ApplicationScope;
|
||||||
import org.tasks.injection.ForApplication;
|
import org.tasks.injection.ForApplication;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@ApplicationScope
|
@ApplicationScope
|
||||||
public class Tracker {
|
public class Tracker {
|
||||||
|
|
||||||
private final GoogleAnalytics analytics;
|
private final GoogleAnalytics analytics;
|
||||||
private final com.google.android.gms.analytics.Tracker tracker;
|
private final com.google.android.gms.analytics.Tracker tracker;
|
||||||
private final ExceptionParser exceptionParser;
|
private final ExceptionParser exceptionParser;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Tracker(@ForApplication Context context) {
|
public Tracker(@ForApplication Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
analytics = GoogleAnalytics.getInstance(context);
|
analytics = GoogleAnalytics.getInstance(context);
|
||||||
tracker = analytics.newTracker(R.xml.google_analytics);
|
tracker = analytics.newTracker(R.xml.google_analytics);
|
||||||
tracker.setAppVersion(Integer.toString(BuildConfig.VERSION_CODE));
|
tracker.setAppVersion(Integer.toString(BuildConfig.VERSION_CODE));
|
||||||
final StandardExceptionParser standardExceptionParser = new StandardExceptionParser(context, null);
|
final StandardExceptionParser standardExceptionParser = new StandardExceptionParser(context,
|
||||||
exceptionParser = (thread, throwable) -> {
|
null);
|
||||||
StringBuilder stack = new StringBuilder()
|
exceptionParser = (thread, throwable) -> {
|
||||||
.append(standardExceptionParser.getDescription(thread, throwable))
|
StringBuilder stack = new StringBuilder()
|
||||||
.append("\n")
|
.append(standardExceptionParser.getDescription(thread, throwable))
|
||||||
.append(throwable.getClass().getName())
|
.append("\n")
|
||||||
.append("\n");
|
.append(throwable.getClass().getName())
|
||||||
for (StackTraceElement element : throwable.getStackTrace()) {
|
.append("\n");
|
||||||
stack.append(element.toString())
|
for (StackTraceElement element : throwable.getStackTrace()) {
|
||||||
.append("\n");
|
stack.append(element.toString())
|
||||||
}
|
.append("\n");
|
||||||
return stack.toString();
|
}
|
||||||
};
|
return stack.toString();
|
||||||
ExceptionReporter reporter = new ExceptionReporter(
|
};
|
||||||
tracker,
|
ExceptionReporter reporter = new ExceptionReporter(
|
||||||
Thread.getDefaultUncaughtExceptionHandler(),
|
tracker,
|
||||||
context);
|
Thread.getDefaultUncaughtExceptionHandler(),
|
||||||
reporter.setExceptionParser(exceptionParser);
|
context);
|
||||||
Thread.setDefaultUncaughtExceptionHandler(reporter);
|
reporter.setExceptionParser(exceptionParser);
|
||||||
}
|
Thread.setDefaultUncaughtExceptionHandler(reporter);
|
||||||
|
}
|
||||||
public void setTrackingEnabled(boolean enabled) {
|
|
||||||
analytics.setAppOptOut(!enabled);
|
public void setTrackingEnabled(boolean enabled) {
|
||||||
}
|
analytics.setAppOptOut(!enabled);
|
||||||
|
}
|
||||||
public void reportException(Throwable t) {
|
|
||||||
reportException(Thread.currentThread(), t);
|
public void reportException(Throwable t) {
|
||||||
}
|
reportException(Thread.currentThread(), t);
|
||||||
|
}
|
||||||
public void reportException(Thread thread, Throwable t) {
|
|
||||||
Timber.e(t, t.getMessage());
|
public void reportException(Thread thread, Throwable t) {
|
||||||
tracker.send(new HitBuilders.ExceptionBuilder()
|
Timber.e(t, t.getMessage());
|
||||||
.setDescription(exceptionParser.getDescription(thread.getName(), t))
|
tracker.send(new HitBuilders.ExceptionBuilder()
|
||||||
.setFatal(false)
|
.setDescription(exceptionParser.getDescription(thread.getName(), t))
|
||||||
.build());
|
.setFatal(false)
|
||||||
}
|
.build());
|
||||||
|
}
|
||||||
public void reportEvent(Tracking.Events event) {
|
|
||||||
reportEvent(event, null);
|
public void reportEvent(Tracking.Events event) {
|
||||||
}
|
reportEvent(event, null);
|
||||||
|
}
|
||||||
public void reportEvent(Tracking.Events event, String label) {
|
|
||||||
reportEvent(event, event.action, label);
|
public void reportEvent(Tracking.Events event, String label) {
|
||||||
}
|
reportEvent(event, event.action, label);
|
||||||
|
}
|
||||||
public void reportEvent(Tracking.Events event, int action, String label) {
|
|
||||||
reportEvent(event, context.getString(action), label);
|
public void reportEvent(Tracking.Events event, int action, String label) {
|
||||||
}
|
reportEvent(event, context.getString(action), label);
|
||||||
|
}
|
||||||
public void reportEvent(Tracking.Events event, String action, String label) {
|
|
||||||
reportEvent(event.category, action, label);
|
public void reportEvent(Tracking.Events event, String action, String label) {
|
||||||
}
|
reportEvent(event.category, action, label);
|
||||||
|
}
|
||||||
private void reportEvent(int category, String action, String label) {
|
|
||||||
HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder()
|
private void reportEvent(int category, String action, String label) {
|
||||||
.setCategory(context.getString(category))
|
HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder()
|
||||||
.setAction(action);
|
.setCategory(context.getString(category))
|
||||||
if (!Strings.isNullOrEmpty(label)) {
|
.setAction(action);
|
||||||
eventBuilder.setLabel(label);
|
if (!Strings.isNullOrEmpty(label)) {
|
||||||
}
|
eventBuilder.setLabel(label);
|
||||||
tracker.send(eventBuilder.build());
|
|
||||||
}
|
}
|
||||||
|
tracker.send(eventBuilder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,39 @@
|
|||||||
package org.tasks.gtasks;
|
package org.tasks.gtasks;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
|
||||||
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
|
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
|
||||||
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
|
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
public class PlayServices {
|
public class PlayServices {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PlayServices() {
|
public PlayServices() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayServicesAvailable() {
|
public boolean isPlayServicesAvailable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refreshAndCheck() {
|
public boolean refreshAndCheck() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolve(Activity activity) {
|
public void resolve(Activity activity) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean clearToken(GoogleAccountCredential googleAccountCredential) {
|
public boolean clearToken(GoogleAccountCredential googleAccountCredential) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAuthToken(GtasksLoginActivity gtasksLoginActivity, String a, GtasksLoginActivity.AuthResultHandler authResultHandler) {
|
public void getAuthToken(GtasksLoginActivity gtasksLoginActivity, String a,
|
||||||
|
GtasksLoginActivity.AuthResultHandler authResultHandler) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
package org.tasks.location;
|
package org.tasks.location;
|
||||||
|
|
||||||
import org.tasks.data.Location;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import org.tasks.data.Location;
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
public class GeofenceApi {
|
public class GeofenceApi {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GeofenceApi() {
|
public GeofenceApi() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(List<Location> activeGeofences) {
|
public void register(List<Location> activeGeofences) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel(Location geofence) {
|
public void cancel(Location geofence) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel(List<Location> geofences) {
|
public void cancel(List<Location> geofences) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,79 +1,77 @@
|
|||||||
package com.todoroo.andlib.utility;
|
package com.todoroo.andlib.utility;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||||
|
import static com.todoroo.andlib.utility.DateUtilities.getRelativeDay;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static org.tasks.Freeze.freezeAt;
|
||||||
|
import static org.tasks.Freeze.thaw;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import java.util.Locale;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.tasks.time.DateTime;
|
import org.tasks.time.DateTime;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
|
||||||
import static com.todoroo.andlib.utility.DateUtilities.getRelativeDay;
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static org.tasks.Freeze.freezeAt;
|
|
||||||
import static org.tasks.Freeze.thaw;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class RelativeDayTest {
|
public class RelativeDayTest {
|
||||||
|
|
||||||
private static Locale defaultLocale;
|
private static final DateTime now = new DateTime(2013, 12, 31, 11, 9, 42, 357);
|
||||||
private static final DateTime now = new DateTime(2013, 12, 31, 11, 9, 42, 357);
|
private static Locale defaultLocale;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
defaultLocale = Locale.getDefault();
|
defaultLocale = Locale.getDefault();
|
||||||
Locale.setDefault(Locale.US);
|
Locale.setDefault(Locale.US);
|
||||||
freezeAt(now);
|
freezeAt(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
Locale.setDefault(defaultLocale);
|
Locale.setDefault(defaultLocale);
|
||||||
thaw();
|
thaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeDayIsToday() {
|
public void testRelativeDayIsToday() {
|
||||||
checkRelativeDay(new DateTime(), "Today", "Today");
|
checkRelativeDay(new DateTime(), "Today", "Today");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeDayIsTomorrow() {
|
public void testRelativeDayIsTomorrow() {
|
||||||
checkRelativeDay(new DateTime().plusDays(1), "Tomorrow", "Tmrw");
|
checkRelativeDay(new DateTime().plusDays(1), "Tomorrow", "Tmrw");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeDayIsYesterday() {
|
public void testRelativeDayIsYesterday() {
|
||||||
checkRelativeDay(new DateTime().minusDays(1), "Yesterday", "Yest");
|
checkRelativeDay(new DateTime().minusDays(1), "Yesterday", "Yest");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeDayTwo() {
|
public void testRelativeDayTwo() {
|
||||||
checkRelativeDay(new DateTime().minusDays(2), "Sunday", "Sun");
|
checkRelativeDay(new DateTime().minusDays(2), "Sunday", "Sun");
|
||||||
checkRelativeDay(new DateTime().plusDays(2), "Thursday", "Thu");
|
checkRelativeDay(new DateTime().plusDays(2), "Thursday", "Thu");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeDaySix() {
|
public void testRelativeDaySix() {
|
||||||
checkRelativeDay(new DateTime().minusDays(6), "Wednesday", "Wed");
|
checkRelativeDay(new DateTime().minusDays(6), "Wednesday", "Wed");
|
||||||
checkRelativeDay(new DateTime().plusDays(6), "Monday", "Mon");
|
checkRelativeDay(new DateTime().plusDays(6), "Monday", "Mon");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeDayOneWeek() {
|
public void testRelativeDayOneWeek() {
|
||||||
checkRelativeDay(new DateTime().minusDays(7), "Dec 24", "Dec 24");
|
checkRelativeDay(new DateTime().minusDays(7), "Dec 24", "Dec 24");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeDayOneWeekNextYear() {
|
public void testRelativeDayOneWeekNextYear() {
|
||||||
checkRelativeDay(new DateTime().plusDays(7), "Jan 7 '14", "Jan 7 '14");
|
checkRelativeDay(new DateTime().plusDays(7), "Jan 7 '14", "Jan 7 '14");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRelativeDay(DateTime now, String full, String abbreviated) {
|
private void checkRelativeDay(DateTime now, String full, String abbreviated) {
|
||||||
assertEquals(full, getRelativeDay(getTargetContext(), now.getMillis(), false));
|
assertEquals(full, getRelativeDay(getTargetContext(), now.getMillis(), false));
|
||||||
assertEquals(abbreviated, getRelativeDay(getTargetContext(), now.getMillis(), true));
|
assertEquals(abbreviated, getRelativeDay(getTargetContext(), now.getMillis(), true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,46 +1,43 @@
|
|||||||
package com.todoroo.astrid.model;
|
package com.todoroo.astrid.model;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static org.tasks.Freeze.freezeClock;
|
||||||
|
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import com.todoroo.astrid.dao.TaskDao;
|
import com.todoroo.astrid.dao.TaskDao;
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.tasks.Snippet;
|
import org.tasks.Snippet;
|
||||||
import org.tasks.injection.InjectingTestCase;
|
import org.tasks.injection.InjectingTestCase;
|
||||||
import org.tasks.injection.TestComponent;
|
import org.tasks.injection.TestComponent;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static org.tasks.Freeze.freezeClock;
|
|
||||||
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class TaskTest extends InjectingTestCase {
|
public class TaskTest extends InjectingTestCase {
|
||||||
|
|
||||||
@Inject TaskDao taskDao;
|
@Inject TaskDao taskDao;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSavedTaskHasCreationDate() {
|
public void testSavedTaskHasCreationDate() {
|
||||||
freezeClock().thawAfter(new Snippet() {{
|
freezeClock().thawAfter(new Snippet() {{
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
taskDao.createNew(task);
|
taskDao.createNew(task);
|
||||||
assertEquals(currentTimeMillis(), (long) task.getCreationDate());
|
assertEquals(currentTimeMillis(), (long) task.getCreationDate());
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadTaskFromDb() {
|
public void testReadTaskFromDb() {
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
taskDao.createNew(task);
|
taskDao.createNew(task);
|
||||||
final Task fromDb = taskDao.fetch(task.getId());
|
final Task fromDb = taskDao.fetch(task.getId());
|
||||||
assertEquals(task, fromDb);
|
assertEquals(task, fromDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(TestComponent component) {
|
protected void inject(TestComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,259 +1,266 @@
|
|||||||
package com.todoroo.astrid.repeats;
|
package com.todoroo.astrid.repeats;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static com.todoroo.astrid.repeats.RepeatTaskHelper.computeNextDueDate;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import com.google.ical.values.Frequency;
|
import com.google.ical.values.Frequency;
|
||||||
import com.google.ical.values.RRule;
|
import com.google.ical.values.RRule;
|
||||||
import com.google.ical.values.Weekday;
|
import com.google.ical.values.Weekday;
|
||||||
import com.google.ical.values.WeekdayNum;
|
import com.google.ical.values.WeekdayNum;
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
|
import java.text.ParseException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.tasks.time.DateTime;
|
import org.tasks.time.DateTime;
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
|
|
||||||
import static com.todoroo.astrid.repeats.RepeatTaskHelper.computeNextDueDate;
|
|
||||||
import static java.util.Arrays.asList;
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class NewRepeatTests {
|
public class NewRepeatTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatMinutelyFromDueDate() throws ParseException {
|
public void testRepeatMinutelyFromDueDate() throws ParseException {
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 26, 12, 30);
|
DateTime dueDateTime = newDayTime(2016, 8, 26, 12, 30);
|
||||||
Task task = newFromDue(Frequency.MINUTELY, 1, dueDateTime);
|
Task task = newFromDue(Frequency.MINUTELY, 1, dueDateTime);
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 8, 26, 12, 31), calculateNextDueDate(task));
|
assertEquals(newDayTime(2016, 8, 26, 12, 31), calculateNextDueDate(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatHourlyFromDueDate() throws ParseException {
|
public void testRepeatHourlyFromDueDate() throws ParseException {
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 26, 12, 30);
|
DateTime dueDateTime = newDayTime(2016, 8, 26, 12, 30);
|
||||||
Task task = newFromDue(Frequency.HOURLY, 1, dueDateTime);
|
Task task = newFromDue(Frequency.HOURLY, 1, dueDateTime);
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 8, 26, 13, 30), calculateNextDueDate(task));
|
assertEquals(newDayTime(2016, 8, 26, 13, 30), calculateNextDueDate(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatDailyFromDueDate() throws ParseException {
|
public void testRepeatDailyFromDueDate() throws ParseException {
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 26, 12, 30);
|
DateTime dueDateTime = newDayTime(2016, 8, 26, 12, 30);
|
||||||
Task task = newFromDue(Frequency.DAILY, 1, dueDateTime);
|
Task task = newFromDue(Frequency.DAILY, 1, dueDateTime);
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 8, 27, 12, 30), calculateNextDueDate(task));
|
assertEquals(newDayTime(2016, 8, 27, 12, 30), calculateNextDueDate(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatWeeklyFromDueDate() throws ParseException {
|
public void testRepeatWeeklyFromDueDate() throws ParseException {
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 1, 34);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 1, 34);
|
||||||
Task task = newFromDue(Frequency.WEEKLY, 1, dueDateTime);
|
Task task = newFromDue(Frequency.WEEKLY, 1, dueDateTime);
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 9, 4, 1, 34), calculateNextDueDate(task));
|
assertEquals(newDayTime(2016, 9, 4, 1, 34), calculateNextDueDate(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatMonthlyFromDueDate() throws ParseException {
|
public void testRepeatMonthlyFromDueDate() throws ParseException {
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 1, 44);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 1, 44);
|
||||||
Task task = newFromDue(Frequency.MONTHLY, 1, dueDateTime);
|
Task task = newFromDue(Frequency.MONTHLY, 1, dueDateTime);
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 9, 28, 1, 44), calculateNextDueDate(task));
|
assertEquals(newDayTime(2016, 9, 28, 1, 44), calculateNextDueDate(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatYearlyFromDueDate() throws ParseException {
|
public void testRepeatYearlyFromDueDate() throws ParseException {
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 1, 44);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 1, 44);
|
||||||
Task task = newFromDue(Frequency.YEARLY, 1, dueDateTime);
|
Task task = newFromDue(Frequency.YEARLY, 1, dueDateTime);
|
||||||
|
|
||||||
assertEquals(newDayTime(2017, 8, 28, 1, 44), calculateNextDueDate(task));
|
assertEquals(newDayTime(2017, 8, 28, 1, 44), calculateNextDueDate(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tests for repeating from completionDate */
|
/**
|
||||||
|
* Tests for repeating from completionDate
|
||||||
@Test
|
*/
|
||||||
public void testRepeatMinutelyFromCompleteDateCompleteBefore() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatMinutelyFromCompleteDateCompleteBefore() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.MINUTELY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 8, 29, 0, 15), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.MINUTELY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 29, 0, 15), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatMinutelyFromCompleteDateCompleteAfter() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatMinutelyFromCompleteDateCompleteAfter() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.MINUTELY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 8, 29, 0, 15), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.MINUTELY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 29, 0, 15), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatHourlyFromCompleteDateCompleteBefore() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatHourlyFromCompleteDateCompleteBefore() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.HOURLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 8, 29, 1, 14), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.HOURLY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 29, 1, 14), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatHourlyFromCompleteDateCompleteAfter() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatHourlyFromCompleteDateCompleteAfter() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.HOURLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 8, 29, 1, 14), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.HOURLY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 29, 1, 14), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatDailyFromCompleteDateCompleteBefore() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatDailyFromCompleteDateCompleteBefore() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.DAILY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 8, 30, 0, 25), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.DAILY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 30, 0, 25), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatDailyFromCompleteDateCompleteAfter() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatDailyFromCompleteDateCompleteAfter() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.DAILY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 8, 30, 0, 4), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.DAILY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 30, 0, 4), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatWeeklyFromCompleteDateCompleteBefore() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatWeeklyFromCompleteDateCompleteBefore() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.WEEKLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 9, 5, 0, 25), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.WEEKLY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 9, 5, 0, 25), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatWeeklyFromCompleteDateCompleteAfter() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatWeeklyFromCompleteDateCompleteAfter() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.WEEKLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 9, 5, 0, 4), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.WEEKLY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 9, 5, 0, 4), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatMonthlyFromCompleteDateCompleteBefore() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatMonthlyFromCompleteDateCompleteBefore() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.MONTHLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 9, 29, 0, 25), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.MONTHLY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 9, 29, 0, 25), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatMonthlyFromCompleteDateCompleteAfter() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatMonthlyFromCompleteDateCompleteAfter() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.MONTHLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2016, 9, 29, 0, 4), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.MONTHLY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2016, 9, 29, 0, 4), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatYearlyFromCompleteDateCompleteBefore() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatYearlyFromCompleteDateCompleteBefore() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.YEARLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 30, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2017, 8, 29, 0, 25), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.YEARLY, 1, dueDateTime, completionDateTime);
|
||||||
}
|
|
||||||
|
assertEquals(newDayTime(2017, 8, 29, 0, 25), calculateNextDueDate(task));
|
||||||
@Test
|
}
|
||||||
public void testRepeatYearlyFromCompleteDateCompleteAfter() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
@Test
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
public void testRepeatYearlyFromCompleteDateCompleteAfter() throws ParseException {
|
||||||
Task task = newFromCompleted(Frequency.YEARLY, 1, dueDateTime, completionDateTime);
|
DateTime dueDateTime = newDayTime(2016, 8, 28, 0, 4);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 29, 0, 14);
|
||||||
assertEquals(newDayTime(2017, 8, 29, 0, 4), calculateNextDueDate(task));
|
Task task = newFromCompleted(Frequency.YEARLY, 1, dueDateTime, completionDateTime);
|
||||||
|
|
||||||
|
assertEquals(newDayTime(2017, 8, 29, 0, 4), calculateNextDueDate(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvancedRepeatWeeklyFromDueDate() throws ParseException {
|
||||||
|
DateTime dueDateTime = newDayTime(2016, 8, 29, 0, 25);
|
||||||
|
Task task = newWeeklyFromDue(1, dueDateTime, new WeekdayNum(0, Weekday.MO),
|
||||||
|
new WeekdayNum(0, Weekday.WE));
|
||||||
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 31, 0, 25), calculateNextDueDate(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvancedRepeatWeeklyFromCompleteDateCompleteBefore() throws ParseException {
|
||||||
|
DateTime dueDateTime = newDayTime(2016, 8, 29, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 8, 28, 1, 9);
|
||||||
|
Task task = newWeeklyFromCompleted(1, dueDateTime, completionDateTime,
|
||||||
|
new WeekdayNum(0, Weekday.MO), new WeekdayNum(0, Weekday.WE));
|
||||||
|
|
||||||
|
assertEquals(newDayTime(2016, 8, 29, 0, 25), calculateNextDueDate(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdvancedRepeatWeeklyFromCompleteDateCompleteAfter() throws ParseException {
|
||||||
|
DateTime dueDateTime = newDayTime(2016, 8, 29, 0, 25);
|
||||||
|
DateTime completionDateTime = newDayTime(2016, 9, 1, 1, 9);
|
||||||
|
Task task = newWeeklyFromCompleted(1, dueDateTime, completionDateTime,
|
||||||
|
new WeekdayNum(0, Weekday.MO), new WeekdayNum(0, Weekday.WE));
|
||||||
|
|
||||||
|
assertEquals(newDayTime(2016, 9, 5, 0, 25), calculateNextDueDate(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateTime newDayTime(int year, int month, int day, int hour, int minute) {
|
||||||
|
return new DateTime(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME,
|
||||||
|
new DateTime(year, month, day, hour, minute).getMillis()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateTime calculateNextDueDate(Task task) throws ParseException {
|
||||||
|
return new DateTime(
|
||||||
|
computeNextDueDate(task, task.sanitizedRecurrence(), task.repeatAfterCompletion()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task newFromDue(Frequency frequency, int interval, DateTime dueDateTime) {
|
||||||
|
return new Task() {{
|
||||||
|
setRecurrence(getRecurrenceRule(frequency, interval, false));
|
||||||
|
setDueDate(dueDateTime.getMillis());
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task newWeeklyFromDue(int interval, DateTime dueDateTime, WeekdayNum... weekdays) {
|
||||||
|
return new Task() {{
|
||||||
|
setRecurrence(getRecurrenceRule(Frequency.WEEKLY, interval, false, weekdays));
|
||||||
|
setDueDate(dueDateTime.getMillis());
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task newFromCompleted(Frequency frequency, int interval, DateTime dueDateTime,
|
||||||
|
DateTime completionDate) {
|
||||||
|
return new Task() {{
|
||||||
|
setRecurrence(getRecurrenceRule(frequency, interval, true));
|
||||||
|
setDueDate(dueDateTime.getMillis());
|
||||||
|
setCompletionDate(completionDate.getMillis());
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task newWeeklyFromCompleted(int interval, DateTime dueDateTime, DateTime completionDate,
|
||||||
|
WeekdayNum... weekdays) {
|
||||||
|
return new Task() {{
|
||||||
|
setRecurrence(getRecurrenceRule(Frequency.WEEKLY, interval, true, weekdays));
|
||||||
|
setDueDate(dueDateTime.getMillis());
|
||||||
|
setCompletionDate(completionDate.getMillis());
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRecurrenceRule(Frequency frequency, int interval, boolean fromCompletion,
|
||||||
|
WeekdayNum... weekdays) {
|
||||||
|
RRule rrule = new RRule();
|
||||||
|
rrule.setFreq(frequency);
|
||||||
|
rrule.setInterval(interval);
|
||||||
|
if (weekdays != null) {
|
||||||
|
rrule.setByDay(asList(weekdays));
|
||||||
}
|
}
|
||||||
|
String result = rrule.toIcal();
|
||||||
@Test
|
if (fromCompletion) {
|
||||||
public void testAdvancedRepeatWeeklyFromDueDate() throws ParseException {
|
result += ";FROM=COMPLETION";
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 29, 0, 25);
|
|
||||||
Task task = newWeeklyFromDue(1, dueDateTime, new WeekdayNum(0, Weekday.MO), new WeekdayNum(0, Weekday.WE));
|
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 8, 31, 0, 25), calculateNextDueDate(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAdvancedRepeatWeeklyFromCompleteDateCompleteBefore() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 29, 0, 25);
|
|
||||||
DateTime completionDateTime = newDayTime(2016, 8, 28, 1, 9);
|
|
||||||
Task task = newWeeklyFromCompleted(1, dueDateTime, completionDateTime, new WeekdayNum(0, Weekday.MO), new WeekdayNum(0, Weekday.WE));
|
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 8, 29, 0, 25), calculateNextDueDate(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAdvancedRepeatWeeklyFromCompleteDateCompleteAfter() throws ParseException {
|
|
||||||
DateTime dueDateTime = newDayTime(2016, 8, 29, 0, 25);
|
|
||||||
DateTime completionDateTime = newDayTime(2016, 9, 1, 1, 9);
|
|
||||||
Task task = newWeeklyFromCompleted(1, dueDateTime, completionDateTime, new WeekdayNum(0, Weekday.MO), new WeekdayNum(0, Weekday.WE));
|
|
||||||
|
|
||||||
assertEquals(newDayTime(2016, 9, 5, 0, 25), calculateNextDueDate(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateTime newDayTime(int year, int month, int day, int hour, int minute) {
|
|
||||||
return new DateTime(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, new DateTime(year, month, day, hour, minute).getMillis()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateTime calculateNextDueDate(Task task) throws ParseException {
|
|
||||||
return new DateTime(computeNextDueDate(task, task.sanitizedRecurrence(), task.repeatAfterCompletion()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task newFromDue(Frequency frequency, int interval, DateTime dueDateTime) {
|
|
||||||
return new Task() {{
|
|
||||||
setRecurrence(getRecurrenceRule(frequency, interval, false));
|
|
||||||
setDueDate(dueDateTime.getMillis());
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task newWeeklyFromDue(int interval, DateTime dueDateTime, WeekdayNum... weekdays) {
|
|
||||||
return new Task() {{
|
|
||||||
setRecurrence(getRecurrenceRule(Frequency.WEEKLY, interval, false, weekdays));
|
|
||||||
setDueDate(dueDateTime.getMillis());
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task newFromCompleted(Frequency frequency, int interval, DateTime dueDateTime, DateTime completionDate) {
|
|
||||||
return new Task() {{
|
|
||||||
setRecurrence(getRecurrenceRule(frequency, interval, true));
|
|
||||||
setDueDate(dueDateTime.getMillis());
|
|
||||||
setCompletionDate(completionDate.getMillis());
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task newWeeklyFromCompleted(int interval, DateTime dueDateTime, DateTime completionDate, WeekdayNum... weekdays) {
|
|
||||||
return new Task() {{
|
|
||||||
setRecurrence(getRecurrenceRule(Frequency.WEEKLY, interval, true, weekdays));
|
|
||||||
setDueDate(dueDateTime.getMillis());
|
|
||||||
setCompletionDate(completionDate.getMillis());
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRecurrenceRule(Frequency frequency, int interval, boolean fromCompletion, WeekdayNum... weekdays) {
|
|
||||||
RRule rrule = new RRule();
|
|
||||||
rrule.setFreq(frequency);
|
|
||||||
rrule.setInterval(interval);
|
|
||||||
if (weekdays != null) {
|
|
||||||
rrule.setByDay(asList(weekdays));
|
|
||||||
}
|
|
||||||
String result = rrule.toIcal();
|
|
||||||
if (fromCompletion) {
|
|
||||||
result += ";FROM=COMPLETION";
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,73 +1,72 @@
|
|||||||
package com.todoroo.astrid.subtasks;
|
package com.todoroo.astrid.subtasks;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import com.todoroo.astrid.dao.TaskDao;
|
import com.todoroo.astrid.dao.TaskDao;
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
import org.tasks.data.TaskListMetadata;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.tasks.data.TaskListMetadata;
|
||||||
import org.tasks.injection.TestComponent;
|
import org.tasks.injection.TestComponent;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SubtasksHelperTest extends SubtasksTestCase {
|
public class SubtasksHelperTest extends SubtasksTestCase {
|
||||||
|
|
||||||
@Inject TaskDao taskDao;
|
private static final String[] EXPECTED_ORDER = {"-1", "1", "2", "3", "4", "5", "6"};
|
||||||
|
private static String EXPECTED_REMOTE = "[\"-1\", [\"6\", \"4\", [\"3\", \"1\"]], \"2\", \"5\"]"
|
||||||
@Override
|
.replaceAll("\\s", "");
|
||||||
public void setUp() {
|
@Inject TaskDao taskDao;
|
||||||
super.setUp();
|
|
||||||
createTasks();
|
@Override
|
||||||
TaskListMetadata m = new TaskListMetadata();
|
public void setUp() {
|
||||||
m.setFilter(TaskListMetadata.FILTER_ID_ALL);
|
super.setUp();
|
||||||
updater.initializeFromSerializedTree(m, filter, SubtasksHelper.convertTreeToRemoteIds(taskDao, DEFAULT_SERIALIZED_TREE));
|
createTasks();
|
||||||
}
|
TaskListMetadata m = new TaskListMetadata();
|
||||||
|
m.setFilter(TaskListMetadata.FILTER_ID_ALL);
|
||||||
private void createTask(String title, String uuid) {
|
updater.initializeFromSerializedTree(m, filter,
|
||||||
Task t = new Task();
|
SubtasksHelper.convertTreeToRemoteIds(taskDao, DEFAULT_SERIALIZED_TREE));
|
||||||
t.setTitle(title);
|
}
|
||||||
t.setUuid(uuid);
|
|
||||||
taskDao.createNew(t);
|
private void createTask(String title, String uuid) {
|
||||||
|
Task t = new Task();
|
||||||
|
t.setTitle(title);
|
||||||
|
t.setUuid(uuid);
|
||||||
|
taskDao.createNew(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createTasks() {
|
||||||
|
createTask("A", "6"); // Local id 1
|
||||||
|
createTask("B", "4"); // Local id 2
|
||||||
|
createTask("C", "3"); // Local id 3
|
||||||
|
createTask("D", "1"); // Local id 4
|
||||||
|
createTask("E", "2"); // Local id 5
|
||||||
|
createTask("F", "5"); // Local id 6
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default order: "[-1, [1, 2, [3, 4]], 5, 6]"
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrderedIdArray() {
|
||||||
|
String[] ids = SubtasksHelper.getStringIdArray(DEFAULT_SERIALIZED_TREE);
|
||||||
|
assertEquals(EXPECTED_ORDER.length, ids.length);
|
||||||
|
for (int i = 0; i < EXPECTED_ORDER.length; i++) {
|
||||||
|
assertEquals(EXPECTED_ORDER[i], ids[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createTasks() {
|
@Test
|
||||||
createTask("A", "6"); // Local id 1
|
public void testLocalToRemoteIdMapping() {
|
||||||
createTask("B", "4"); // Local id 2
|
String mapped = SubtasksHelper.convertTreeToRemoteIds(taskDao, DEFAULT_SERIALIZED_TREE)
|
||||||
createTask("C", "3"); // Local id 3
|
.replaceAll("\\s", "");
|
||||||
createTask("D", "1"); // Local id 4
|
assertEquals(EXPECTED_REMOTE, mapped);
|
||||||
createTask("E", "2"); // Local id 5
|
}
|
||||||
createTask("F", "5"); // Local id 6
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String[] EXPECTED_ORDER = { "-1", "1", "2", "3", "4", "5", "6" };
|
|
||||||
|
|
||||||
@Test
|
@Override
|
||||||
public void testOrderedIdArray() {
|
protected void inject(TestComponent component) {
|
||||||
String[] ids = SubtasksHelper.getStringIdArray(DEFAULT_SERIALIZED_TREE);
|
super.inject(component);
|
||||||
assertEquals(EXPECTED_ORDER.length, ids.length);
|
|
||||||
for (int i = 0; i < EXPECTED_ORDER.length; i++) {
|
|
||||||
assertEquals(EXPECTED_ORDER[i], ids[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default order: "[-1, [1, 2, [3, 4]], 5, 6]"
|
component.inject(this);
|
||||||
|
}
|
||||||
private static String EXPECTED_REMOTE = "[\"-1\", [\"6\", \"4\", [\"3\", \"1\"]], \"2\", \"5\"]".replaceAll("\\s", "");
|
|
||||||
@Test
|
|
||||||
public void testLocalToRemoteIdMapping() {
|
|
||||||
String mapped = SubtasksHelper.convertTreeToRemoteIds(taskDao, DEFAULT_SERIALIZED_TREE).replaceAll("\\s", "");
|
|
||||||
assertEquals(EXPECTED_REMOTE, mapped);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void inject(TestComponent component) {
|
|
||||||
super.inject(component);
|
|
||||||
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,66 +1,63 @@
|
|||||||
package com.todoroo.astrid.subtasks;
|
package com.todoroo.astrid.subtasks;
|
||||||
|
|
||||||
|
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertNotNull;
|
||||||
|
|
||||||
import com.todoroo.astrid.api.Filter;
|
import com.todoroo.astrid.api.Filter;
|
||||||
import com.todoroo.astrid.core.BuiltInFilterExposer;
|
import com.todoroo.astrid.core.BuiltInFilterExposer;
|
||||||
import com.todoroo.astrid.dao.TaskDao;
|
import com.todoroo.astrid.dao.TaskDao;
|
||||||
import org.tasks.data.TaskListMetadataDao;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
import com.todoroo.astrid.subtasks.SubtasksFilterUpdater.Node;
|
import com.todoroo.astrid.subtasks.SubtasksFilterUpdater.Node;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import org.tasks.data.TaskListMetadataDao;
|
||||||
import org.tasks.injection.InjectingTestCase;
|
import org.tasks.injection.InjectingTestCase;
|
||||||
import org.tasks.injection.TestComponent;
|
import org.tasks.injection.TestComponent;
|
||||||
import org.tasks.preferences.Preferences;
|
import org.tasks.preferences.Preferences;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains useful methods common to all subtasks tests
|
* Contains useful methods common to all subtasks tests
|
||||||
* @author Sam
|
|
||||||
*
|
*
|
||||||
|
* @author Sam
|
||||||
*/
|
*/
|
||||||
public class SubtasksTestCase extends InjectingTestCase {
|
public class SubtasksTestCase extends InjectingTestCase {
|
||||||
|
|
||||||
@Inject TaskListMetadataDao taskListMetadataDao;
|
/* Starting State:
|
||||||
@Inject TaskDao taskDao;
|
*
|
||||||
@Inject Preferences preferences;
|
* A
|
||||||
|
* B
|
||||||
protected SubtasksFilterUpdater updater;
|
* C
|
||||||
protected Filter filter;
|
* D
|
||||||
|
* E
|
||||||
/* Starting State:
|
* F
|
||||||
*
|
*/
|
||||||
* A
|
public static final String DEFAULT_SERIALIZED_TREE = "[-1, [1, 2, [3, 4]], 5, 6]"
|
||||||
* B
|
.replaceAll("\\s", "");
|
||||||
* C
|
protected SubtasksFilterUpdater updater;
|
||||||
* D
|
protected Filter filter;
|
||||||
* E
|
@Inject TaskListMetadataDao taskListMetadataDao;
|
||||||
* F
|
@Inject TaskDao taskDao;
|
||||||
*/
|
@Inject Preferences preferences;
|
||||||
public static final String DEFAULT_SERIALIZED_TREE = "[-1, [1, 2, [3, 4]], 5, 6]".replaceAll("\\s", "");
|
|
||||||
|
@Override
|
||||||
@Override
|
public void setUp() {
|
||||||
public void setUp() {
|
super.setUp();
|
||||||
super.setUp();
|
filter = BuiltInFilterExposer.getMyTasksFilter(getTargetContext().getResources());
|
||||||
filter = BuiltInFilterExposer.getMyTasksFilter(getTargetContext().getResources());
|
preferences.clear(SubtasksFilterUpdater.ACTIVE_TASKS_ORDER);
|
||||||
preferences.clear(SubtasksFilterUpdater.ACTIVE_TASKS_ORDER);
|
updater = new SubtasksFilterUpdater(taskListMetadataDao, taskDao);
|
||||||
updater = new SubtasksFilterUpdater(taskListMetadataDao, taskDao);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
protected void inject(TestComponent component) {
|
||||||
protected void inject(TestComponent component) {
|
component.inject(this);
|
||||||
component.inject(this);
|
}
|
||||||
}
|
|
||||||
|
protected void expectParentAndPosition(Task task, Task parent, int positionInParent) {
|
||||||
protected void expectParentAndPosition(Task task, Task parent, int positionInParent) {
|
String parentId = (parent == null ? "-1" : parent.getUuid());
|
||||||
String parentId = (parent == null ? "-1" : parent.getUuid());
|
Node n = updater.findNodeForTask(task.getUuid());
|
||||||
Node n = updater.findNodeForTask(task.getUuid());
|
assertNotNull("No node found for task " + task.getTitle(), n);
|
||||||
assertNotNull("No node found for task " + task.getTitle(), n);
|
assertEquals("Parent mismatch", parentId, n.parent.uuid);
|
||||||
assertEquals("Parent mismatch", parentId, n.parent.uuid);
|
assertEquals("Position mismatch", positionInParent, n.parent.children.indexOf(n));
|
||||||
assertEquals("Position mismatch", positionInParent, n.parent.children.indexOf(n));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,47 @@
|
|||||||
package com.todoroo.astrid.sync;
|
package com.todoroo.astrid.sync;
|
||||||
|
|
||||||
import org.tasks.data.TagDataDao;
|
|
||||||
import com.todoroo.astrid.dao.TaskDao;
|
import com.todoroo.astrid.dao.TaskDao;
|
||||||
import org.tasks.data.TagData;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import org.tasks.data.TagData;
|
||||||
|
import org.tasks.data.TagDataDao;
|
||||||
import org.tasks.injection.InjectingTestCase;
|
import org.tasks.injection.InjectingTestCase;
|
||||||
import org.tasks.injection.TestComponent;
|
import org.tasks.injection.TestComponent;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
public class NewSyncTestCase extends InjectingTestCase {
|
public class NewSyncTestCase extends InjectingTestCase {
|
||||||
|
|
||||||
@Inject TaskDao taskDao;
|
public static final String SYNC_TASK_TITLE = "new title";
|
||||||
@Inject TagDataDao tagDataDao;
|
public static final int SYNC_TASK_IMPORTANCE = Task.IMPORTANCE_MUST_DO;
|
||||||
|
@Inject TaskDao taskDao;
|
||||||
protected Task createTask(String title) {
|
@Inject TagDataDao tagDataDao;
|
||||||
Task task = new Task();
|
|
||||||
task.setTitle(title);
|
|
||||||
task.setImportance(SYNC_TASK_IMPORTANCE);
|
|
||||||
|
|
||||||
taskDao.createNew(task);
|
protected Task createTask(String title) {
|
||||||
return task;
|
Task task = new Task();
|
||||||
}
|
task.setTitle(title);
|
||||||
|
task.setImportance(SYNC_TASK_IMPORTANCE);
|
||||||
|
|
||||||
public static final String SYNC_TASK_TITLE = "new title";
|
taskDao.createNew(task);
|
||||||
public static final int SYNC_TASK_IMPORTANCE = Task.IMPORTANCE_MUST_DO;
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
protected Task createTask() {
|
protected Task createTask() {
|
||||||
return createTask(SYNC_TASK_TITLE);
|
return createTask(SYNC_TASK_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TagData createTagData(String name) {
|
protected TagData createTagData(String name) {
|
||||||
TagData tag = new TagData();
|
TagData tag = new TagData();
|
||||||
tag.setName(name);
|
tag.setName(name);
|
||||||
|
|
||||||
tagDataDao.createNew(tag);
|
tagDataDao.createNew(tag);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TagData createTagData() {
|
protected TagData createTagData() {
|
||||||
return createTagData("new tag");
|
return createTagData("new tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(TestComponent component) {
|
protected void inject(TestComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
package com.todoroo.astrid.sync;
|
package com.todoroo.astrid.sync;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static junit.framework.Assert.assertFalse;
|
||||||
|
|
||||||
import org.tasks.data.TagData;
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.tasks.data.TagData;
|
||||||
import static junit.framework.Assert.assertFalse;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SyncModelTest extends NewSyncTestCase {
|
public class SyncModelTest extends NewSyncTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTaskMakesUuid() {
|
public void testCreateTaskMakesUuid() {
|
||||||
Task task = createTask();
|
Task task = createTask();
|
||||||
assertFalse(Task.NO_UUID.equals(task.getUuid()));
|
assertFalse(Task.NO_UUID.equals(task.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTagMakesUuid() {
|
public void testCreateTagMakesUuid() {
|
||||||
TagData tag = createTagData();
|
TagData tag = createTagData();
|
||||||
assertFalse(Task.NO_UUID.equals(tag.getRemoteId()));
|
assertFalse(Task.NO_UUID.equals(tag.getRemoteId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
package org.tasks;
|
package org.tasks;
|
||||||
|
|
||||||
|
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
||||||
|
|
||||||
import org.tasks.time.DateTime;
|
import org.tasks.time.DateTime;
|
||||||
import org.tasks.time.DateTimeUtils;
|
import org.tasks.time.DateTimeUtils;
|
||||||
|
|
||||||
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
|
||||||
|
|
||||||
public class Freeze {
|
public class Freeze {
|
||||||
|
|
||||||
public static Freeze freezeClock() {
|
public static Freeze freezeClock() {
|
||||||
return freezeAt(currentTimeMillis());
|
return freezeAt(currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Freeze freezeAt(DateTime dateTime) {
|
public static Freeze freezeAt(DateTime dateTime) {
|
||||||
return freezeAt(dateTime.getMillis());
|
return freezeAt(dateTime.getMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Freeze freezeAt(long millis) {
|
public static Freeze freezeAt(long millis) {
|
||||||
DateTimeUtils.setCurrentMillisFixed(millis);
|
DateTimeUtils.setCurrentMillisFixed(millis);
|
||||||
return new Freeze();
|
return new Freeze();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void thaw() {
|
public static void thaw() {
|
||||||
DateTimeUtils.setCurrentMillisSystem();
|
DateTimeUtils.setCurrentMillisSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedParameters")
|
@SuppressWarnings("UnusedParameters")
|
||||||
public void thawAfter(Snippet snippet) {
|
public void thawAfter(Snippet snippet) {
|
||||||
thaw();
|
thaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void thawAfter(Runnable run) {
|
public void thawAfter(Runnable run) {
|
||||||
try {
|
try {
|
||||||
run.run();
|
run.run();
|
||||||
} finally {
|
} finally {
|
||||||
thaw();
|
thaw();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package org.tasks;
|
package org.tasks;
|
||||||
|
|
||||||
public class Snippet {
|
public class Snippet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,41 @@
|
|||||||
package org.tasks.date;
|
package org.tasks.date;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static org.tasks.Freeze.freezeAt;
|
||||||
|
import static org.tasks.date.DateTimeUtils.newDateUtc;
|
||||||
|
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import java.util.TimeZone;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.tasks.Snippet;
|
import org.tasks.Snippet;
|
||||||
import org.tasks.time.DateTime;
|
import org.tasks.time.DateTime;
|
||||||
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static org.tasks.Freeze.freezeAt;
|
|
||||||
import static org.tasks.date.DateTimeUtils.newDateUtc;
|
|
||||||
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class DateTimeUtilsTest {
|
public class DateTimeUtilsTest {
|
||||||
|
|
||||||
private final DateTime now = new DateTime(2014, 1, 1, 15, 17, 53, 0);
|
private final DateTime now = new DateTime(2014, 1, 1, 15, 17, 53, 0);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCurrentTime() {
|
public void testGetCurrentTime() {
|
||||||
freezeAt(now).thawAfter(new Snippet() {{
|
freezeAt(now).thawAfter(new Snippet() {{
|
||||||
assertEquals(now.getMillis(), currentTimeMillis());
|
assertEquals(now.getMillis(), currentTimeMillis());
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewUtcDate() {
|
public void testCreateNewUtcDate() {
|
||||||
DateTime utc = now.toUTC();
|
DateTime utc = now.toUTC();
|
||||||
DateTime actual = newDateUtc(utc.getYear(), utc.getMonthOfYear(), utc.getDayOfMonth(), utc.getHourOfDay(), utc.getMinuteOfHour(), utc.getSecondOfMinute());
|
DateTime actual = newDateUtc(utc.getYear(), utc.getMonthOfYear(), utc.getDayOfMonth(),
|
||||||
assertEquals(utc.getMillis(), actual.getMillis());
|
utc.getHourOfDay(), utc.getMinuteOfHour(), utc.getSecondOfMinute());
|
||||||
}
|
assertEquals(utc.getMillis(), actual.getMillis());
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void testIllegalInstant() {
|
@Test
|
||||||
new DateTime(2015, 7, 24, 0, 0, 0, 0, TimeZone.getTimeZone("Africa/Cairo"));
|
public void testIllegalInstant() {
|
||||||
new DateTime(2015, 10, 18, 0, 0, 0, 0, TimeZone.getTimeZone("America/Sao_Paulo"));
|
new DateTime(2015, 7, 24, 0, 0, 0, 0, TimeZone.getTimeZone("Africa/Cairo"));
|
||||||
new DateTime(2015, 10, 4, 0, 0, 0, 0, TimeZone.getTimeZone("America/Asuncion"));
|
new DateTime(2015, 10, 18, 0, 0, 0, 0, TimeZone.getTimeZone("America/Sao_Paulo"));
|
||||||
}
|
new DateTime(2015, 10, 4, 0, 0, 0, 0, TimeZone.getTimeZone("America/Asuncion"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
package org.tasks.injection;
|
package org.tasks.injection;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||||
import static org.tasks.TestUtilities.initializeMockito;
|
import static org.tasks.TestUtilities.initializeMockito;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
public abstract class InjectingTestCase {
|
public abstract class InjectingTestCase {
|
||||||
|
|
||||||
protected TestComponent component;
|
protected TestComponent component;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
initializeMockito(getTargetContext());
|
initializeMockito(getTargetContext());
|
||||||
|
|
||||||
component = DaggerTestComponent.builder()
|
component = DaggerTestComponent.builder()
|
||||||
.testModule(new TestModule(getTargetContext()))
|
.testModule(new TestModule(getTargetContext()))
|
||||||
.build();
|
.build();
|
||||||
inject(component);
|
inject(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void inject(TestComponent component);
|
protected abstract void inject(TestComponent component);
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,33 @@
|
|||||||
package org.tasks.makers;
|
package org.tasks.makers;
|
||||||
|
|
||||||
|
import static com.natpryce.makeiteasy.Property.newProperty;
|
||||||
|
import static org.tasks.makers.Maker.make;
|
||||||
|
|
||||||
import com.natpryce.makeiteasy.Instantiator;
|
import com.natpryce.makeiteasy.Instantiator;
|
||||||
import com.natpryce.makeiteasy.Property;
|
import com.natpryce.makeiteasy.Property;
|
||||||
import com.natpryce.makeiteasy.PropertyValue;
|
import com.natpryce.makeiteasy.PropertyValue;
|
||||||
|
|
||||||
import org.tasks.data.GoogleTaskList;
|
import org.tasks.data.GoogleTaskList;
|
||||||
|
|
||||||
import static com.natpryce.makeiteasy.Property.newProperty;
|
|
||||||
import static org.tasks.makers.Maker.make;
|
|
||||||
|
|
||||||
public class GtaskListMaker {
|
public class GtaskListMaker {
|
||||||
|
|
||||||
public static final Property<GoogleTaskList, Long> ID = newProperty();
|
public static final Property<GoogleTaskList, Long> ID = newProperty();
|
||||||
public static final Property<GoogleTaskList, Integer> ORDER = newProperty();
|
public static final Property<GoogleTaskList, Integer> ORDER = newProperty();
|
||||||
public static final Property<GoogleTaskList, String> REMOTE_ID = newProperty();
|
public static final Property<GoogleTaskList, String> REMOTE_ID = newProperty();
|
||||||
public static final Property<GoogleTaskList, Long> LAST_SYNC = newProperty();
|
public static final Property<GoogleTaskList, Long> LAST_SYNC = newProperty();
|
||||||
public static final Property<GoogleTaskList, String> NAME = newProperty();
|
public static final Property<GoogleTaskList, String> NAME = newProperty();
|
||||||
public static final Property<GoogleTaskList, Integer> COLOR = newProperty();
|
public static final Property<GoogleTaskList, Integer> COLOR = newProperty();
|
||||||
|
private static final Instantiator<GoogleTaskList> instantiator = lookup -> new GoogleTaskList() {{
|
||||||
public static GoogleTaskList newGtaskList(PropertyValue<? super GoogleTaskList, ?>... properties) {
|
setDeleted(0L);
|
||||||
return make(instantiator, properties);
|
setId(lookup.valueOf(GtaskListMaker.ID, 0L));
|
||||||
}
|
setRemoteId(lookup.valueOf(REMOTE_ID, "1"));
|
||||||
|
setTitle(lookup.valueOf(NAME, "Default"));
|
||||||
|
setRemoteOrder(lookup.valueOf(ORDER, 0));
|
||||||
|
setLastSync(lookup.valueOf(LAST_SYNC, 0L));
|
||||||
|
setColor(lookup.valueOf(COLOR, -1));
|
||||||
|
}};
|
||||||
|
|
||||||
private static final Instantiator<GoogleTaskList> instantiator = lookup -> new GoogleTaskList() {{
|
public static GoogleTaskList newGtaskList(
|
||||||
setDeleted(0L);
|
PropertyValue<? super GoogleTaskList, ?>... properties) {
|
||||||
setId(lookup.valueOf(GtaskListMaker.ID, 0L));
|
return make(instantiator, properties);
|
||||||
setRemoteId(lookup.valueOf(REMOTE_ID, "1"));
|
}
|
||||||
setTitle(lookup.valueOf(NAME, "Default"));
|
|
||||||
setRemoteOrder(lookup.valueOf(ORDER, 0));
|
|
||||||
setLastSync(lookup.valueOf(LAST_SYNC, 0L));
|
|
||||||
setColor(lookup.valueOf(COLOR, -1));
|
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package org.tasks.makers;
|
package org.tasks.makers;
|
||||||
|
|
||||||
|
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||||
|
|
||||||
import com.natpryce.makeiteasy.Instantiator;
|
import com.natpryce.makeiteasy.Instantiator;
|
||||||
import com.natpryce.makeiteasy.PropertyValue;
|
import com.natpryce.makeiteasy.PropertyValue;
|
||||||
|
|
||||||
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
|
||||||
|
|
||||||
public class Maker {
|
public class Maker {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T make(Instantiator<T> instantiator, PropertyValue<? super T, ?>... properties) {
|
@SuppressWarnings("unchecked")
|
||||||
return com.natpryce.makeiteasy.MakeItEasy.make(a(instantiator, properties));
|
public static <T> T make(Instantiator<T> instantiator,
|
||||||
}
|
PropertyValue<? super T, ?>... properties) {
|
||||||
|
return com.natpryce.makeiteasy.MakeItEasy.make(a(instantiator, properties));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,112 +1,110 @@
|
|||||||
package org.tasks.makers;
|
package org.tasks.makers;
|
||||||
|
|
||||||
|
import static com.natpryce.makeiteasy.Property.newProperty;
|
||||||
|
import static org.tasks.date.DateTimeUtils.newDateTime;
|
||||||
|
import static org.tasks.makers.Maker.make;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.ical.values.RRule;
|
import com.google.ical.values.RRule;
|
||||||
import com.natpryce.makeiteasy.Instantiator;
|
import com.natpryce.makeiteasy.Instantiator;
|
||||||
import com.natpryce.makeiteasy.Property;
|
import com.natpryce.makeiteasy.Property;
|
||||||
import com.natpryce.makeiteasy.PropertyValue;
|
import com.natpryce.makeiteasy.PropertyValue;
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
|
|
||||||
import org.tasks.time.DateTime;
|
import org.tasks.time.DateTime;
|
||||||
|
|
||||||
import static com.natpryce.makeiteasy.Property.newProperty;
|
|
||||||
import static org.tasks.date.DateTimeUtils.newDateTime;
|
|
||||||
import static org.tasks.makers.Maker.make;
|
|
||||||
|
|
||||||
public class TaskMaker {
|
public class TaskMaker {
|
||||||
|
|
||||||
public static Property<Task, Long> ID = newProperty();
|
public static Property<Task, Long> ID = newProperty();
|
||||||
public static Property<Task, String> TITLE = newProperty();
|
public static Property<Task, String> TITLE = newProperty();
|
||||||
public static Property<Task, DateTime> DUE_DATE = newProperty();
|
public static Property<Task, DateTime> DUE_DATE = newProperty();
|
||||||
public static Property<Task, DateTime> DUE_TIME = newProperty();
|
public static Property<Task, DateTime> DUE_TIME = newProperty();
|
||||||
public static Property<Task, Integer> PRIORITY = newProperty();
|
public static Property<Task, Integer> PRIORITY = newProperty();
|
||||||
public static Property<Task, DateTime> REMINDER_LAST = newProperty();
|
public static Property<Task, DateTime> REMINDER_LAST = newProperty();
|
||||||
public static Property<Task, Long> RANDOM_REMINDER_PERIOD = newProperty();
|
public static Property<Task, Long> RANDOM_REMINDER_PERIOD = newProperty();
|
||||||
public static Property<Task, Integer> HIDE_TYPE = newProperty();
|
public static Property<Task, Integer> HIDE_TYPE = newProperty();
|
||||||
public static Property<Task, Integer> REMINDERS = newProperty();
|
public static Property<Task, Integer> REMINDERS = newProperty();
|
||||||
public static Property<Task, DateTime> CREATION_TIME = newProperty();
|
public static Property<Task, DateTime> CREATION_TIME = newProperty();
|
||||||
public static Property<Task, DateTime> COMPLETION_TIME = newProperty();
|
public static Property<Task, DateTime> COMPLETION_TIME = newProperty();
|
||||||
public static Property<Task, DateTime> DELETION_TIME = newProperty();
|
public static Property<Task, DateTime> DELETION_TIME = newProperty();
|
||||||
public static Property<Task, DateTime> SNOOZE_TIME = newProperty();
|
public static Property<Task, DateTime> SNOOZE_TIME = newProperty();
|
||||||
public static Property<Task, RRule> RRULE = newProperty();
|
public static Property<Task, RRule> RRULE = newProperty();
|
||||||
public static Property<Task, Boolean> AFTER_COMPLETE = newProperty();
|
public static Property<Task, Boolean> AFTER_COMPLETE = newProperty();
|
||||||
|
private static final Instantiator<Task> instantiator = lookup -> {
|
||||||
@SafeVarargs
|
Task task = new Task();
|
||||||
public static Task newTask(PropertyValue<? super Task, ?>... properties) {
|
|
||||||
return make(instantiator, properties);
|
String title = lookup.valueOf(TITLE, (String) null);
|
||||||
|
if (!Strings.isNullOrEmpty(title)) {
|
||||||
|
task.setTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Instantiator<Task> instantiator = lookup -> {
|
long id = lookup.valueOf(ID, Task.NO_ID);
|
||||||
Task task = new Task();
|
if (id != Task.NO_ID) {
|
||||||
|
task.setId(id);
|
||||||
String title = lookup.valueOf(TITLE, (String) null);
|
}
|
||||||
if (!Strings.isNullOrEmpty(title)) {
|
|
||||||
task.setTitle(title);
|
int priority = lookup.valueOf(PRIORITY, -1);
|
||||||
}
|
if (priority >= 0) {
|
||||||
|
task.setImportance(priority);
|
||||||
long id = lookup.valueOf(ID, Task.NO_ID);
|
}
|
||||||
if (id != Task.NO_ID) {
|
|
||||||
task.setId(id);
|
DateTime dueDate = lookup.valueOf(DUE_DATE, (DateTime) null);
|
||||||
}
|
if (dueDate != null) {
|
||||||
|
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate.getMillis()));
|
||||||
int priority = lookup.valueOf(PRIORITY, -1);
|
}
|
||||||
if (priority >= 0) {
|
|
||||||
task.setImportance(priority);
|
DateTime dueTime = lookup.valueOf(DUE_TIME, (DateTime) null);
|
||||||
}
|
if (dueTime != null) {
|
||||||
|
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, dueTime.getMillis()));
|
||||||
DateTime dueDate = lookup.valueOf(DUE_DATE, (DateTime) null);
|
}
|
||||||
if (dueDate != null) {
|
|
||||||
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate.getMillis()));
|
DateTime completionTime = lookup.valueOf(COMPLETION_TIME, (DateTime) null);
|
||||||
}
|
if (completionTime != null) {
|
||||||
|
task.setCompletionDate(completionTime.getMillis());
|
||||||
DateTime dueTime = lookup.valueOf(DUE_TIME, (DateTime) null);
|
}
|
||||||
if (dueTime != null) {
|
|
||||||
task.setDueDate(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, dueTime.getMillis()));
|
DateTime deletedTime = lookup.valueOf(DELETION_TIME, (DateTime) null);
|
||||||
}
|
if (deletedTime != null) {
|
||||||
|
task.setDeletionDate(deletedTime.getMillis());
|
||||||
DateTime completionTime = lookup.valueOf(COMPLETION_TIME, (DateTime) null);
|
}
|
||||||
if (completionTime != null) {
|
|
||||||
task.setCompletionDate(completionTime.getMillis());
|
DateTime snoozeTime = lookup.valueOf(SNOOZE_TIME, (DateTime) null);
|
||||||
}
|
if (snoozeTime != null) {
|
||||||
|
task.setReminderSnooze(snoozeTime.getMillis());
|
||||||
DateTime deletedTime = lookup.valueOf(DELETION_TIME, (DateTime) null);
|
}
|
||||||
if (deletedTime != null) {
|
|
||||||
task.setDeletionDate(deletedTime.getMillis());
|
int hideType = lookup.valueOf(HIDE_TYPE, -1);
|
||||||
}
|
if (hideType >= 0) {
|
||||||
|
task.setHideUntil(task.createHideUntil(hideType, 0));
|
||||||
DateTime snoozeTime = lookup.valueOf(SNOOZE_TIME, (DateTime) null);
|
}
|
||||||
if (snoozeTime != null) {
|
|
||||||
task.setReminderSnooze(snoozeTime.getMillis());
|
int reminderFlags = lookup.valueOf(REMINDERS, -1);
|
||||||
}
|
if (reminderFlags >= 0) {
|
||||||
|
task.setReminderFlags(reminderFlags);
|
||||||
int hideType = lookup.valueOf(HIDE_TYPE, -1);
|
}
|
||||||
if (hideType >= 0) {
|
|
||||||
task.setHideUntil(task.createHideUntil(hideType, 0));
|
DateTime reminderLast = lookup.valueOf(REMINDER_LAST, (DateTime) null);
|
||||||
}
|
if (reminderLast != null) {
|
||||||
|
task.setReminderLast(reminderLast.getMillis());
|
||||||
int reminderFlags = lookup.valueOf(REMINDERS, -1);
|
}
|
||||||
if (reminderFlags >= 0) {
|
|
||||||
task.setReminderFlags(reminderFlags);
|
long randomReminderPeriod = lookup.valueOf(RANDOM_REMINDER_PERIOD, 0L);
|
||||||
}
|
if (randomReminderPeriod > 0) {
|
||||||
|
task.setReminderPeriod(randomReminderPeriod);
|
||||||
DateTime reminderLast = lookup.valueOf(REMINDER_LAST, (DateTime) null);
|
}
|
||||||
if (reminderLast != null) {
|
|
||||||
task.setReminderLast(reminderLast.getMillis());
|
RRule rrule = lookup.valueOf(RRULE, (RRule) null);
|
||||||
}
|
if (rrule != null) {
|
||||||
|
task.setRecurrence(rrule, lookup.valueOf(AFTER_COMPLETE, false));
|
||||||
long randomReminderPeriod = lookup.valueOf(RANDOM_REMINDER_PERIOD, 0L);
|
}
|
||||||
if (randomReminderPeriod > 0) {
|
|
||||||
task.setReminderPeriod(randomReminderPeriod);
|
DateTime creationTime = lookup.valueOf(CREATION_TIME, newDateTime());
|
||||||
}
|
task.setCreationDate(creationTime.getMillis());
|
||||||
|
|
||||||
RRule rrule = lookup.valueOf(RRULE, (RRule) null);
|
return task;
|
||||||
if (rrule != null) {
|
};
|
||||||
task.setRecurrence(rrule, lookup.valueOf(AFTER_COMPLETE, false));
|
|
||||||
}
|
@SafeVarargs
|
||||||
|
public static Task newTask(PropertyValue<? super Task, ?>... properties) {
|
||||||
DateTime creationTime = lookup.valueOf(CREATION_TIME, newDateTime());
|
return make(instantiator, properties);
|
||||||
task.setCreationDate(creationTime.getMillis());
|
}
|
||||||
|
|
||||||
return task;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,41 @@
|
|||||||
package org.tasks.preferences;
|
package org.tasks.preferences;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.tasks.injection.ForApplication;
|
import org.tasks.injection.ForApplication;
|
||||||
|
|
||||||
public class PermissivePermissionChecker extends PermissionChecker {
|
public class PermissivePermissionChecker extends PermissionChecker {
|
||||||
public PermissivePermissionChecker(@ForApplication Context context) {
|
|
||||||
super(context);
|
public PermissivePermissionChecker(@ForApplication Context context) {
|
||||||
}
|
super(context);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean canAccessCalendars() {
|
@Override
|
||||||
return true;
|
public boolean canAccessCalendars() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean canWriteToExternalStorage() {
|
@Override
|
||||||
return true;
|
public boolean canWriteToExternalStorage() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean canAccessAccounts() {
|
@Override
|
||||||
return true;
|
public boolean canAccessAccounts() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean canAccessLocation() {
|
@Override
|
||||||
return true;
|
public boolean canAccessLocation() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean canAccessMic() {
|
@Override
|
||||||
return true;
|
public boolean canAccessMic() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean canAccessMissedCallPermissions() {
|
@Override
|
||||||
return true;
|
public boolean canAccessMissedCallPermissions() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,154 +1,152 @@
|
|||||||
package org.tasks.preferences;
|
package org.tasks.preferences;
|
||||||
|
|
||||||
|
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.tasks.R;
|
import org.tasks.R;
|
||||||
import org.tasks.time.DateTime;
|
import org.tasks.time.DateTime;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class PreferenceTests {
|
public class PreferenceTests {
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private static final int MILLIS_PER_HOUR = (int) TimeUnit.HOURS.toMillis(1);
|
private static final int MILLIS_PER_HOUR = (int) TimeUnit.HOURS.toMillis(1);
|
||||||
|
|
||||||
private Preferences preferences;
|
private Preferences preferences;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
preferences = new Preferences(getTargetContext(), null);
|
preferences = new Preferences(getTargetContext(), null);
|
||||||
preferences.clear();
|
preferences.clear();
|
||||||
preferences.setBoolean(R.string.p_rmd_enable_quiet, true);
|
preferences.setBoolean(R.string.p_rmd_enable_quiet, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotQuietWhenQuietHoursDisabled() {
|
public void testNotQuietWhenQuietHoursDisabled() {
|
||||||
preferences.setBoolean(R.string.p_rmd_enable_quiet, false);
|
preferences.setBoolean(R.string.p_rmd_enable_quiet, false);
|
||||||
setQuietHoursStart(22);
|
setQuietHoursStart(22);
|
||||||
setQuietHoursEnd(10);
|
setQuietHoursEnd(10);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 8, 0, 1).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 8, 0, 1).getMillis();
|
||||||
|
|
||||||
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsQuietAtStartOfQuietHoursNoWrap() {
|
public void testIsQuietAtStartOfQuietHoursNoWrap() {
|
||||||
setQuietHoursStart(18);
|
setQuietHoursStart(18);
|
||||||
setQuietHoursEnd(19);
|
setQuietHoursEnd(19);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 18, 0, 1).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 18, 0, 1).getMillis();
|
||||||
|
|
||||||
assertEquals(new DateTime(2015, 12, 29, 19, 0).getMillis(),
|
assertEquals(new DateTime(2015, 12, 29, 19, 0).getMillis(),
|
||||||
preferences.adjustForQuietHours(dueDate));
|
preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsQuietAtStartOfQuietHoursWrap() {
|
public void testIsQuietAtStartOfQuietHoursWrap() {
|
||||||
setQuietHoursStart(22);
|
setQuietHoursStart(22);
|
||||||
setQuietHoursEnd(10);
|
setQuietHoursEnd(10);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 22, 0, 1).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 22, 0, 1).getMillis();
|
||||||
|
|
||||||
assertEquals(new DateTime(2015, 12, 30, 10, 0).getMillis(),
|
assertEquals(new DateTime(2015, 12, 30, 10, 0).getMillis(),
|
||||||
preferences.adjustForQuietHours(dueDate));
|
preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdjustForQuietHoursNightWrap() {
|
public void testAdjustForQuietHoursNightWrap() {
|
||||||
setQuietHoursStart(22);
|
setQuietHoursStart(22);
|
||||||
setQuietHoursEnd(10);
|
setQuietHoursEnd(10);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 23, 30).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 23, 30).getMillis();
|
||||||
|
|
||||||
assertEquals(new DateTime(2015, 12, 30, 10, 0).getMillis(),
|
assertEquals(new DateTime(2015, 12, 30, 10, 0).getMillis(),
|
||||||
preferences.adjustForQuietHours(dueDate));
|
preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdjustForQuietHoursMorningWrap() {
|
public void testAdjustForQuietHoursMorningWrap() {
|
||||||
setQuietHoursStart(22);
|
setQuietHoursStart(22);
|
||||||
setQuietHoursEnd(10);
|
setQuietHoursEnd(10);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 30, 7, 15).getMillis();
|
long dueDate = new DateTime(2015, 12, 30, 7, 15).getMillis();
|
||||||
|
|
||||||
assertEquals(new DateTime(2015, 12, 30, 10, 0).getMillis(),
|
assertEquals(new DateTime(2015, 12, 30, 10, 0).getMillis(),
|
||||||
preferences.adjustForQuietHours(dueDate));
|
preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdjustForQuietHoursWhenStartAndEndAreSame() {
|
public void testAdjustForQuietHoursWhenStartAndEndAreSame() {
|
||||||
setQuietHoursStart(18);
|
setQuietHoursStart(18);
|
||||||
setQuietHoursEnd(18);
|
setQuietHoursEnd(18);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 18, 0, 0).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 18, 0, 0).getMillis();
|
||||||
|
|
||||||
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotQuietAtEndOfQuietHoursNoWrap() {
|
public void testIsNotQuietAtEndOfQuietHoursNoWrap() {
|
||||||
setQuietHoursStart(17);
|
setQuietHoursStart(17);
|
||||||
setQuietHoursEnd(18);
|
setQuietHoursEnd(18);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 18, 0).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 18, 0).getMillis();
|
||||||
|
|
||||||
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotQuietAtEndOfQuietHoursWrap() {
|
public void testIsNotQuietAtEndOfQuietHoursWrap() {
|
||||||
setQuietHoursStart(22);
|
setQuietHoursStart(22);
|
||||||
setQuietHoursEnd(10);
|
setQuietHoursEnd(10);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 10, 0).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 10, 0).getMillis();
|
||||||
|
|
||||||
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotQuietBeforeNoWrap() {
|
public void testIsNotQuietBeforeNoWrap() {
|
||||||
setQuietHoursStart(17);
|
setQuietHoursStart(17);
|
||||||
setQuietHoursEnd(18);
|
setQuietHoursEnd(18);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 11, 30).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 11, 30).getMillis();
|
||||||
|
|
||||||
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotQuietAfterNoWrap() {
|
public void testIsNotQuietAfterNoWrap() {
|
||||||
setQuietHoursStart(17);
|
setQuietHoursStart(17);
|
||||||
setQuietHoursEnd(18);
|
setQuietHoursEnd(18);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 22, 15).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 22, 15).getMillis();
|
||||||
|
|
||||||
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotQuietWrap() {
|
public void testIsNotQuietWrap() {
|
||||||
setQuietHoursStart(22);
|
setQuietHoursStart(22);
|
||||||
setQuietHoursEnd(10);
|
setQuietHoursEnd(10);
|
||||||
|
|
||||||
long dueDate = new DateTime(2015, 12, 29, 13, 45).getMillis();
|
long dueDate = new DateTime(2015, 12, 29, 13, 45).getMillis();
|
||||||
|
|
||||||
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
assertEquals(dueDate, preferences.adjustForQuietHours(dueDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setQuietHoursStart(int hour) {
|
private void setQuietHoursStart(int hour) {
|
||||||
preferences.setInt(R.string.p_rmd_quietStart, hour * MILLIS_PER_HOUR);
|
preferences.setInt(R.string.p_rmd_quietStart, hour * MILLIS_PER_HOUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setQuietHoursEnd(int hour) {
|
private void setQuietHoursEnd(int hour) {
|
||||||
preferences.setInt(R.string.p_rmd_quietEnd, hour * MILLIS_PER_HOUR);
|
preferences.setInt(R.string.p_rmd_quietEnd, hour * MILLIS_PER_HOUR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,57 @@
|
|||||||
package org.tasks.repeats;
|
package org.tasks.repeats;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import com.google.ical.values.RRule;
|
import com.google.ical.values.RRule;
|
||||||
|
import java.text.ParseException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.tasks.locale.Locale;
|
import org.tasks.locale.Locale;
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
|
|
||||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class RepeatRuleToStringTest {
|
public class RepeatRuleToStringTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void weekly() {
|
public void weekly() {
|
||||||
assertEquals("Repeats weekly", toString("RRULE:FREQ=WEEKLY;INTERVAL=1"));
|
assertEquals("Repeats weekly", toString("RRULE:FREQ=WEEKLY;INTERVAL=1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void weeklyPlural() {
|
public void weeklyPlural() {
|
||||||
assertEquals("Repeats every 2 weeks", toString("RRULE:FREQ=WEEKLY;INTERVAL=2"));
|
assertEquals("Repeats every 2 weeks", toString("RRULE:FREQ=WEEKLY;INTERVAL=2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void weeklyByDay() {
|
public void weeklyByDay() {
|
||||||
assertEquals("Repeats weekly on Mon, Tue, Wed, Thu, Fri", toString("RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR"));
|
assertEquals("Repeats weekly on Mon, Tue, Wed, Thu, Fri",
|
||||||
}
|
toString("RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR"));
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void printDaysInRepeatRuleOrder() {
|
@Test
|
||||||
assertEquals("Repeats weekly on Fri, Thu, Wed, Tue, Mon", toString("RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=FR,TH,WE,TU,MO"));
|
public void printDaysInRepeatRuleOrder() {
|
||||||
}
|
assertEquals("Repeats weekly on Fri, Thu, Wed, Tue, Mon",
|
||||||
|
toString("RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=FR,TH,WE,TU,MO"));
|
||||||
@Test
|
}
|
||||||
public void useLocaleForDays() {
|
|
||||||
assertEquals("Wiederhole wöchentlich am Sa., So.", toString("de", "RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=SA,SU"));
|
@Test
|
||||||
}
|
public void useLocaleForDays() {
|
||||||
|
assertEquals("Wiederhole wöchentlich am Sa., So.",
|
||||||
private String toString(String rrule) {
|
toString("de", "RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=SA,SU"));
|
||||||
return toString(null, rrule);
|
}
|
||||||
}
|
|
||||||
|
private String toString(String rrule) {
|
||||||
private String toString(String language, String rrule) {
|
return toString(null, rrule);
|
||||||
try {
|
}
|
||||||
Locale locale = new Locale(java.util.Locale.getDefault(), language, -1);
|
|
||||||
return new RepeatRuleToString(locale.createConfigurationContext(getTargetContext()), locale)
|
private String toString(String language, String rrule) {
|
||||||
.toString(new RRule(rrule));
|
try {
|
||||||
} catch (ParseException e) {
|
Locale locale = new Locale(java.util.Locale.getDefault(), language, -1);
|
||||||
throw new RuntimeException(e);
|
return new RepeatRuleToString(locale.createConfigurationContext(getTargetContext()), locale)
|
||||||
}
|
.toString(new RRule(rrule));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,337 +1,356 @@
|
|||||||
package org.tasks.time;
|
package org.tasks.time;
|
||||||
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertFalse;
|
||||||
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.tasks.Freeze;
|
import org.tasks.Freeze;
|
||||||
import org.tasks.Snippet;
|
import org.tasks.Snippet;
|
||||||
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static junit.framework.Assert.assertFalse;
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class DateTimeTest {
|
public class DateTimeTest {
|
||||||
@Test
|
|
||||||
public void testGetMillisOfDay() {
|
|
||||||
assertEquals(7248412, new DateTime(2015, 10, 6, 2, 0, 48, 412).getMillisOfDay());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithMillisOfDay() {
|
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 10, 6, 2, 0, 48, 412),
|
|
||||||
new DateTime(2015, 10, 6, 0, 0, 0, 0).withMillisOfDay(7248412));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithMillisOfDayDuringDST() {
|
|
||||||
TimeZone def = TimeZone.getDefault();
|
|
||||||
try {
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
|
||||||
assertEquals(2, new DateTime(2015, 10, 31, 2, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2)).getHourOfDay());
|
|
||||||
} finally {
|
|
||||||
TimeZone.setDefault(def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithMillisOfDayAfterDST() {
|
|
||||||
TimeZone def = TimeZone.getDefault();
|
|
||||||
try {
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
|
||||||
assertEquals(2, new DateTime(2015, 11, 2, 2, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2)).getHourOfDay());
|
|
||||||
} finally {
|
|
||||||
TimeZone.setDefault(def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithMillisOfDayStartDST() {
|
|
||||||
TimeZone def = TimeZone.getDefault();
|
|
||||||
try {
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
|
||||||
assertEquals(1, new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(1)).getHourOfDay());
|
|
||||||
assertEquals(3, new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2)).getHourOfDay());
|
|
||||||
assertEquals(3, new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(3)).getHourOfDay());
|
|
||||||
assertEquals(4, new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(4)).getHourOfDay());
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2)).getMillis(),
|
|
||||||
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(3)).getMillis());
|
|
||||||
} finally {
|
|
||||||
TimeZone.setDefault(def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithMillisOfDayEndDST() {
|
|
||||||
TimeZone def = TimeZone.getDefault();
|
|
||||||
try {
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
|
||||||
assertEquals(1, new DateTime(2015, 11, 1, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(1)).getHourOfDay());
|
|
||||||
assertEquals(2, new DateTime(2015, 11, 1, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2)).getHourOfDay());
|
|
||||||
assertEquals(3, new DateTime(2015, 11, 1, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(3)).getHourOfDay());
|
|
||||||
} finally {
|
|
||||||
TimeZone.setDefault(def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPlusMonths() {
|
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 11, 6, 2, 0, 48, 412),
|
|
||||||
new DateTime(2015, 10, 6, 2, 0, 48, 412).plusMonths(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPlusMonthsWrapYear() {
|
|
||||||
assertEquals(
|
|
||||||
new DateTime(2016, 1, 6, 2, 0, 48, 412),
|
|
||||||
new DateTime(2015, 10, 6, 2, 0, 48, 412).plusMonths(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDayOfMonth() {
|
|
||||||
assertEquals(5, new DateTime(2015, 10, 5, 0, 0, 0).getDayOfMonth());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPlusDays() {
|
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 10, 6, 2, 0, 48, 412),
|
|
||||||
new DateTime(2015, 10, 5, 2, 0, 48, 412).plusDays(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPlusDaysWrapMonth() {
|
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 11, 1, 2, 0, 48, 412),
|
|
||||||
new DateTime(2015, 10, 31, 2, 0, 48, 412).plusDays(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMinuteOfHour() {
|
|
||||||
assertEquals(43, new DateTime(2015, 10, 5, 2, 43, 48).getMinuteOfHour());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsEndOfMonth() {
|
|
||||||
assertTrue(new DateTime(2014, 1, 31, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 2, 28, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 3, 31, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 4, 30, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 5, 31, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 6, 30, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 7, 31, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 8, 31, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 9, 30, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 10, 31, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 11, 30, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2014, 12, 31, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNotTheEndOfTheMonth() {
|
|
||||||
for (int month = 1; month <= 12; month++) {
|
|
||||||
int lastDay = new DateTime(2014, month, 1, 0, 0, 0, 0).getNumberOfDaysInMonth();
|
|
||||||
for (int day = 1; day < lastDay; day++) {
|
|
||||||
assertFalse(new DateTime(2014, month, day, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCheckEndOfMonthDuringLeapYear() {
|
|
||||||
assertFalse(new DateTime(2016, 2, 28, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
assertTrue(new DateTime(2016, 2, 29, 0, 0, 0).isLastDayOfMonth());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNumberOfDaysInMonth() {
|
|
||||||
assertEquals(31, new DateTime(2015, 1, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(28, new DateTime(2015, 2, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(31, new DateTime(2015, 3, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(30, new DateTime(2015, 4, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(31, new DateTime(2015, 5, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(30, new DateTime(2015, 6, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(31, new DateTime(2015, 7, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(31, new DateTime(2015, 8, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(30, new DateTime(2015, 9, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(31, new DateTime(2015, 10, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(30, new DateTime(2015, 11, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
assertEquals(31, new DateTime(2015, 12, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithMillisOfSecond() {
|
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 11, 6, 13, 34, 56, 453),
|
|
||||||
new DateTime(2015, 11, 6, 13, 34, 56, 0).withMillisOfSecond(453));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithHourOfDay() {
|
public void testGetMillisOfDay() {
|
||||||
assertEquals(
|
assertEquals(7248412, new DateTime(2015, 10, 6, 2, 0, 48, 412).getMillisOfDay());
|
||||||
new DateTime(2015, 11, 6, 23, 0, 0),
|
}
|
||||||
new DateTime(2015, 11, 6, 1, 0, 0).withHourOfDay(23));
|
|
||||||
}
|
@Test
|
||||||
|
public void testWithMillisOfDay() {
|
||||||
@Test
|
assertEquals(
|
||||||
public void testWithMinuteOfHour() {
|
new DateTime(2015, 10, 6, 2, 0, 48, 412),
|
||||||
assertEquals(
|
new DateTime(2015, 10, 6, 0, 0, 0, 0).withMillisOfDay(7248412));
|
||||||
new DateTime(2015, 11, 6, 23, 13, 0),
|
}
|
||||||
new DateTime(2015, 11, 6, 23, 1, 0).withMinuteOfHour(13));
|
|
||||||
}
|
@Test
|
||||||
|
public void testWithMillisOfDayDuringDST() {
|
||||||
@Test
|
TimeZone def = TimeZone.getDefault();
|
||||||
public void testWithSecondOfMinute() {
|
try {
|
||||||
assertEquals(
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
||||||
new DateTime(2015, 11, 6, 23, 13, 56),
|
assertEquals(2,
|
||||||
new DateTime(2015, 11, 6, 23, 13, 1).withSecondOfMinute(56));
|
new DateTime(2015, 10, 31, 2, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2))
|
||||||
}
|
.getHourOfDay());
|
||||||
|
} finally {
|
||||||
@Test
|
TimeZone.setDefault(def);
|
||||||
public void testGetYear() {
|
}
|
||||||
assertEquals(2015, new DateTime(2015, 1, 1, 1, 1, 1).getYear());
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
public void testWithMillisOfDayAfterDST() {
|
||||||
public void testMinusMinutes() {
|
TimeZone def = TimeZone.getDefault();
|
||||||
assertEquals(
|
try {
|
||||||
new DateTime(2015, 11, 4, 23, 59, 0),
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
||||||
new DateTime(2015, 11, 5, 0, 1, 0).minusMinutes(2));
|
assertEquals(2,
|
||||||
}
|
new DateTime(2015, 11, 2, 2, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2))
|
||||||
|
.getHourOfDay());
|
||||||
@Test
|
} finally {
|
||||||
public void testIsBefore() {
|
TimeZone.setDefault(def);
|
||||||
assertTrue(new DateTime(2015, 11, 4, 23, 59, 0)
|
}
|
||||||
.isBefore(new DateTime(2015, 11, 4, 23, 59, 1)));
|
}
|
||||||
|
|
||||||
assertFalse(new DateTime(2015, 11, 4, 23, 59, 0)
|
@Test
|
||||||
.isBefore(new DateTime(2015, 11, 4, 23, 59, 0)));
|
public void testWithMillisOfDayStartDST() {
|
||||||
}
|
TimeZone def = TimeZone.getDefault();
|
||||||
|
try {
|
||||||
@Test
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
||||||
public void testGetMonthOfYear() {
|
assertEquals(1,
|
||||||
assertEquals(1, new DateTime(2015, 1, 2, 3, 4, 5).getMonthOfYear());
|
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(1))
|
||||||
}
|
.getHourOfDay());
|
||||||
|
assertEquals(3,
|
||||||
@Test
|
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2))
|
||||||
public void testIsAfter() {
|
.getHourOfDay());
|
||||||
assertTrue(new DateTime(2015, 11, 4, 23, 59, 1)
|
assertEquals(3,
|
||||||
.isAfter(new DateTime(2015, 11, 4, 23, 59, 0)));
|
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(3))
|
||||||
|
.getHourOfDay());
|
||||||
assertFalse(new DateTime(2015, 11, 4, 23, 59, 0)
|
assertEquals(4,
|
||||||
.isAfter(new DateTime(2015, 11, 4, 23, 59, 0)));
|
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(4))
|
||||||
}
|
.getHourOfDay());
|
||||||
|
|
||||||
@Test
|
assertEquals(
|
||||||
public void testWithYear() {
|
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2))
|
||||||
assertEquals(
|
.getMillis(),
|
||||||
new DateTime(2016, 1, 1, 1, 1, 1),
|
new DateTime(2015, 3, 8, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(3))
|
||||||
new DateTime(2015, 1, 1, 1, 1, 1).withYear(2016));
|
.getMillis());
|
||||||
}
|
} finally {
|
||||||
|
TimeZone.setDefault(def);
|
||||||
@Test
|
}
|
||||||
public void testWithMonthOfYear() {
|
}
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 1, 2, 3, 4, 5),
|
@Test
|
||||||
new DateTime(2015, 2, 2, 3, 4, 5).withMonthOfYear(1));
|
public void testWithMillisOfDayEndDST() {
|
||||||
}
|
TimeZone def = TimeZone.getDefault();
|
||||||
|
try {
|
||||||
@Test
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
||||||
public void testGetHourOfDay() {
|
assertEquals(1,
|
||||||
assertEquals(3, new DateTime(2015, 1, 2, 3, 4, 5).getHourOfDay());
|
new DateTime(2015, 11, 1, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(1))
|
||||||
}
|
.getHourOfDay());
|
||||||
|
assertEquals(2,
|
||||||
@Test
|
new DateTime(2015, 11, 1, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(2))
|
||||||
public void testWithDayOfMonth() {
|
.getHourOfDay());
|
||||||
assertEquals(
|
assertEquals(3,
|
||||||
new DateTime(2015, 1, 2, 3, 4, 5),
|
new DateTime(2015, 11, 1, 0, 0, 0).withMillisOfDay((int) TimeUnit.HOURS.toMillis(3))
|
||||||
new DateTime(2015, 1, 1, 3, 4, 5).withDayOfMonth(2));
|
.getHourOfDay());
|
||||||
}
|
} finally {
|
||||||
|
TimeZone.setDefault(def);
|
||||||
@Test
|
}
|
||||||
public void testPlusMinutes() {
|
}
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 1, 2, 3, 4, 5),
|
@Test
|
||||||
new DateTime(2015, 1, 2, 2, 59, 5).plusMinutes(5));
|
public void testPlusMonths() {
|
||||||
}
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 2, 0, 48, 412),
|
||||||
@Test
|
new DateTime(2015, 10, 6, 2, 0, 48, 412).plusMonths(1));
|
||||||
public void testPlusHours() {
|
}
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 1, 2, 3, 4, 5),
|
@Test
|
||||||
new DateTime(2015, 1, 1, 3, 4, 5).plusHours(24));
|
public void testPlusMonthsWrapYear() {
|
||||||
}
|
assertEquals(
|
||||||
|
new DateTime(2016, 1, 6, 2, 0, 48, 412),
|
||||||
@Test
|
new DateTime(2015, 10, 6, 2, 0, 48, 412).plusMonths(3));
|
||||||
public void testPlusWeeks() {
|
}
|
||||||
assertEquals(
|
|
||||||
new DateTime(2015, 1, 2, 3, 4, 5),
|
@Test
|
||||||
new DateTime(2014, 12, 12, 3, 4, 5).plusWeeks(3));
|
public void testGetDayOfMonth() {
|
||||||
}
|
assertEquals(5, new DateTime(2015, 10, 5, 0, 0, 0).getDayOfMonth());
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void testIsBeforeNow() {
|
@Test
|
||||||
Freeze.freezeAt(new DateTime(2015, 10, 6, 16, 15, 27)).thawAfter(new Snippet() {{
|
public void testPlusDays() {
|
||||||
assertFalse(new DateTime(2015, 10, 6, 16, 15, 27).isBeforeNow());
|
assertEquals(
|
||||||
assertTrue(new DateTime(2015, 10, 6, 16, 15, 26).isBeforeNow());
|
new DateTime(2015, 10, 6, 2, 0, 48, 412),
|
||||||
}});
|
new DateTime(2015, 10, 5, 2, 0, 48, 412).plusDays(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMinusMillis() {
|
public void testPlusDaysWrapMonth() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
new DateTime(2015, 11, 6, 16, 18, 20, 452),
|
new DateTime(2015, 11, 1, 2, 0, 48, 412),
|
||||||
new DateTime(2015, 11, 6, 16, 18, 21, 374).minusMillis(922));
|
new DateTime(2015, 10, 31, 2, 0, 48, 412).plusDays(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMinusDays() {
|
public void testMinuteOfHour() {
|
||||||
assertEquals(
|
assertEquals(43, new DateTime(2015, 10, 5, 2, 43, 48).getMinuteOfHour());
|
||||||
new DateTime(2015, 11, 6, 16, 19, 16),
|
}
|
||||||
new DateTime(2015, 12, 4, 16, 19, 16).minusDays(28));
|
|
||||||
|
@Test
|
||||||
assertEquals(
|
public void testIsEndOfMonth() {
|
||||||
new DateTime(2015, 11, 6, 16, 19, 16),
|
assertTrue(new DateTime(2014, 1, 31, 0, 0, 0).isLastDayOfMonth());
|
||||||
new DateTime(2015, 11, 7, 16, 19, 16).minusDays(1));
|
assertTrue(new DateTime(2014, 2, 28, 0, 0, 0).isLastDayOfMonth());
|
||||||
}
|
assertTrue(new DateTime(2014, 3, 31, 0, 0, 0).isLastDayOfMonth());
|
||||||
|
assertTrue(new DateTime(2014, 4, 30, 0, 0, 0).isLastDayOfMonth());
|
||||||
@Test
|
assertTrue(new DateTime(2014, 5, 31, 0, 0, 0).isLastDayOfMonth());
|
||||||
public void testGetSecondOfMinute() {
|
assertTrue(new DateTime(2014, 6, 30, 0, 0, 0).isLastDayOfMonth());
|
||||||
assertEquals(32, new DateTime(2015, 11, 6, 16, 19, 32).getSecondOfMinute());
|
assertTrue(new DateTime(2014, 7, 31, 0, 0, 0).isLastDayOfMonth());
|
||||||
}
|
assertTrue(new DateTime(2014, 8, 31, 0, 0, 0).isLastDayOfMonth());
|
||||||
|
assertTrue(new DateTime(2014, 9, 30, 0, 0, 0).isLastDayOfMonth());
|
||||||
@Test
|
assertTrue(new DateTime(2014, 10, 31, 0, 0, 0).isLastDayOfMonth());
|
||||||
public void testToUTC() {
|
assertTrue(new DateTime(2014, 11, 30, 0, 0, 0).isLastDayOfMonth());
|
||||||
TimeZone def = TimeZone.getDefault();
|
assertTrue(new DateTime(2014, 12, 31, 0, 0, 0).isLastDayOfMonth());
|
||||||
try {
|
}
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
|
||||||
assertEquals(
|
@Test
|
||||||
new DateTime(2015, 10, 6, 14, 45, 15, 0, TimeZone.getTimeZone("GMT")),
|
public void testNotTheEndOfTheMonth() {
|
||||||
new DateTime(2015, 10, 6, 9, 45, 15).toUTC());
|
for (int month = 1; month <= 12; month++) {
|
||||||
} finally {
|
int lastDay = new DateTime(2014, month, 1, 0, 0, 0, 0).getNumberOfDaysInMonth();
|
||||||
TimeZone.setDefault(def);
|
for (int day = 1; day < lastDay; day++) {
|
||||||
}
|
assertFalse(new DateTime(2014, month, day, 0, 0, 0).isLastDayOfMonth());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Test
|
}
|
||||||
public void testStartOfMinute() {
|
|
||||||
assertEquals(
|
@Test
|
||||||
new DateTime(2017, 9, 3, 0, 51, 0, 0),
|
public void testCheckEndOfMonthDuringLeapYear() {
|
||||||
new DateTime(2017, 9, 3, 0, 51, 13, 427).startOfMinute());
|
assertFalse(new DateTime(2016, 2, 28, 0, 0, 0).isLastDayOfMonth());
|
||||||
}
|
assertTrue(new DateTime(2016, 2, 29, 0, 0, 0).isLastDayOfMonth());
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void testEndOfMinute() {
|
@Test
|
||||||
assertEquals(
|
public void testNumberOfDaysInMonth() {
|
||||||
new DateTime(2017, 9, 22, 14, 47, 59, 999),
|
assertEquals(31, new DateTime(2015, 1, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
new DateTime(2017, 9, 22, 14, 47, 14, 453).endOfMinute());
|
assertEquals(28, new DateTime(2015, 2, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
}
|
assertEquals(31, new DateTime(2015, 3, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(30, new DateTime(2015, 4, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(31, new DateTime(2015, 5, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(30, new DateTime(2015, 6, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(31, new DateTime(2015, 7, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(31, new DateTime(2015, 8, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(30, new DateTime(2015, 9, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(31, new DateTime(2015, 10, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(30, new DateTime(2015, 11, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
assertEquals(31, new DateTime(2015, 12, 5, 9, 45, 34).getNumberOfDaysInMonth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithMillisOfSecond() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 13, 34, 56, 453),
|
||||||
|
new DateTime(2015, 11, 6, 13, 34, 56, 0).withMillisOfSecond(453));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithHourOfDay() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 23, 0, 0),
|
||||||
|
new DateTime(2015, 11, 6, 1, 0, 0).withHourOfDay(23));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithMinuteOfHour() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 23, 13, 0),
|
||||||
|
new DateTime(2015, 11, 6, 23, 1, 0).withMinuteOfHour(13));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithSecondOfMinute() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 23, 13, 56),
|
||||||
|
new DateTime(2015, 11, 6, 23, 13, 1).withSecondOfMinute(56));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetYear() {
|
||||||
|
assertEquals(2015, new DateTime(2015, 1, 1, 1, 1, 1).getYear());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinusMinutes() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 4, 23, 59, 0),
|
||||||
|
new DateTime(2015, 11, 5, 0, 1, 0).minusMinutes(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsBefore() {
|
||||||
|
assertTrue(new DateTime(2015, 11, 4, 23, 59, 0)
|
||||||
|
.isBefore(new DateTime(2015, 11, 4, 23, 59, 1)));
|
||||||
|
|
||||||
|
assertFalse(new DateTime(2015, 11, 4, 23, 59, 0)
|
||||||
|
.isBefore(new DateTime(2015, 11, 4, 23, 59, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMonthOfYear() {
|
||||||
|
assertEquals(1, new DateTime(2015, 1, 2, 3, 4, 5).getMonthOfYear());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAfter() {
|
||||||
|
assertTrue(new DateTime(2015, 11, 4, 23, 59, 1)
|
||||||
|
.isAfter(new DateTime(2015, 11, 4, 23, 59, 0)));
|
||||||
|
|
||||||
|
assertFalse(new DateTime(2015, 11, 4, 23, 59, 0)
|
||||||
|
.isAfter(new DateTime(2015, 11, 4, 23, 59, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithYear() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2016, 1, 1, 1, 1, 1),
|
||||||
|
new DateTime(2015, 1, 1, 1, 1, 1).withYear(2016));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithMonthOfYear() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 1, 2, 3, 4, 5),
|
||||||
|
new DateTime(2015, 2, 2, 3, 4, 5).withMonthOfYear(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetHourOfDay() {
|
||||||
|
assertEquals(3, new DateTime(2015, 1, 2, 3, 4, 5).getHourOfDay());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithDayOfMonth() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 1, 2, 3, 4, 5),
|
||||||
|
new DateTime(2015, 1, 1, 3, 4, 5).withDayOfMonth(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlusMinutes() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 1, 2, 3, 4, 5),
|
||||||
|
new DateTime(2015, 1, 2, 2, 59, 5).plusMinutes(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlusHours() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 1, 2, 3, 4, 5),
|
||||||
|
new DateTime(2015, 1, 1, 3, 4, 5).plusHours(24));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlusWeeks() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 1, 2, 3, 4, 5),
|
||||||
|
new DateTime(2014, 12, 12, 3, 4, 5).plusWeeks(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsBeforeNow() {
|
||||||
|
Freeze.freezeAt(new DateTime(2015, 10, 6, 16, 15, 27)).thawAfter(new Snippet() {{
|
||||||
|
assertFalse(new DateTime(2015, 10, 6, 16, 15, 27).isBeforeNow());
|
||||||
|
assertTrue(new DateTime(2015, 10, 6, 16, 15, 26).isBeforeNow());
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinusMillis() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 16, 18, 20, 452),
|
||||||
|
new DateTime(2015, 11, 6, 16, 18, 21, 374).minusMillis(922));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinusDays() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 16, 19, 16),
|
||||||
|
new DateTime(2015, 12, 4, 16, 19, 16).minusDays(28));
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 11, 6, 16, 19, 16),
|
||||||
|
new DateTime(2015, 11, 7, 16, 19, 16).minusDays(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetSecondOfMinute() {
|
||||||
|
assertEquals(32, new DateTime(2015, 11, 6, 16, 19, 32).getSecondOfMinute());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToUTC() {
|
||||||
|
TimeZone def = TimeZone.getDefault();
|
||||||
|
try {
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2015, 10, 6, 14, 45, 15, 0, TimeZone.getTimeZone("GMT")),
|
||||||
|
new DateTime(2015, 10, 6, 9, 45, 15).toUTC());
|
||||||
|
} finally {
|
||||||
|
TimeZone.setDefault(def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartOfMinute() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2017, 9, 3, 0, 51, 0, 0),
|
||||||
|
new DateTime(2017, 9, 3, 0, 51, 13, 427).startOfMinute());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEndOfMinute() {
|
||||||
|
assertEquals(
|
||||||
|
new DateTime(2017, 9, 22, 14, 47, 59, 999),
|
||||||
|
new DateTime(2017, 9, 22, 14, 47, 14, 453).endOfMinute());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
package org.tasks.makers;
|
package org.tasks.makers;
|
||||||
|
|
||||||
|
import static com.natpryce.makeiteasy.Property.newProperty;
|
||||||
|
import static org.tasks.makers.Maker.make;
|
||||||
|
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
||||||
|
|
||||||
import com.google.api.client.util.DateTime;
|
import com.google.api.client.util.DateTime;
|
||||||
import com.google.api.services.tasks.model.TaskList;
|
import com.google.api.services.tasks.model.TaskList;
|
||||||
import com.natpryce.makeiteasy.Instantiator;
|
import com.natpryce.makeiteasy.Instantiator;
|
||||||
import com.natpryce.makeiteasy.Property;
|
import com.natpryce.makeiteasy.Property;
|
||||||
import com.natpryce.makeiteasy.PropertyValue;
|
import com.natpryce.makeiteasy.PropertyValue;
|
||||||
|
|
||||||
import static com.natpryce.makeiteasy.Property.newProperty;
|
|
||||||
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
|
|
||||||
import static org.tasks.makers.Maker.make;
|
|
||||||
|
|
||||||
public class RemoteGtaskListMaker {
|
public class RemoteGtaskListMaker {
|
||||||
public static final Property<TaskList, String> REMOTE_ID = newProperty();
|
|
||||||
public static final Property<TaskList, String> NAME = newProperty();
|
|
||||||
|
|
||||||
public static TaskList newRemoteList(PropertyValue<? super TaskList, ?>... properties) {
|
public static final Property<TaskList, String> REMOTE_ID = newProperty();
|
||||||
return make(instantiator, properties);
|
public static final Property<TaskList, String> NAME = newProperty();
|
||||||
}
|
private static final Instantiator<TaskList> instantiator = lookup -> new TaskList()
|
||||||
|
.setId(lookup.valueOf(REMOTE_ID, "1"))
|
||||||
|
.setTitle(lookup.valueOf(NAME, "Default"))
|
||||||
|
.setUpdated(new DateTime(currentTimeMillis()));
|
||||||
|
|
||||||
private static final Instantiator<TaskList> instantiator = lookup -> new TaskList()
|
public static TaskList newRemoteList(PropertyValue<? super TaskList, ?>... properties) {
|
||||||
.setId(lookup.valueOf(REMOTE_ID, "1"))
|
return make(instantiator, properties);
|
||||||
.setTitle(lookup.valueOf(NAME, "Default"))
|
}
|
||||||
.setUpdated(new DateTime(currentTimeMillis()));
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
package org.tasks;
|
package org.tasks;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.tasks.caldav.CaldavAccountManager;
|
import org.tasks.caldav.CaldavAccountManager;
|
||||||
import org.tasks.preferences.Preferences;
|
import org.tasks.preferences.Preferences;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
public class FlavorSetup {
|
public class FlavorSetup {
|
||||||
private final CaldavAccountManager caldavAccountManager;
|
|
||||||
private final Preferences preferences;
|
|
||||||
|
|
||||||
@Inject
|
private final CaldavAccountManager caldavAccountManager;
|
||||||
public FlavorSetup(CaldavAccountManager caldavAccountManager, Preferences preferences) {
|
private final Preferences preferences;
|
||||||
this.caldavAccountManager = caldavAccountManager;
|
|
||||||
this.preferences = preferences;
|
@Inject
|
||||||
}
|
public FlavorSetup(CaldavAccountManager caldavAccountManager, Preferences preferences) {
|
||||||
|
this.caldavAccountManager = caldavAccountManager;
|
||||||
|
this.preferences = preferences;
|
||||||
|
}
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
caldavAccountManager.setBackgroundSynchronization(preferences.getBoolean(R.string.p_background_sync, true));
|
caldavAccountManager
|
||||||
}
|
.setBackgroundSynchronization(preferences.getBoolean(R.string.p_background_sync, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,40 @@
|
|||||||
package org.tasks.analytics;
|
package org.tasks.analytics;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class Tracker {
|
public class Tracker {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Tracker() {
|
public Tracker() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrackingEnabled(boolean enabled) {
|
public void setTrackingEnabled(boolean enabled) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportException(Throwable t) {
|
public void reportException(Throwable t) {
|
||||||
Timber.e(t, t.getMessage());
|
Timber.e(t, t.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportException(Thread thread, Throwable t) {
|
public void reportException(Thread thread, Throwable t) {
|
||||||
Timber.e(t, t.getMessage());
|
Timber.e(t, t.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportEvent(Tracking.Events event) {
|
public void reportEvent(Tracking.Events event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportEvent(Tracking.Events event, String string) {
|
public void reportEvent(Tracking.Events event, String string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportEvent(Tracking.Events setPreference, int resId, String s) {
|
public void reportEvent(Tracking.Events setPreference, int resId, String s) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportEvent(Tracking.Events category, String action, String label) {
|
public void reportEvent(Tracking.Events category, String action, String label) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,39 @@
|
|||||||
package org.tasks.gtasks;
|
package org.tasks.gtasks;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
|
||||||
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
|
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
|
||||||
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
|
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
public class PlayServices {
|
public class PlayServices {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PlayServices() {
|
public PlayServices() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayServicesAvailable() {
|
public boolean isPlayServicesAvailable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refreshAndCheck() {
|
public boolean refreshAndCheck() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolve(Activity activity) {
|
public void resolve(Activity activity) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean clearToken(GoogleAccountCredential googleAccountCredential) {
|
public boolean clearToken(GoogleAccountCredential googleAccountCredential) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAuthToken(GtasksLoginActivity gtasksLoginActivity, String a, GtasksLoginActivity.AuthResultHandler authResultHandler) {
|
public void getAuthToken(GtasksLoginActivity gtasksLoginActivity, String a,
|
||||||
|
GtasksLoginActivity.AuthResultHandler authResultHandler) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
package org.tasks.location;
|
package org.tasks.location;
|
||||||
|
|
||||||
import org.tasks.data.Location;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import org.tasks.data.Location;
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
public class GeofenceApi {
|
public class GeofenceApi {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GeofenceApi() {
|
public GeofenceApi() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(List<Location> activeGeofences) {
|
public void register(List<Location> activeGeofences) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel(Location geofence) {
|
public void cancel(Location geofence) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel(List<Location> geofences) {
|
public void cancel(List<Location> geofences) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,42 +1,41 @@
|
|||||||
package org.tasks;
|
package org.tasks;
|
||||||
|
|
||||||
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
|
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.tasks.billing.InventoryHelper;
|
import org.tasks.billing.InventoryHelper;
|
||||||
import org.tasks.caldav.CaldavAccountManager;
|
import org.tasks.caldav.CaldavAccountManager;
|
||||||
import org.tasks.gtasks.GoogleAccountManager;
|
import org.tasks.gtasks.GoogleAccountManager;
|
||||||
import org.tasks.gtasks.PlayServices;
|
import org.tasks.gtasks.PlayServices;
|
||||||
import org.tasks.preferences.Preferences;
|
import org.tasks.preferences.Preferences;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
public class FlavorSetup {
|
public class FlavorSetup {
|
||||||
|
|
||||||
private final GtasksPreferenceService gtasksPreferenceService;
|
private final GtasksPreferenceService gtasksPreferenceService;
|
||||||
private final InventoryHelper inventoryHelper;
|
private final InventoryHelper inventoryHelper;
|
||||||
private final Preferences preferences;
|
private final Preferences preferences;
|
||||||
private final PlayServices playServices;
|
private final PlayServices playServices;
|
||||||
private final GoogleAccountManager googleAccountManager;
|
private final GoogleAccountManager googleAccountManager;
|
||||||
private final CaldavAccountManager caldavAccountManager;
|
private final CaldavAccountManager caldavAccountManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FlavorSetup(GtasksPreferenceService gtasksPreferenceService, InventoryHelper inventoryHelper,
|
public FlavorSetup(GtasksPreferenceService gtasksPreferenceService,
|
||||||
Preferences preferences, PlayServices playServices,
|
InventoryHelper inventoryHelper,
|
||||||
GoogleAccountManager googleAccountManager, CaldavAccountManager caldavAccountManager) {
|
Preferences preferences, PlayServices playServices,
|
||||||
this.gtasksPreferenceService = gtasksPreferenceService;
|
GoogleAccountManager googleAccountManager, CaldavAccountManager caldavAccountManager) {
|
||||||
this.inventoryHelper = inventoryHelper;
|
this.gtasksPreferenceService = gtasksPreferenceService;
|
||||||
this.preferences = preferences;
|
this.inventoryHelper = inventoryHelper;
|
||||||
this.playServices = playServices;
|
this.preferences = preferences;
|
||||||
this.googleAccountManager = googleAccountManager;
|
this.playServices = playServices;
|
||||||
this.caldavAccountManager = caldavAccountManager;
|
this.googleAccountManager = googleAccountManager;
|
||||||
}
|
this.caldavAccountManager = caldavAccountManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
inventoryHelper.initialize();
|
inventoryHelper.initialize();
|
||||||
gtasksPreferenceService.stopOngoing(); // if sync ongoing flag was set, clear it
|
gtasksPreferenceService.stopOngoing(); // if sync ongoing flag was set, clear it
|
||||||
boolean backgroundSyncEnabled = preferences.getBoolean(R.string.p_background_sync, true);
|
boolean backgroundSyncEnabled = preferences.getBoolean(R.string.p_background_sync, true);
|
||||||
googleAccountManager.setBackgroundSynchronization(backgroundSyncEnabled);
|
googleAccountManager.setBackgroundSynchronization(backgroundSyncEnabled);
|
||||||
caldavAccountManager.setBackgroundSynchronization(backgroundSyncEnabled);
|
caldavAccountManager.setBackgroundSynchronization(backgroundSyncEnabled);
|
||||||
playServices.refresh();
|
playServices.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,111 +1,110 @@
|
|||||||
package org.tasks.location;
|
package org.tasks.location;
|
||||||
|
|
||||||
|
import static com.google.android.gms.location.Geofence.NEVER_EXPIRE;
|
||||||
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
import static com.google.common.collect.Lists.newArrayList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
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;
|
||||||
|
|
||||||
import com.google.android.gms.common.api.PendingResult;
|
import com.google.android.gms.common.api.PendingResult;
|
||||||
import com.google.android.gms.common.api.Status;
|
import com.google.android.gms.common.api.Status;
|
||||||
import com.google.android.gms.location.GeofencingRequest;
|
import com.google.android.gms.location.GeofencingRequest;
|
||||||
import com.google.android.gms.location.LocationServices;
|
import com.google.android.gms.location.LocationServices;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.tasks.R;
|
import org.tasks.R;
|
||||||
import org.tasks.data.Location;
|
import org.tasks.data.Location;
|
||||||
import org.tasks.injection.ForApplication;
|
import org.tasks.injection.ForApplication;
|
||||||
import org.tasks.preferences.PermissionChecker;
|
import org.tasks.preferences.PermissionChecker;
|
||||||
import org.tasks.preferences.Preferences;
|
import org.tasks.preferences.Preferences;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static com.google.android.gms.location.Geofence.NEVER_EXPIRE;
|
|
||||||
import static com.google.common.collect.Iterables.transform;
|
|
||||||
import static com.google.common.collect.Lists.newArrayList;
|
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
|
|
||||||
public class GeofenceApi {
|
public class GeofenceApi {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final Preferences preferences;
|
private final Preferences preferences;
|
||||||
private final PermissionChecker permissionChecker;
|
private final PermissionChecker permissionChecker;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GeofenceApi(@ForApplication Context context, Preferences preferences, PermissionChecker permissionChecker) {
|
public GeofenceApi(@ForApplication Context context, Preferences preferences,
|
||||||
this.context = context;
|
PermissionChecker permissionChecker) {
|
||||||
this.preferences = preferences;
|
this.context = context;
|
||||||
this.permissionChecker = permissionChecker;
|
this.preferences = preferences;
|
||||||
}
|
this.permissionChecker = permissionChecker;
|
||||||
|
}
|
||||||
public void register(final List<Location> locations) {
|
|
||||||
if (locations.isEmpty() || !permissionChecker.canAccessLocation()) {
|
public void register(final List<Location> locations) {
|
||||||
return;
|
if (locations.isEmpty() || !permissionChecker.canAccessLocation()) {
|
||||||
}
|
return;
|
||||||
|
|
||||||
newClient(client -> {
|
|
||||||
@SuppressWarnings("ResourceType")
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
PendingResult<Status> result = LocationServices.GeofencingApi.addGeofences(
|
|
||||||
client,
|
|
||||||
getRequests(locations),
|
|
||||||
PendingIntent.getBroadcast(context, 0, new Intent(context, GeofenceTransitionsIntentService.Broadcast.class), PendingIntent.FLAG_UPDATE_CURRENT));
|
|
||||||
result.setResultCallback(status -> {
|
|
||||||
if (status.isSuccess()) {
|
|
||||||
Timber.i("Registered %s", locations);
|
|
||||||
} else {
|
|
||||||
Timber.e("Failed to register %s", locations);
|
|
||||||
}
|
|
||||||
|
|
||||||
client.disconnect();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancel(final Location location) {
|
|
||||||
cancel(singletonList(location));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel(final List<Location> locations) {
|
newClient(client -> {
|
||||||
if (locations.isEmpty() || !permissionChecker.canAccessLocation()) {
|
@SuppressWarnings("ResourceType")
|
||||||
return;
|
@SuppressLint("MissingPermission")
|
||||||
|
PendingResult<Status> result = LocationServices.GeofencingApi.addGeofences(
|
||||||
|
client,
|
||||||
|
getRequests(locations),
|
||||||
|
PendingIntent.getBroadcast(context, 0,
|
||||||
|
new Intent(context, GeofenceTransitionsIntentService.Broadcast.class),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT));
|
||||||
|
result.setResultCallback(status -> {
|
||||||
|
if (status.isSuccess()) {
|
||||||
|
Timber.i("Registered %s", locations);
|
||||||
|
} else {
|
||||||
|
Timber.e("Failed to register %s", locations);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> ids = Lists.transform(locations, geofence -> Long.toString(geofence.getId()));
|
client.disconnect();
|
||||||
|
});
|
||||||
newClient(client -> LocationServices.GeofencingApi.removeGeofences(client, ids)
|
});
|
||||||
.setResultCallback(status -> {
|
}
|
||||||
if (status.isSuccess()) {
|
|
||||||
Timber.i("Removed %s", locations);
|
|
||||||
} else {
|
|
||||||
Timber.e("Failed to remove %s", locations);
|
|
||||||
}
|
|
||||||
|
|
||||||
client.disconnect();
|
public void cancel(final Location location) {
|
||||||
}));
|
cancel(singletonList(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void newClient(final GoogleApi.GoogleApiClientConnectionHandler handler) {
|
|
||||||
new GoogleApi(context).connect(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<com.google.android.gms.location.Geofence> getRequests(List<Location> locations) {
|
public void cancel(final List<Location> locations) {
|
||||||
return newArrayList(transform(locations, this::toGoogleGeofence));
|
if (locations.isEmpty() || !permissionChecker.canAccessLocation()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private com.google.android.gms.location.Geofence toGoogleGeofence(Location location) {
|
List<String> ids = Lists.transform(locations, geofence -> Long.toString(geofence.getId()));
|
||||||
int radius = preferences.getIntegerFromString(R.string.p_geofence_radius, 250);
|
|
||||||
int responsiveness = (int) TimeUnit.SECONDS.toMillis(preferences.getIntegerFromString(R.string.p_geofence_responsiveness, 60));
|
newClient(client -> LocationServices.GeofencingApi.removeGeofences(client, ids)
|
||||||
return new com.google.android.gms.location.Geofence.Builder()
|
.setResultCallback(status -> {
|
||||||
.setCircularRegion(location.getLatitude(), location.getLongitude(), radius)
|
if (status.isSuccess()) {
|
||||||
.setNotificationResponsiveness(responsiveness)
|
Timber.i("Removed %s", locations);
|
||||||
.setRequestId(Long.toString(location.getId()))
|
} else {
|
||||||
.setTransitionTypes(GeofencingRequest.INITIAL_TRIGGER_ENTER)
|
Timber.e("Failed to remove %s", locations);
|
||||||
.setExpirationDuration(NEVER_EXPIRE)
|
}
|
||||||
.build();
|
|
||||||
}
|
client.disconnect();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void newClient(final GoogleApi.GoogleApiClientConnectionHandler handler) {
|
||||||
|
new GoogleApi(context).connect(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<com.google.android.gms.location.Geofence> getRequests(List<Location> locations) {
|
||||||
|
return newArrayList(transform(locations, this::toGoogleGeofence));
|
||||||
|
}
|
||||||
|
|
||||||
|
private com.google.android.gms.location.Geofence toGoogleGeofence(Location location) {
|
||||||
|
int radius = preferences.getIntegerFromString(R.string.p_geofence_radius, 250);
|
||||||
|
int responsiveness = (int) TimeUnit.SECONDS
|
||||||
|
.toMillis(preferences.getIntegerFromString(R.string.p_geofence_responsiveness, 60));
|
||||||
|
return new com.google.android.gms.location.Geofence.Builder()
|
||||||
|
.setCircularRegion(location.getLatitude(), location.getLongitude(), radius)
|
||||||
|
.setNotificationResponsiveness(responsiveness)
|
||||||
|
.setRequestId(Long.toString(location.getId()))
|
||||||
|
.setTransitionTypes(GeofencingRequest.INITIAL_TRIGGER_ENTER)
|
||||||
|
.setExpirationDuration(NEVER_EXPIRE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,65 +1,63 @@
|
|||||||
/**
|
/**
|
||||||
* TODO: make this lightweight, don't extend the entire TaskListActivity
|
* TODO: make this lightweight, don't extend the entire TaskListActivity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.todoroo.astrid.activity;
|
package com.todoroo.astrid.activity;
|
||||||
|
|
||||||
|
import static org.tasks.intents.TaskIntents.getEditTaskStack;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.todoroo.astrid.dao.TaskDao;
|
import com.todoroo.astrid.dao.TaskDao;
|
||||||
import com.todoroo.astrid.data.Task;
|
import com.todoroo.astrid.data.Task;
|
||||||
import com.todoroo.astrid.service.TaskCreator;
|
import com.todoroo.astrid.service.TaskCreator;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.tasks.injection.ActivityComponent;
|
import org.tasks.injection.ActivityComponent;
|
||||||
import org.tasks.injection.InjectingAppCompatActivity;
|
import org.tasks.injection.InjectingAppCompatActivity;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static org.tasks.intents.TaskIntents.getEditTaskStack;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author joshuagross
|
* @author joshuagross
|
||||||
*
|
*
|
||||||
* Create a new task based on incoming links from the "share" menu
|
* Create a new task based on incoming links from the "share" menu
|
||||||
*/
|
*/
|
||||||
public final class ShareLinkActivity extends InjectingAppCompatActivity {
|
public final class ShareLinkActivity extends InjectingAppCompatActivity {
|
||||||
|
|
||||||
@Inject TaskCreator taskCreator;
|
@Inject TaskCreator taskCreator;
|
||||||
@Inject TaskDao taskDao;
|
@Inject TaskDao taskDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
readIntent();
|
readIntent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inject(ActivityComponent component) {
|
public void inject(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
|
|
||||||
readIntent();
|
readIntent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readIntent() {
|
private void readIntent() {
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
||||||
if (subject == null) {
|
if (subject == null) {
|
||||||
subject = "";
|
subject = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Task task = taskCreator.createWithValues(null, subject);
|
Task task = taskCreator.createWithValues(null, subject);
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
task.setNotes(intent.getStringExtra(Intent.EXTRA_TEXT));
|
task.setNotes(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||||
getEditTaskStack(this, null, task).startActivities();
|
getEditTaskStack(this, null, task).startActivities();
|
||||||
}
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue