Adjust when title parsing happens so that date insertion happens according to precedence rules. Also lots of code cleanup

pull/14/head
Sam Bosley 13 years ago
parent b88e4f9cad
commit a10a3c6620

@ -59,7 +59,6 @@ import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet; import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.reminders.Notifications; import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
@ -93,9 +92,6 @@ public class TaskRabbitActivity extends FragmentActivity {
@Autowired @Autowired
private TaskService taskService; private TaskService taskService;
@Autowired
private MetadataService metadataService;
@Autowired @Autowired
private ExceptionService exceptionService; private ExceptionService exceptionService;
@ -291,8 +287,7 @@ public class TaskRabbitActivity extends FragmentActivity {
} catch (Exception e) { } catch (Exception e) {
// oops, can't serialize // oops, can't serialize
} }
model = TaskService.createWithValues(values, null, model = TaskService.createWithValues(values, null);
taskService, metadataService);
} }
if (model == null) { if (model == null) {

@ -754,8 +754,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
} catch (Exception e) { } catch (Exception e) {
// oops, can't serialize // oops, can't serialize
} }
model = TaskService.createWithValues(values, null, model = TaskService.createWithValues(values, null);
taskService, metadataService);
getActivity().getIntent().putExtra(TOKEN_ID, model.getId()); getActivity().getIntent().putExtra(TOKEN_ID, model.getId());
} }

@ -1,6 +1,7 @@
package com.todoroo.astrid.service; package com.todoroo.astrid.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.weloveastrid.rmilk.data.MilkTaskFields; import org.weloveastrid.rmilk.data.MilkTaskFields;
@ -11,7 +12,6 @@ import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
@ -21,6 +21,7 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
@ -65,9 +66,6 @@ public class TaskService {
@Autowired @Autowired
private MetadataDao metadataDao; private MetadataDao metadataDao;
@Autowired
private ExceptionService exceptionService;
public TaskService() { public TaskService() {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
} }
@ -401,14 +399,7 @@ public class TaskService {
* <li>@context - add the tag "@context" * <li>@context - add the tag "@context"
* <li>!4 - set priority to !!!! * <li>!4 - set priority to !!!!
*/ */
public boolean quickAdd(Task task) { private void quickAdd(Task task, List<String> tags) {
ArrayList<String> tags = new ArrayList<String>();
boolean quickAddMarkup = false;
try {
quickAddMarkup = parseQuickAddMarkup(task, tags);
} catch (Throwable e) {
exceptionService.reportError("parse-quick-add", e); //$NON-NLS-1$
}
save(task); save(task);
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
@ -418,7 +409,6 @@ public class TaskService {
metadata.setValue(TagService.TAG, tag); metadata.setValue(TagService.TAG, tag);
metadataDao.createNew(metadata); metadataDao.createNew(metadata);
} }
return quickAddMarkup;
} }
/** /**
@ -463,10 +453,9 @@ public class TaskService {
* @param metadataService * @param metadataService
* @return * @return
*/ */
public static Task createWithValues(ContentValues values, String title, public static Task createWithValues(ContentValues values, String title) {
TaskService taskService, MetadataService metadataService) {
Task task = new Task(); Task task = new Task();
return createWithValues(task, values, title, taskService, metadataService); return createWithValues(task, values, title);
} }
/** /**
@ -479,11 +468,18 @@ public class TaskService {
* @param metadataService * @param metadataService
* @return * @return
*/ */
public static Task createWithValues(Task task, ContentValues values, String title, public static Task createWithValues(Task task, ContentValues values, String title) {
TaskService taskService, MetadataService metadataService) {
if (title != null) if (title != null)
task.setValue(Task.TITLE, title); task.setValue(Task.TITLE, title);
ArrayList<String> tags = new ArrayList<String>();
boolean quickAddMarkup = false;
try {
quickAddMarkup = parseQuickAddMarkup(task, tags);
} catch (Throwable e) {
PluginServices.getExceptionService().reportError("parse-quick-add", e); //$NON-NLS-1$
}
ContentValues forMetadata = null; ContentValues forMetadata = null;
if (values != null && values.size() > 0) { if (values != null && values.size() > 0) {
ContentValues forTask = new ContentValues(); ContentValues forTask = new ContentValues();
@ -508,15 +504,15 @@ public class TaskService {
if (task.getValue(Task.USER_ID) != Task.USER_ID_SELF) if (task.getValue(Task.USER_ID) != Task.USER_ID_SELF)
task.putTransitory(TRANS_ASSIGNED, true); task.putTransitory(TRANS_ASSIGNED, true);
boolean markup = taskService.quickAdd(task); PluginServices.getTaskService().quickAdd(task, tags);
if (markup) if (quickAddMarkup)
task.putTransitory(TRANS_QUICK_ADD_MARKUP, true); task.putTransitory(TRANS_QUICK_ADD_MARKUP, true);
if (forMetadata != null && forMetadata.size() > 0) { if (forMetadata != null && forMetadata.size() > 0) {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
metadata.setValue(Metadata.TASK, task.getId()); metadata.setValue(Metadata.TASK, task.getId());
metadata.mergeWith(forMetadata); metadata.mergeWith(forMetadata);
metadataService.save(metadata); PluginServices.getMetadataService().save(metadata);
} }
return task; return task;

@ -84,7 +84,6 @@ public class QuickAddBar extends LinearLayout implements RecognizerApiListener {
@Autowired AddOnService addOnService; @Autowired AddOnService addOnService;
@Autowired ExceptionService exceptionService; @Autowired ExceptionService exceptionService;
@Autowired TaskService taskService;
@Autowired MetadataService metadataService; @Autowired MetadataService metadataService;
@Autowired ActFmPreferenceService actFmPreferenceService; @Autowired ActFmPreferenceService actFmPreferenceService;
@ -305,14 +304,13 @@ public class QuickAddBar extends LinearLayout implements RecognizerApiListener {
peopleControl.saveSharingSettings(null); peopleControl.saveSharingSettings(null);
} }
TaskService.createWithValues(task, fragment.getFilter().valuesForNewTasks, title, TaskService.createWithValues(task, fragment.getFilter().valuesForNewTasks, title);
taskService, metadataService);
String assignedTo = peopleControl.getAssignedToString(); String assignedTo = peopleControl.getAssignedToString();
resetControlSets(); resetControlSets();
addToCalendar(task, title, taskService); addToCalendar(task, title);
if(!TextUtils.isEmpty(title)) if(!TextUtils.isEmpty(title))
fragment.showTaskEditHelpPopover(); fragment.showTaskEditHelpPopover();
@ -356,7 +354,7 @@ public class QuickAddBar extends LinearLayout implements RecognizerApiListener {
} }
} }
private static void addToCalendar(Task task, String title, TaskService taskService) { private static void addToCalendar(Task task, String title) {
boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null
&& !Preferences.getStringValue(R.string.gcal_p_default).equals("-1"); //$NON-NLS-1$ && !Preferences.getStringValue(R.string.gcal_p_default).equals("-1"); //$NON-NLS-1$
@ -366,7 +364,7 @@ public class QuickAddBar extends LinearLayout implements RecognizerApiListener {
task.setValue(Task.CALENDAR_URI, calendarUri.toString()); task.setValue(Task.CALENDAR_URI, calendarUri.toString());
task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true); task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
taskService.save(task); PluginServices.getTaskService().save(task);
} }
} }
@ -380,12 +378,10 @@ public class QuickAddBar extends LinearLayout implements RecognizerApiListener {
if (TextUtils.isEmpty(title)) if (TextUtils.isEmpty(title))
return null; return null;
TaskService taskService = PluginServices.getTaskService();
MetadataService metadataService = PluginServices.getMetadataService();
title = title.trim(); title = title.trim();
Task task = TaskService.createWithValues(null, title, taskService, metadataService); Task task = TaskService.createWithValues(null, title);
addToCalendar(task, title, taskService); addToCalendar(task, title);
return task; return task;
} }

Loading…
Cancel
Save