Remove statics from TaskService

pull/189/head
Alex Baker 11 years ago
parent 362e18f602
commit b17e25253f

@ -8,7 +8,6 @@ package com.todoroo.astrid.reminders;
import android.content.Intent;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
@ -78,7 +77,13 @@ public class NotificationTests extends DatabaseTestCase {
putExtra(Notifications.EXTRAS_TYPE, ReminderService.TYPE_DUE);
}});
verify(broadcaster).sendOrderedBroadcast(any(Intent.class), eq(AstridApiConstants.PERMISSION_READ));
verify(broadcaster).requestNotification(
eq(task.getId()),
any(Intent.class),
eq(ReminderService.TYPE_DUE),
eq("Tasks"),
eq(" rubberduck"),
eq(1));
}
public void testDeletedTaskDoesntTriggerNotification() {

@ -6,7 +6,6 @@
package com.todoroo.astrid.service;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.test.DatabaseTestCase;
import java.util.ArrayList;
@ -17,7 +16,7 @@ import javax.inject.Inject;
public class QuickAddMarkupTest extends DatabaseTestCase {
@Inject TagService tagService;
@Inject TaskService taskService;
@Override
protected void setUp() {
@ -90,7 +89,7 @@ public class QuickAddMarkupTest extends DatabaseTestCase {
task = new Task();
task.setTitle(title);
tags.clear();
TaskService.parseQuickAddMarkup(tagService, task, tags);
taskService.parseQuickAddMarkup(task, tags);
}
private void assertImportanceIs(int importance) {

@ -27,7 +27,6 @@ public class TitleParserTest extends DatabaseTestCase {
@Inject TaskService taskService;
@Inject TagService tagService;
@Inject MetadataService metadataService;
@Inject Preferences preferences;
@Override
@ -156,7 +155,7 @@ public class TitleParserTest extends DatabaseTestCase {
private void insertTitleAddTask(String title, Task task) {
task.clear();
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
}
@ -167,7 +166,7 @@ public class TitleParserTest extends DatabaseTestCase {
String title = "Jog today";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
Date date = newDate(task.getDueDate());
assertEquals(date.getDay()+1, today.get(Calendar.DAY_OF_WEEK));
//Calendar starts 1-6, date.getDay() starts at 0
@ -175,7 +174,7 @@ public class TitleParserTest extends DatabaseTestCase {
task = new Task();
title = "Jog tomorrow";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
date = newDate(task.getDueDate());
assertEquals((date.getDay()+1) % 7, (today.get(Calendar.DAY_OF_WEEK)+1) % 7);
@ -202,14 +201,14 @@ public class TitleParserTest extends DatabaseTestCase {
task = new Task();
title = "Jog "+ days[i];
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
date = newDate(task.getDueDate());
assertEquals(date.getDay(), i);
task = new Task();
title = "Jog "+ abrevDays[i];
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
date = newDate(task.getDueDate());
assertEquals(date.getDay(), i);
}
@ -233,14 +232,14 @@ public class TitleParserTest extends DatabaseTestCase {
task = new Task();
String title = "Jog " + acceptedString;
task.setTitle(title); //test at end of task. should set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals((int)task.getImportance(), Task.IMPORTANCE_LEAST);
}
for (String acceptedString:acceptedStrings){
task = new Task();
String title = acceptedString + " jog";
task.setTitle(title); //test at beginning of task. should not set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertNotSame(task.getImportance(),Task.IMPORTANCE_LEAST);
}
}
@ -297,25 +296,25 @@ public class TitleParserTest extends DatabaseTestCase {
task = new Task();
String title = "Jog " + acceptedStringAtEnd;
task.setTitle(title); //test at end of task. should set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals((int)task.getImportance(), Task.IMPORTANCE_MUST_DO);
task = new Task();
title = acceptedStringAtEnd + " jog";
task.setTitle(title); //test at beginning of task. should not set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertNotSame(task.getImportance(), Task.IMPORTANCE_MUST_DO);
}
for (String acceptedStringAnywhere:acceptedStringsAnywhere){
task = new Task();
String title = "Jog " + acceptedStringAnywhere;
task.setTitle(title); //test at end of task. should set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals((int)task.getImportance(), Task.IMPORTANCE_MUST_DO);
title = acceptedStringAnywhere + " jog";
task.setTitle(title); //test at beginning of task. should set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals((int)task.getImportance(), Task.IMPORTANCE_MUST_DO);
}
}
@ -339,25 +338,25 @@ public class TitleParserTest extends DatabaseTestCase {
task = new Task();
String title = "Jog " + acceptedStringAtEnd;
task.setTitle(title); //test at end of task. should set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals((int)task.getImportance(), Task.IMPORTANCE_DO_OR_DIE);
task = new Task();
title = acceptedStringAtEnd + " jog";
task.setTitle(title); //test at beginning of task. should not set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertNotSame(task.getImportance(), Task.IMPORTANCE_DO_OR_DIE);
}
for (String acceptedStringAnywhere:acceptedStringsAnywhere){
task = new Task();
String title = "Jog " + acceptedStringAnywhere;
task.setTitle(title); //test at end of task. should set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals((int)task.getImportance(), Task.IMPORTANCE_DO_OR_DIE);
title = acceptedStringAnywhere + " jog";
task.setTitle(title); //test at beginning of task. should set importance.
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals((int)task.getImportance(), Task.IMPORTANCE_DO_OR_DIE);
}
}
@ -373,7 +372,7 @@ public class TitleParserTest extends DatabaseTestCase {
Task task = new Task();
String title = "Jog daily";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
RRule rrule = new RRule();
rrule.setFreq(Frequency.DAILY);
rrule.setInterval(1);
@ -383,7 +382,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every day";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertFalse(task.hasDueTime());
assertFalse(task.hasDueDate());
@ -392,7 +391,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every " + i + " days.";
task.setTitle(title);
rrule.setInterval(i);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertFalse(task.hasDueTime());
assertFalse(task.hasDueDate());
@ -406,7 +405,7 @@ public class TitleParserTest extends DatabaseTestCase {
Task task = new Task();
String title = "Jog weekly";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
RRule rrule = new RRule();
rrule.setFreq(Frequency.WEEKLY);
rrule.setInterval(1);
@ -416,7 +415,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every week";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertFalse(task.hasDueTime());
assertFalse(task.hasDueDate());
@ -425,7 +424,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every " + i + " weeks";
task.setTitle(title);
rrule.setInterval(i);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertFalse(task.hasDueTime());
assertFalse(task.hasDueDate());
@ -438,7 +437,7 @@ public class TitleParserTest extends DatabaseTestCase {
Task task = new Task();
String title = "Jog monthly";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
RRule rrule = new RRule();
rrule.setFreq(Frequency.MONTHLY);
rrule.setInterval(1);
@ -448,7 +447,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every month";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertFalse(task.hasDueTime());
assertFalse(task.hasDueDate());
@ -457,7 +456,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every " + i + " months";
task.setTitle(title);
rrule.setInterval(i);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertFalse(task.hasDueTime());
assertFalse(task.hasDueDate());
@ -469,7 +468,7 @@ public class TitleParserTest extends DatabaseTestCase {
Task task = new Task();
String title = "Jog daily starting from today";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
RRule rrule = new RRule();
rrule.setFreq(Frequency.DAILY);
rrule.setInterval(1);
@ -480,7 +479,7 @@ public class TitleParserTest extends DatabaseTestCase {
task.clearValue(Task.UUID);
title = "Jog every day starting from today";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertTrue(task.hasDueDate());
@ -488,7 +487,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every " + i + " days starting from today";
task.setTitle(title);
rrule.setInterval(i);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertTrue(task.hasDueDate());
task = new Task();
@ -499,7 +498,7 @@ public class TitleParserTest extends DatabaseTestCase {
Task task = new Task();
String title = "Jog weekly starting from today";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
RRule rrule = new RRule();
rrule.setFreq(Frequency.WEEKLY);
rrule.setInterval(1);
@ -510,7 +509,7 @@ public class TitleParserTest extends DatabaseTestCase {
task.clearValue(Task.UUID);
title = "Jog every week starting from today";
task.setTitle(title);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertTrue(task.hasDueDate());
@ -518,7 +517,7 @@ public class TitleParserTest extends DatabaseTestCase {
title = "Jog every " + i + " weeks starting from today";
task.setTitle(title);
rrule.setInterval(i);
TaskService.createWithValues(taskService, metadataService, tagService, task, null, title);
taskService.createWithValues(task, null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
assertTrue(task.hasDueDate());
task = new Task();

@ -9,9 +9,7 @@ import android.os.Bundle;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.QuickAddBar;
import org.tasks.injection.ForApplication;
@ -26,8 +24,6 @@ import javax.inject.Inject;
public final class ShareLinkActivity extends TaskListActivity {
@Inject TaskService taskService;
@Inject TagService tagService;
@Inject MetadataService metadataService;
@Inject GCalHelper gcalHelper;
@Inject @ForApplication Context context;
@ -54,7 +50,7 @@ public final class ShareLinkActivity extends TaskListActivity {
if (!handled) {
Intent callerIntent = getIntent();
Task task = QuickAddBar.basicQuickAddTask(context, gcalHelper, taskService, metadataService, tagService, subject);
Task task = QuickAddBar.basicQuickAddTask(context, gcalHelper, taskService, subject);
if (task != null) {
task.setNotes(callerIntent.getStringExtra(Intent.EXTRA_TEXT));
taskService.save(task);

@ -598,7 +598,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
// oops, can't serialize
log.error(e.getMessage(), e);
}
model = TaskService.createWithValues(taskService, metadataService, tagService, values, null);
model = taskService.createWithValues(values, null);
getActivity().getIntent().putExtra(TOKEN_ID, model.getId());
}

@ -63,15 +63,17 @@ public class TaskService {
private final FilterCounter filterCounter;
private final RefreshScheduler refreshScheduler;
private final TagService tagService;
private final MetadataService metadataService;
@Inject
public TaskService(TaskDao taskDao, Broadcaster broadcaster, FilterCounter filterCounter,
RefreshScheduler refreshScheduler, TagService tagService) {
RefreshScheduler refreshScheduler, TagService tagService, MetadataService metadataService) {
this.taskDao = taskDao;
this.broadcaster = broadcaster;
this.filterCounter = filterCounter;
this.refreshScheduler = refreshScheduler;
this.tagService = tagService;
this.metadataService = metadataService;
}
// --- service layer
@ -243,7 +245,7 @@ public class TaskService {
* Parse quick add markup for the given task
* @param tags an empty array to apply tags to
*/
public static boolean parseQuickAddMarkup(TagService tagService, Task task, ArrayList<String> tags) {
boolean parseQuickAddMarkup(Task task, ArrayList<String> tags) {
return TitleParser.parse(tagService, task, tags);
}
@ -251,16 +253,16 @@ public class TaskService {
* Create task from the given content values, saving it. This version
* doesn't need to start with a base task model.
*/
public static Task createWithValues(TaskService taskService, MetadataService metadataService, TagService tagService, ContentValues values, String title) {
public Task createWithValues(ContentValues values, String title) {
Task task = new Task();
return createWithValues(taskService, metadataService, tagService, task, values, title);
return createWithValues(task, values, title);
}
/**
* Create task from the given content values, saving it.
* @param task base task to start with
*/
public static Task createWithValues(TaskService taskService, MetadataService metadataService, TagService tagService, Task task, ContentValues values, String title) {
public Task createWithValues(Task task, ContentValues values, String title) {
if (title != null) {
task.setTitle(title);
}
@ -268,7 +270,7 @@ public class TaskService {
ArrayList<String> tags = new ArrayList<>();
boolean quickAddMarkup = false;
try {
quickAddMarkup = parseQuickAddMarkup(tagService, task, tags);
quickAddMarkup = parseQuickAddMarkup(task, tags);
} catch (Throwable e) {
log.error(e.getMessage(), e);
}
@ -296,7 +298,7 @@ public class TaskService {
task.mergeWithoutReplacement(forTask);
}
taskService.quickAdd(task, tags);
quickAdd(task, tags);
if (quickAddMarkup) {
task.putTransitory(TRANS_QUICK_ADD_MARKUP, true);
}

@ -36,9 +36,7 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalControlSet;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.repeats.RepeatControlSet;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.utility.Flags;
import com.todoroo.astrid.voice.VoiceRecognizer;
@ -73,8 +71,6 @@ public class QuickAddBar extends LinearLayout {
private RepeatControlSet repeatControl;
private GCalControlSet gcalControl;
@Inject TagService tagService;
@Inject MetadataService metadataService;
@Inject TaskService taskService;
@Inject GCalHelper gcalHelper;
@Inject ActivityPreferences preferences;
@ -280,7 +276,7 @@ public class QuickAddBar extends LinearLayout {
}
gcalControl.writeToModel(task);
TaskService.createWithValues(taskService, metadataService, tagService, task, fragment.getFilter().valuesForNewTasks, title);
taskService.createWithValues(task, fragment.getFilter().valuesForNewTasks, title);
resetControlSets();
@ -325,14 +321,14 @@ public class QuickAddBar extends LinearLayout {
* Static method to quickly add tasks without all the control set nonsense.
* Used from the share link activity.
*/
public static Task basicQuickAddTask(Context context, GCalHelper gcalHelper, TaskService taskService, MetadataService metadataService, TagService tagService, String title) {
public static Task basicQuickAddTask(Context context, GCalHelper gcalHelper, TaskService taskService, String title) {
if (TextUtils.isEmpty(title)) {
return null;
}
title = title.trim();
Task task = TaskService.createWithValues(taskService, metadataService, tagService, null, title);
Task task = taskService.createWithValues(null, title);
addToCalendar(context, gcalHelper, taskService, task, title);
return task;

@ -6,9 +6,7 @@ import android.os.Bundle;
import android.widget.Toast;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagService;
import org.tasks.R;
import org.tasks.injection.ForApplication;
@ -21,8 +19,6 @@ import static com.todoroo.astrid.ui.QuickAddBar.basicQuickAddTask;
public class VoiceCommandActivity extends InjectingActivity {
@Inject GCalHelper gcalHelper;
@Inject MetadataService metadataService;
@Inject TagService tagService;
@Inject TaskService taskService;
@Inject @ForApplication Context context;
@ -35,7 +31,7 @@ public class VoiceCommandActivity extends InjectingActivity {
switch (intent.getAction()) {
case "com.google.android.gm.action.AUTO_SEND":
final String text = intent.getStringExtra(Intent.EXTRA_TEXT);
basicQuickAddTask(context, gcalHelper, taskService, metadataService, tagService, text);
basicQuickAddTask(context, gcalHelper, taskService, text);
Context context = getApplicationContext();
if (context != null) {
Toast.makeText(context, getString(R.string.voice_command_added_task), Toast.LENGTH_LONG).show();

Loading…
Cancel
Save