diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java index 4643209fc..7c09fe57b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java @@ -153,8 +153,12 @@ public class EditPeopleControlSet extends PopupControlSet { @Override public void readFromTask(Task sourceTask) { - task = sourceTask; - setUpData(); + setTask(sourceTask); + setUpData(task); + } + + public void setTask(Task task) { + this.task = task; } public View getSharedWithRow() { @@ -166,7 +170,7 @@ public class EditPeopleControlSet extends PopupControlSet { } @SuppressWarnings("nls") - private void setUpData() { + public void setUpData(final Task task) { try { JSONObject sharedWith; if(task.getValue(Task.SHARED_WITH).length() > 0) @@ -220,7 +224,7 @@ public class EditPeopleControlSet extends PopupControlSet { if(collaborators.size() > 0) buildCollaborators(collaborators); - buildAssignedToSpinner(sharedPeople); + buildAssignedToSpinner(task, sharedPeople); } catch (JSONException e) { exceptionService.reportError("json-reading-data", e); } finally { @@ -284,13 +288,13 @@ public class EditPeopleControlSet extends PopupControlSet { } @SuppressWarnings("nls") - private void buildAssignedToSpinner(ArrayList sharedPeople) throws JSONException { + private void buildAssignedToSpinner(Task model, ArrayList sharedPeople) throws JSONException { HashSet userIds = new HashSet(); HashSet emails = new HashSet(); HashMap names = new HashMap(); - if(task.getValue(Task.USER_ID) > 0) { - JSONObject user = new JSONObject(task.getValue(Task.USER)); + if(model.getValue(Task.USER_ID) > 0) { + JSONObject user = new JSONObject(model.getValue(Task.USER)); sharedPeople.add(0, user); } @@ -298,8 +302,8 @@ public class EditPeopleControlSet extends PopupControlSet { myself.put("id", Task.USER_ID_SELF); sharedPeople.add(0, myself); - boolean hasTags = task.getTransitory("tags") != null && - ((HashSet)task.getTransitory("tags")).size() > 0; + boolean hasTags = model.getTransitory("tags") != null && + ((HashSet)model.getTransitory("tags")).size() > 0; if (actFmPreferenceService.isLoggedIn() && hasTags) { JSONObject unassigned = new JSONObject(); unassigned.put("id", Task.USER_ID_UNASSIGNED); @@ -347,7 +351,7 @@ public class EditPeopleControlSet extends PopupControlSet { names.put(name, atu); } - String assignedStr = task.getValue(Task.USER); + String assignedStr = model.getValue(Task.USER); int assignedIndex = 0; if (!TextUtils.isEmpty(assignedStr)) { JSONObject assigned = new JSONObject(assignedStr); diff --git a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java index be96498e1..3229a7b3f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java @@ -324,6 +324,10 @@ public class RepeatControlSet extends PopupControlSet { return null; } + public boolean isRecurrenceSet() { + return doRepeat; + } + @Override protected void refreshDisplayView() { TextView repeatDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit); diff --git a/astrid/res/layout/control_set_default_display.xml b/astrid/res/layout/control_set_default_display.xml index cbf0bdc70..bc1782fb9 100644 --- a/astrid/res/layout/control_set_default_display.xml +++ b/astrid/res/layout/control_set_default_display.xml @@ -17,7 +17,7 @@ android:id="@+id/display_row_title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="15dip" + android:layout_marginRight="10dip" style="@style/TextAppearance.GEN_EditLabel" /> - - - - - - + + + + + + + + - - - + + + + + + + + + + + + diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java index 9d1a59368..98413b00a 100755 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java @@ -150,7 +150,7 @@ public final class TaskEditFragment extends Fragment implements // --- request codes - private static final int REQUEST_LOG_IN = 0; + public static final int REQUEST_LOG_IN = 0; private static final int REQUEST_VOICE_RECOG = 1; // --- menu codes diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index a3e0eb2c6..7d9e40d07 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -46,6 +46,7 @@ import android.view.View.OnClickListener; import android.view.View.OnKeyListener; import android.view.View.OnLongClickListener; import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; @@ -55,6 +56,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ImageButton; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; @@ -76,6 +78,7 @@ import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.widget.GestureService; import com.todoroo.andlib.widget.GestureService.GestureInterface; import com.todoroo.astrid.actfm.ActFmLoginActivity; +import com.todoroo.astrid.actfm.EditPeopleControlSet; import com.todoroo.astrid.actfm.TagUpdatesActivity; import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener; @@ -96,12 +99,14 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.gcal.GCalControlSet; import com.todoroo.astrid.gcal.GCalHelper; import com.todoroo.astrid.helper.MetadataHelper; import com.todoroo.astrid.helper.ProgressBarSyncResultCallback; import com.todoroo.astrid.helper.TaskListContextMenuExtensionLoader; import com.todoroo.astrid.helper.TaskListContextMenuExtensionLoader.ContextMenuItem; import com.todoroo.astrid.reminders.ReminderDebugContextActions; +import com.todoroo.astrid.repeats.RepeatControlSet; import com.todoroo.astrid.service.AddOnService; import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.MetadataService; @@ -115,6 +120,7 @@ import com.todoroo.astrid.service.UpgradeService; import com.todoroo.astrid.sync.SyncResultCallback; import com.todoroo.astrid.sync.SyncV2Provider; import com.todoroo.astrid.ui.DateChangedAlerts; +import com.todoroo.astrid.ui.DeadlineControlSet; import com.todoroo.astrid.utility.AstridPreferences; import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Flags; @@ -229,6 +235,11 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, protected OnTaskListItemClickedListener mListener; private boolean mDualFragments = false; + private DeadlineControlSet deadlineControl; + private RepeatControlSet repeatControl; + private GCalControlSet gcalControl; + private EditPeopleControlSet peopleControl; + /* * ====================================================================== * ======================================================= initialization @@ -503,6 +514,8 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, } }); + setUpQuickAddControlSets(); + // set listener for pressing enter in quick-add box quickAddBox = (EditText) getView().findViewById(R.id.quickAddText); quickAddBox.setOnEditorActionListener(new OnEditorActionListener() { @@ -595,6 +608,44 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, getView().findViewById(R.id.progressBar).setVisibility(View.GONE); } + private void setUpQuickAddControlSets() { + + repeatControl = new RepeatControlSet(getActivity(), + R.layout.control_set_repeat, + R.layout.control_set_repeat_display, R.string.repeat_enabled); + + gcalControl = new GCalControlSet(getActivity(), + R.layout.control_set_gcal, R.layout.control_set_gcal_display, + R.string.gcal_TEA_addToCalendar_label); + + deadlineControl = new DeadlineControlSet( + getActivity(), R.layout.control_set_deadline, + R.layout.control_set_default_display, + repeatControl.getDisplayView(), gcalControl.getDisplayView()); + deadlineControl.setUseNewlineForDisplaySeparator(true); + + peopleControl = new EditPeopleControlSet(getActivity(), + R.layout.control_set_assigned, + R.layout.control_set_default_display, + R.string.actfm_EPA_assign_label, TaskEditFragment.REQUEST_LOG_IN); + + resetControlSets(); + + LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1.0f); + LinearLayout container = (LinearLayout) getView().findViewById(R.id.taskListQuickaddControls); + container.addView(peopleControl.getDisplayView(), 0, lp); + container.addView(deadlineControl.getDisplayView(), 2, lp); + } + + private void resetControlSets() { + Task empty = new Task(); + repeatControl.readFromTask(empty); + gcalControl.readFromTask(empty); + deadlineControl.readFromTask(empty); + peopleControl.setUpData(empty); + peopleControl.setTask(null); + } + // Subclasses can override these to customize extras in quickadd intent protected Intent getOnClickQuickAddIntent(Task t) { Intent intent = new Intent(getActivity(), TaskEditActivity.class); @@ -1079,6 +1130,18 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, Task task = createWithValues(filter.valuesForNewTasks, title, taskService, metadataService); + //TODO: fix assigned + if (repeatControl.isRecurrenceSet()) + repeatControl.writeToModel(task); + if (deadlineControl.isDeadlineSet()) + deadlineControl.writeToModel(task); + gcalControl.writeToModel(task); + //peopleControl.setTask(task); + //peopleControl.saveSharingSettings(""); + taskService.save(task); + + resetControlSets(); + boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null && !Preferences.getStringValue(R.string.gcal_p_default).equals( "-1"); diff --git a/astrid/src/com/todoroo/astrid/ui/DateAndTimeDialog.java b/astrid/src/com/todoroo/astrid/ui/DateAndTimeDialog.java index e97994ea8..119751b55 100644 --- a/astrid/src/com/todoroo/astrid/ui/DateAndTimeDialog.java +++ b/astrid/src/com/todoroo/astrid/ui/DateAndTimeDialog.java @@ -93,10 +93,10 @@ public class DateAndTimeDialog extends Dialog { } public String getDisplayString(Context context) { - return dateAndTimePicker.getDisplayString(context); + return dateAndTimePicker.getDisplayString(context, false); } public String getDisplayString(Context context, long forDate) { - return DateAndTimePicker.getDisplayString(context, forDate); + return DateAndTimePicker.getDisplayString(context, forDate, false); } } diff --git a/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java b/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java index 071b55e40..0750bf375 100644 --- a/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java +++ b/astrid/src/com/todoroo/astrid/ui/DateAndTimePicker.java @@ -223,18 +223,18 @@ public class DateAndTimePicker extends LinearLayout { this.listener = listener; } - public String getDisplayString(Context context) { + public String getDisplayString(Context context, boolean useNewline) { long dueDate = constructDueDate(); - return getDisplayString(context, dueDate); + return getDisplayString(context, dueDate, useNewline); } - public static String getDisplayString(Context context, long forDate) { + public static String getDisplayString(Context context, long forDate, boolean useNewline) { StringBuilder displayString = new StringBuilder(); Date d = new Date(forDate); if (d.getTime() > 0) { displayString.append(DateUtilities.getDateString(context, d)); if (Task.hasDueTime(forDate)) { - displayString.append(", "); //$NON-NLS-1$ + displayString.append(useNewline ? "\n" : ", "); //$NON-NLS-1$ //$NON-NLS-2$ displayString.append(DateUtilities.getTimeString(context, d)); } } diff --git a/astrid/src/com/todoroo/astrid/ui/DeadlineControlSet.java b/astrid/src/com/todoroo/astrid/ui/DeadlineControlSet.java index 1ca043f89..35f0540e0 100644 --- a/astrid/src/com/todoroo/astrid/ui/DeadlineControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/DeadlineControlSet.java @@ -15,6 +15,7 @@ import com.todoroo.astrid.data.Task; public class DeadlineControlSet extends PopupControlSet { + private boolean useNewline = false; private final DateAndTimePicker dateAndTimePicker; public DeadlineControlSet(Activity activity, int viewLayout, int displayViewLayout, View...extraViews) { @@ -43,14 +44,14 @@ public class DeadlineControlSet extends PopupControlSet { @Override protected void refreshDisplayView() { TextView dateDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit); - String toDisplay = dateAndTimePicker.getDisplayString(activity); + String toDisplay = dateAndTimePicker.getDisplayString(activity, useNewline); dateDisplay.setText(toDisplay); } @Override public void readFromTask(Task task) { long dueDate = task.getValue(Task.DUE_DATE); - dateAndTimePicker.initializeWithDate(dueDate); + initializeWithDate(dueDate); refreshDisplayView(); } @@ -60,4 +61,20 @@ public class DeadlineControlSet extends PopupControlSet { task.setValue(Task.DUE_DATE, dueDate); return null; } + + public void initializeWithDate(long dueDate) { + dateAndTimePicker.initializeWithDate(dueDate); + } + + public boolean isDeadlineSet() { + return dateAndTimePicker.constructDueDate() != 0; + } + + /** + * Set whether date and time should be separated by a newline or a comma + * in the display view + */ + public void setUseNewlineForDisplaySeparator(boolean useNewline) { + this.useNewline = useNewline; + } } diff --git a/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java b/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java index 9abaefc6c..b846db507 100644 --- a/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java @@ -249,7 +249,7 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect task.setValue(Task.HIDE_UNTIL, value); if (value != 0) - return activity.getString(R.string.TEA_hideUntil_message, DateAndTimePicker.getDisplayString(activity, value)); + return activity.getString(R.string.TEA_hideUntil_message, DateAndTimePicker.getDisplayString(activity, value, false)); return null; }