Merge remote-tracking branch 'sbosley/120214_sb_bugfixes' into 4.0

pull/14/head
Tim Su 13 years ago
commit 12f5e60b02

@ -520,12 +520,28 @@ public class EditPeopleControlSet extends PopupControlSet {
// --- events
@Override
protected void readFromTaskPrivate() {
// Nothing, we don't lazy load this control set yet
}
@Override
public String writeToModel(Task model) {
// do nothing, we use a separate method
return null;
}
@Override
protected String writeToModelPrivate(Task task) {
// Nothing, we don't lazy load this control set yet
return null;
}
@Override
protected void afterInflate() {
// Nothing, we don't lazy load this control set yet
}
/**
* Save sharing settings
* @param toast toast to show after saving is finished

@ -30,29 +30,18 @@ public final class AlarmControlSet extends TaskEditControlSet {
// --- instance variables
private final LinearLayout alertsContainer;
private final Activity activity;
private final DateAndTimeDialog pickerDialog;
private LinearLayout alertsContainer;
private DateAndTimeDialog pickerDialog;
public AlarmControlSet(Activity activity, int layout) {
//View v = LayoutInflater.from(activity).inflate(R.layout.alarm_control, parent, true);
super(activity, layout);
this.activity = activity;
this.alertsContainer = (LinearLayout) getView().findViewById(R.id.alert_container);
getView().findViewById(R.id.alarms_add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
addAlarm(new Date());
}
});
pickerDialog = new DateAndTimeDialog(activity, 0);
}
@Override
public void readFromTask(Task task) {
protected void readFromTaskPrivate() {
alertsContainer.removeAllViews();
TodorooCursor<Metadata> cursor = AlarmService.getInstance().getAlarms(task.getId());
TodorooCursor<Metadata> cursor = AlarmService.getInstance().getAlarms(model.getId());
try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
addAlarm(new Date(cursor.get(AlarmFields.TIME)));
@ -62,7 +51,20 @@ public final class AlarmControlSet extends TaskEditControlSet {
}
@Override
public String writeToModel(Task task) {
protected void afterInflate() {
this.alertsContainer = (LinearLayout) getView().findViewById(R.id.alert_container);
getView().findViewById(R.id.alarms_add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
addAlarm(new Date());
}
});
pickerDialog = new DateAndTimeDialog(activity, 0);
}
@Override
protected String writeToModelPrivate(Task task) {
LinkedHashSet<Long> alarms = new LinkedHashSet<Long>();
for(int i = 0; i < alertsContainer.getChildCount(); i++) {
Long dateValue = (Long) alertsContainer.getChildAt(i).getTag();

@ -13,7 +13,6 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
@ -46,26 +45,25 @@ public class GCalControlSet extends PopupControlSet {
@Autowired
private ExceptionService exceptionService;
private final Activity activity;
private Uri calendarUri = null;
private Task myTask;
private final CalendarResult calendars;
private boolean hasEvent = false;
private final Spinner calendarSelector;
private Spinner calendarSelector;
private final int title;
public GCalControlSet(final Activity activity, int viewLayout, int displayViewLayout, int title) {
super(activity, viewLayout, displayViewLayout, title);
DependencyInjectionService.getInstance().inject(this);
ViewGroup parent = (ViewGroup) getView().getParent();
parent.removeView(getView());
this.title = title;
calendars = Calendars.getCalendars();
}
@Override
protected void afterInflate() {
((LinearLayout) getDisplayView()).addView(getView()); //hack for spinner
this.activity = activity;
this.calendarSelector = (Spinner) getView().findViewById(R.id.calendars);
calendars = Calendars.getCalendars();
ArrayList<String> items = new ArrayList<String>();
Collections.addAll(items, calendars.calendars);
items.add(0, activity.getString(R.string.gcal_TEA_nocal));
@ -92,9 +90,8 @@ public class GCalControlSet extends PopupControlSet {
}
@Override
public void readFromTask(Task task) {
this.myTask = task;
String uri = GCalHelper.getTaskEventUri(task);
protected void readFromTaskPrivate() {
String uri = GCalHelper.getTaskEventUri(model);
if(!TextUtils.isEmpty(uri)) {
try {
calendarUri = Uri.parse(uri);
@ -116,7 +113,7 @@ public class GCalControlSet extends PopupControlSet {
hasEvent = true;
} catch (Exception e) {
exceptionService.reportError("unable-to-parse-calendar: " + //$NON-NLS-1$
task.getValue(Task.CALENDAR_URI), e);
model.getValue(Task.CALENDAR_URI), e);
}
}
refreshDisplayView();
@ -124,7 +121,7 @@ public class GCalControlSet extends PopupControlSet {
@SuppressWarnings("nls")
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null &&
!Preferences.getStringValue(R.string.gcal_p_default).equals("-1");
if ((gcalCreateEventEnabled || calendarSelector.getSelectedItemPosition() != 0) &&
@ -193,7 +190,7 @@ public class GCalControlSet extends PopupControlSet {
if(cursor.getCount() == 0) {
// event no longer exists, recreate it
calendarUri = null;
writeToModel(myTask);
writeToModel(model);
return;
}
cursor.moveToFirst();
@ -213,6 +210,7 @@ public class GCalControlSet extends PopupControlSet {
@Override
protected void refreshDisplayView() {
TextView calendar = (TextView) getDisplayView().findViewById(R.id.calendar_display_which);
if (initialized) {
if (hasEvent) {
calendar.setText(R.string.gcal_TEA_has_event);
} else if (calendarSelector.getSelectedItemPosition() != 0) {
@ -220,6 +218,16 @@ public class GCalControlSet extends PopupControlSet {
} else {
calendar.setText(R.string.gcal_TEA_none_selected);
}
} else {
int index = calendars.defaultIndex + 1;
if (!TextUtils.isEmpty(model.getValue(Task.CALENDAR_URI))) {
calendar.setText(R.string.gcal_TEA_has_event);
} else if (index != 0 && index < calendars.calendars.length) {
calendar.setText(calendars.calendars[index]);
} else {
calendar.setText(R.string.gcal_TEA_none_selected);
}
}
}
@Override
@ -227,6 +235,8 @@ public class GCalControlSet extends PopupControlSet {
return new OnClickListener() {
@Override
public void onClick(View v) {
if (calendarSelector == null)
getView(); // Force load
if (!hasEvent) {
calendarSelector.performClick();
} else {

@ -183,13 +183,11 @@ public class OpencrxControlSet extends PopupControlSet {
// --- instance variables
private final Activity activity;
private Spinner assignedToSelector;
private Spinner creatorSelector;
private final Spinner assignedToSelector;
private final Spinner creatorSelector;
private final AutoCompleteTextView assignedToTextInput;
private final AutoCompleteTextView creatorTextInput;
private AutoCompleteTextView assignedToTextInput;
private AutoCompleteTextView creatorTextInput;
private ArrayList<OpencrxContact> users = null;
private ArrayList<OpencrxActivityCreator> dashboards = null;
@ -204,9 +202,10 @@ public class OpencrxControlSet extends PopupControlSet {
public OpencrxControlSet(final Activity activity, int viewLayout, int displayViewLayout, int title) {
super(activity, viewLayout, displayViewLayout, title);
DependencyInjectionService.getInstance().inject(this);
}
this.activity = activity;
@Override
protected void afterInflate() {
//View view = LayoutInflater.from(activity).inflate(R.layout.opencrx_control, parent, true);
this.assignedToSelector = (Spinner) getView().findViewById(R.id.opencrx_TEA_task_assign);
@ -218,16 +217,15 @@ public class OpencrxControlSet extends PopupControlSet {
this.assignedToTextInput = (AutoCompleteTextView) getView().findViewById(R.id.opencrx_TEA_contact_textinput);
this.creatorTextInput = (AutoCompleteTextView) getView().findViewById(R.id.opencrx_TEA_creator_textinput);
}
@Override
public void readFromTask(Task task) {
protected void readFromTaskPrivate() {
Metadata metadata = getTaskMetadata(task.getId());
Metadata metadata = getTaskMetadata(model.getId());
if(metadata == null)
metadata = OpencrxCoreUtils.INSTANCE.newMetadata(task.getId());
metadata = OpencrxCoreUtils.INSTANCE.newMetadata(model.getId());
// Fill the dashboard-spinner and set the current dashboard
long dashboardId = OpencrxCoreUtils.INSTANCE.getDefaultCreator();
@ -339,7 +337,7 @@ public class OpencrxControlSet extends PopupControlSet {
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
Metadata metadata = getTaskMetadata(task.getId());
try {
if (metadata == null) {

@ -43,14 +43,8 @@ import com.todoroo.astrid.ui.PopupControlSet;
*/
public class ProducteevControlSet extends PopupControlSet {
// --- instance variables
private final Activity activity;
//private final View view;
private Task myTask;
private final Spinner responsibleSelector;
private final Spinner dashboardSelector;
private Spinner responsibleSelector;
private Spinner dashboardSelector;
private ArrayList<ProducteevUser> users = null;
private ArrayList<ProducteevDashboard> dashboards = null;
@ -63,87 +57,6 @@ public class ProducteevControlSet extends PopupControlSet {
public ProducteevControlSet(final Activity activity, int layout, int displayViewLayout, int title) {
super(activity, layout, displayViewLayout, title);
DependencyInjectionService.getInstance().inject(this);
this.activity = activity;
this.displayText.setText(activity.getString(R.string.producteev_TEA_control_set_display));
//view = LayoutInflater.from(activity).inflate(R.layout.producteev_control, parent, true);
this.responsibleSelector = (Spinner) getView().findViewById(R.id.producteev_TEA_task_assign);
TextView emptyView = new TextView(activity);
emptyView.setText(activity.getText(R.string.producteev_no_dashboard));
responsibleSelector.setEmptyView(emptyView);
this.dashboardSelector = (Spinner) getView().findViewById(R.id.producteev_TEA_dashboard_assign);
this.dashboardSelector.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> spinnerParent, View spinnerView,
int position, long id) {
final Spinner dashSelector = (Spinner) spinnerParent;
ProducteevDashboard dashboard = (ProducteevDashboard) dashSelector.getSelectedItem();
if (dashboard.getId() == ProducteevUtilities.DASHBOARD_CREATE) {
// let the user create a new dashboard
final EditText editor = new EditText(ProducteevControlSet.this.activity);
OnClickListener okListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Activity context = ProducteevControlSet.this.activity;
String newDashboardName = editor.getText().toString();
if (newDashboardName == null || newDashboardName.length() == 0) {
dialog.cancel();
} else {
// create the real dashboard, select it in the spinner and refresh responsiblespinner
ProgressDialog progressDialog = com.todoroo.andlib.utility.DialogUtilities.progressDialog(context,
context.getString(R.string.DLG_wait));
try {
progressDialog.show();
JSONObject newDashJSON = ProducteevSyncProvider.getInvoker().dashboardsCreate(
newDashboardName).getJSONObject("dashboard"); //$NON-NLS-1$
StoreObject local = ProducteevDataService.getInstance().updateDashboards(newDashJSON, true);
if (local != null) {
ProducteevDashboard newDashboard = new ProducteevDashboard(local);
ArrayAdapter<ProducteevDashboard> adapter = (ArrayAdapter<ProducteevDashboard>) dashSelector.getAdapter();
adapter.insert(newDashboard, adapter.getCount()-1);
dashSelector.setSelection(adapter.getCount()-2);
refreshResponsibleSpinner(newDashboard.getUsers());
DialogUtilities.dismissDialog(context, progressDialog);
}
} catch (Exception e) {
DialogUtilities.dismissDialog(context, progressDialog);
DialogUtilities.okDialog(context,
context.getString(R.string.DLG_error, e.getMessage()),
null);
exceptionService.reportError("pdv-create-dashboard", e); //$NON-NLS-1$
dashSelector.setSelection(0);
}
}
}
};
OnClickListener cancelListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
dashboardSelector.setSelection(lastDashboardSelection);
}
};
DialogUtilities.viewDialog(ProducteevControlSet.this.activity,
ProducteevControlSet.this.activity.getString(R.string.producteev_create_dashboard_name),
editor,
okListener,
cancelListener);
} else {
refreshResponsibleSpinner(dashboard.getUsers());
lastDashboardSelection = position;
}
}
@Override
public void onNothingSelected(AdapterView<?> spinnerParent) {
//
}
});
}
/**
@ -152,7 +65,7 @@ public class ProducteevControlSet extends PopupControlSet {
* @param newUsers the new userlist to show in the responsibleSelector
*/
private void refreshResponsibleSpinner(ArrayList<ProducteevUser> newUsers) {
Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(myTask.getId());
Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(model.getId());
long responsibleId = -1;
if(metadata != null && metadata.containsNonNullValue(ProducteevTask.RESPONSIBLE_ID))
responsibleId = metadata.getValue(ProducteevTask.RESPONSIBLE_ID);
@ -192,9 +105,8 @@ public class ProducteevControlSet extends PopupControlSet {
}
@Override
public void readFromTask(Task task) {
this.myTask = task;
Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(myTask.getId());
protected void readFromTaskPrivate() {
Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(model.getId());
if(metadata == null)
metadata = ProducteevTask.newMetadata();
@ -241,7 +153,91 @@ public class ProducteevControlSet extends PopupControlSet {
}
@Override
public String writeToModel(Task task) {
protected void afterInflate() {
this.displayText.setText(activity.getString(R.string.producteev_TEA_control_set_display));
//view = LayoutInflater.from(activity).inflate(R.layout.producteev_control, parent, true);
this.responsibleSelector = (Spinner) getView().findViewById(R.id.producteev_TEA_task_assign);
TextView emptyView = new TextView(activity);
emptyView.setText(activity.getText(R.string.producteev_no_dashboard));
responsibleSelector.setEmptyView(emptyView);
this.dashboardSelector = (Spinner) getView().findViewById(R.id.producteev_TEA_dashboard_assign);
this.dashboardSelector.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> spinnerParent, View spinnerView,
int position, long id) {
final Spinner dashSelector = (Spinner) spinnerParent;
ProducteevDashboard dashboard = (ProducteevDashboard) dashSelector.getSelectedItem();
if (dashboard.getId() == ProducteevUtilities.DASHBOARD_CREATE) {
// let the user create a new dashboard
final EditText editor = new EditText(ProducteevControlSet.this.activity);
OnClickListener okListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Activity context = ProducteevControlSet.this.activity;
String newDashboardName = editor.getText().toString();
if (newDashboardName == null || newDashboardName.length() == 0) {
dialog.cancel();
} else {
// create the real dashboard, select it in the spinner and refresh responsiblespinner
ProgressDialog progressDialog = com.todoroo.andlib.utility.DialogUtilities.progressDialog(context,
context.getString(R.string.DLG_wait));
try {
progressDialog.show();
JSONObject newDashJSON = ProducteevSyncProvider.getInvoker().dashboardsCreate(
newDashboardName).getJSONObject("dashboard"); //$NON-NLS-1$
StoreObject local = ProducteevDataService.getInstance().updateDashboards(newDashJSON, true);
if (local != null) {
ProducteevDashboard newDashboard = new ProducteevDashboard(local);
ArrayAdapter<ProducteevDashboard> adapter = (ArrayAdapter<ProducteevDashboard>) dashSelector.getAdapter();
adapter.insert(newDashboard, adapter.getCount()-1);
dashSelector.setSelection(adapter.getCount()-2);
refreshResponsibleSpinner(newDashboard.getUsers());
DialogUtilities.dismissDialog(context, progressDialog);
}
} catch (Exception e) {
DialogUtilities.dismissDialog(context, progressDialog);
DialogUtilities.okDialog(context,
context.getString(R.string.DLG_error, e.getMessage()),
null);
exceptionService.reportError("pdv-create-dashboard", e); //$NON-NLS-1$
dashSelector.setSelection(0);
}
}
}
};
OnClickListener cancelListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
dashboardSelector.setSelection(lastDashboardSelection);
}
};
DialogUtilities.viewDialog(ProducteevControlSet.this.activity,
ProducteevControlSet.this.activity.getString(R.string.producteev_create_dashboard_name),
editor,
okListener,
cancelListener);
} else {
refreshResponsibleSpinner(dashboard.getUsers());
lastDashboardSelection = position;
}
}
@Override
public void onNothingSelected(AdapterView<?> spinnerParent) {
//
}
});
}
@Override
protected String writeToModelPrivate(Task task) {
Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(task.getId());
try {
if (metadata == null) {

@ -61,18 +61,18 @@ public class RepeatControlSet extends PopupControlSet {
private static final int TYPE_DUE_DATE = 0;
private static final int TYPE_COMPLETION_DATE = 1;
// --- instance variables
private final Activity activity;
//private final CheckBox enabled;
private boolean doRepeat = true;
private final Button value;
private final Spinner interval;
private final Spinner type;
private final LinearLayout repeatContainer;
private final LinearLayout daysOfWeekContainer;
private boolean doRepeat = false;
private Button value;
private Spinner interval;
private Spinner type;
private LinearLayout repeatContainer;
private LinearLayout daysOfWeekContainer;
private final CompoundButton[] daysOfWeek = new CompoundButton[7];
private Task model;
private String recurrence;
private int repeatValue;
private int intervalValue;
private final List<RepeatChangedListener> listeners = new LinkedList<RepeatChangedListener>();
@ -91,74 +91,19 @@ public class RepeatControlSet extends PopupControlSet {
public RepeatControlSet(Activity activity, int viewLayout, int displayViewLayout, int title) {
super(activity, viewLayout, displayViewLayout, title);
DependencyInjectionService.getInstance().inject(this);
this.activity = activity;
value = (Button) getView().findViewById(R.id.repeatValue);
interval = (Spinner) getView().findViewById(R.id.repeatInterval);
type = (Spinner) getView().findViewById(R.id.repeatType);
repeatContainer = (LinearLayout) getView().findViewById(R.id.repeatContainer);
daysOfWeekContainer = (LinearLayout) getView().findViewById(R.id.repeatDayOfWeekContainer);
setRepeatValue(1);
// set up days of week
DateFormatSymbols dfs = new DateFormatSymbols();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f/14);
LinearLayout.LayoutParams textLp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f/14);
for(int i = 0; i < 7; i++) {
CheckBox checkBox = new CheckBox(activity);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
checkBox.setPadding(0, 0, 0, 0);
checkBox.setLayoutParams(lp);
checkBox.setTag(Weekday.values()[dayOfWeek - 1]);
checkBox.setButtonDrawable(R.drawable.btn_check_small);
TextView label = new TextView(activity);
label.setTextAppearance(activity, R.style.TextAppearance_GEN_EditLabel);
label.setLayoutParams(textLp);
label.setTextSize(14);
label.setText(dfs.getShortWeekdays()[dayOfWeek].substring(0, 1));
daysOfWeek[i] = checkBox;
calendar.add(Calendar.DATE, 1);
daysOfWeekContainer.addView(checkBox);
daysOfWeekContainer.addView(label);
}
// set up listeners
value.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
repeatValueClick();
}
});
interval.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View view, int position, long id) {
daysOfWeekContainer.setVisibility(position == INTERVAL_WEEKS ? View.VISIBLE : View.GONE);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
//
}
});
daysOfWeekContainer.setVisibility(View.GONE);
}
/** Set up the repeat value button */
private void setRepeatValue(int newValue) {
repeatValue = newValue;
value.setText(activity.getString(R.string.repeat_every, newValue));
value.setTag(newValue);
}
protected void repeatValueClick() {
final int tagValue = (Integer)value.getTag();
final Runnable openDialogRunnable = new Runnable() {
public void run() {
int dialogValue = tagValue;
int dialogValue = repeatValue;
if(dialogValue == 0)
dialogValue = 1;
@ -186,56 +131,71 @@ public class RepeatControlSet extends PopupControlSet {
listeners.remove(listener);
}
@SuppressWarnings("nls")
@Override
public void readFromTask(Task task) {
model = task;
String recurrence = task.getValue(Task.RECURRENCE);
super.readFromTask(task);
recurrence = model.getValue(Task.RECURRENCE);
if(recurrence == null)
recurrence = "";
Date date;
if(model.getValue(Task.DUE_DATE) == 0)
date = new Date();
else
date = new Date(model.getValue(Task.DUE_DATE));
int dayOfWeek = date.getDay();
for(int i = 0; i < 7; i++)
daysOfWeek[i].setChecked(i == dayOfWeek);
// read recurrence rule
if(recurrence.length() > 0) {
try {
RRule rrule = new RRule(recurrence);
setRepeatValue(rrule.getInterval());
repeatValue = rrule.getInterval();
switch(rrule.getFreq()) {
case DAILY:
interval.setSelection(INTERVAL_DAYS);
intervalValue = INTERVAL_DAYS;
break;
case WEEKLY: {
interval.setSelection(INTERVAL_WEEKS);
intervalValue = INTERVAL_WEEKS;
break;
}
case MONTHLY:
interval.setSelection(INTERVAL_MONTHS);
intervalValue = INTERVAL_MONTHS;
break;
case HOURLY:
interval.setSelection(INTERVAL_HOURS);
intervalValue = INTERVAL_HOURS;
break;
case MINUTELY:
interval.setSelection(INTERVAL_MINUTES);
intervalValue = INTERVAL_MINUTES;
break;
case YEARLY:
interval.setSelection(INTERVAL_YEARS);
intervalValue = INTERVAL_YEARS;
break;
default:
// an unhandled recurrence
exceptionService.reportError("repeat-unhandled-rule", //$NON-NLS-1$
new Exception("Unhandled rrule frequency: " + recurrence));
}
} catch (Exception e) {
// invalid RRULE
recurrence = ""; //$NON-NLS-1$
exceptionService.reportError("repeat-parse-exception", e);
}
}
doRepeat = recurrence.length() > 0;
refreshDisplayView();
}
@SuppressWarnings("nls")
@Override
protected void readFromTaskPrivate() {
Date date;
if(model.getValue(Task.DUE_DATE) == 0)
date = new Date();
else
date = new Date(model.getValue(Task.DUE_DATE));
int dayOfWeek = date.getDay();
for(int i = 0; i < 7; i++)
daysOfWeek[i].setChecked(i == dayOfWeek);
// read recurrence rule
if(recurrence.length() > 0) {
try {
RRule rrule = new RRule(recurrence);
setRepeatValue(rrule.getInterval());
interval.setSelection(intervalValue);
// clear all day of week checks, then update them
for(int i = 0; i < 7; i++)
@ -258,7 +218,7 @@ public class RepeatControlSet extends PopupControlSet {
doRepeat = recurrence.length() > 0;
// read flag
if(task.getFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION))
if(model.getFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION))
type.setSelection(TYPE_COMPLETION_DATE);
else
type.setSelection(TYPE_DUE_DATE);
@ -266,9 +226,64 @@ public class RepeatControlSet extends PopupControlSet {
refreshDisplayView();
}
@Override
protected void afterInflate() {
value = (Button) getView().findViewById(R.id.repeatValue);
interval = (Spinner) getView().findViewById(R.id.repeatInterval);
type = (Spinner) getView().findViewById(R.id.repeatType);
repeatContainer = (LinearLayout) getView().findViewById(R.id.repeatContainer);
daysOfWeekContainer = (LinearLayout) getView().findViewById(R.id.repeatDayOfWeekContainer);
setRepeatValue(1);
// set up days of week
DateFormatSymbols dfs = new DateFormatSymbols();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f/14);
LinearLayout.LayoutParams textLp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f/14);
for(int i = 0; i < 7; i++) {
CheckBox checkBox = new CheckBox(activity);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
checkBox.setPadding(0, 0, 0, 0);
checkBox.setLayoutParams(lp);
checkBox.setTag(Weekday.values()[dayOfWeek - 1]);
checkBox.setButtonDrawable(R.drawable.btn_check_small);
TextView label = new TextView(activity);
label.setTextAppearance(activity, R.style.TextAppearance_GEN_EditLabel);
label.setLayoutParams(textLp);
label.setTextSize(14);
label.setText(dfs.getShortWeekdays()[dayOfWeek].substring(0, 1));
daysOfWeek[i] = checkBox;
calendar.add(Calendar.DATE, 1);
daysOfWeekContainer.addView(checkBox);
daysOfWeekContainer.addView(label);
}
// set up listeners
value.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
repeatValueClick();
}
});
interval.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View view, int position, long id) {
daysOfWeekContainer.setVisibility(position == INTERVAL_WEEKS ? View.VISIBLE : View.GONE);
}
@Override
public String writeToModel(Task task) {
public void onNothingSelected(AdapterView<?> arg0) {
//
}
});
daysOfWeekContainer.setVisibility(View.GONE);
}
@Override
protected String writeToModelPrivate(Task task) {
String result;
if(!doRepeat)
result = ""; //$NON-NLS-1$
@ -278,7 +293,7 @@ public class RepeatControlSet extends PopupControlSet {
}
RRule rrule = new RRule();
rrule.setInterval((Integer)value.getTag());
rrule.setInterval(repeatValue);
switch(interval.getSelectedItemPosition()) {
case INTERVAL_DAYS:
rrule.setFreq(Frequency.DAILY);
@ -328,29 +343,47 @@ public class RepeatControlSet extends PopupControlSet {
return doRepeat;
}
/**
* @return the recurrence display string if set, null
* if not set
*/
public String getStringForExternalDisplay() {
if (isRecurrenceSet()) {
return getRepeatString(false);
}
return null;
}
@Override
protected void refreshDisplayView() {
TextView repeatDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
ImageView repeatImage = (ImageView) getDisplayView().findViewById(R.id.repeat_image_icon);
if (doRepeat) {
String[] dateAbbrev = activity.getResources().getStringArray(
R.array.repeat_interval_short);
String date = String.format("%s %s", (Integer)value.getTag(), dateAbbrev[interval.getSelectedItemPosition()]); //$NON-NLS-1$
String text = String.format(activity.getString(R.string.repeat_detail_duedate), date); // Every freq int
repeatDisplay.setText(text);
repeatDisplay.setText(getRepeatString(true));
TypedValue repeatIcon = new TypedValue();
activity.getTheme().resolveAttribute(R.attr.asRepeatIcon, repeatIcon, false);
repeatImage.setImageResource(repeatIcon.data);
} else {
repeatDisplay.setText(R.string.repeat_never);
repeatImage.setImageResource(R.drawable.icn_edit_repeats);
}
}
private String getRepeatString(boolean useAbbrev) {
int arrayResource;
if (useAbbrev)
arrayResource = R.array.repeat_interval_short;
else
arrayResource = R.array.repeat_interval;
String[] dates = activity.getResources().getStringArray(
arrayResource);
String date = String.format("%s %s", repeatValue, dates[intervalValue]); //$NON-NLS-1$
return String.format(activity.getString(R.string.repeat_detail_duedate), date); // Every freq int
}
@Override
protected Dialog buildDialog(String title, final DialogInterface.OnClickListener okListener, final DialogInterface.OnCancelListener cancelListener) {

@ -2,7 +2,6 @@ package com.todoroo.astrid.tags;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import android.app.Activity;
@ -44,32 +43,19 @@ public final class TagsControlSet extends PopupControlSet {
//private final Spinner tagSpinner;
//@Autowired private TagDataService tagDataService;
private final TagService tagService = TagService.getInstance();
private final ArrayList<String> allTagNames;
private ArrayList<String> allTagNames;
private final LinearLayout newTags;
private final ListView selectedTags;
private LinearLayout newTags;
private ListView selectedTags;
private boolean populated = false;
private final HashMap<String, Integer> tagIndices;
private HashMap<String, Integer> tagIndices;
//private final LinearLayout tagsContainer;
private final Activity activity;
private final TextView tagsDisplay;
public TagsControlSet(Activity activity, int viewLayout, int displayViewLayout, int title) {
super(activity, viewLayout, displayViewLayout, title);
DependencyInjectionService.getInstance().inject(this);
this.activity = activity;
Tag[] allTags = getTagArray();
allTagNames = getTagNames(allTags);
tagIndices = buildTagIndices(allTagNames);
selectedTags = (ListView) getView().findViewById(R.id.existingTags);
selectedTags.setAdapter(new ArrayAdapter<String>(activity,
R.layout.simple_list_item_multiple_choice_themed, allTagNames));
selectedTags.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
this.newTags = (LinearLayout) getView().findViewById(R.id.newTags);
tagsDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
this.displayText.setText(activity.getString(R.string.TEA_tags_label));
}
@ -124,6 +110,7 @@ public final class TagsControlSet extends PopupControlSet {
private LinkedHashSet<String> getTagSet() {
LinkedHashSet<String> tags = new LinkedHashSet<String>();
if (initialized) {
for(int i = 0; i < selectedTags.getAdapter().getCount(); i++) {
if (selectedTags.isItemChecked(i))
tags.add(allTagNames.get(i));
@ -136,6 +123,11 @@ public final class TagsControlSet extends PopupControlSet {
tags.add(tagName.getText().toString());
}
} else {
if (model.getTransitory("tags") != null) {
return (LinkedHashSet<String>) model.getTransitory("tags");
}
}
return tags;
}
@ -229,32 +221,62 @@ public final class TagsControlSet extends PopupControlSet {
@Override
public void readFromTask(Task task) {
newTags.removeAllViews();
for (int i = 0; i < selectedTags.getCount(); i++) { // clear all selected items
selectedTags.setItemChecked(i, false);
}
if(task.getId() != AbstractModel.NO_ID) {
TodorooCursor<Metadata> cursor = tagService.getTags(task.getId());
HashSet<String> tags = new HashSet<String>(cursor.getCount());
super.readFromTask(task);
if(model.getId() != AbstractModel.NO_ID) {
TodorooCursor<Metadata> cursor = tagService.getTags(model.getId());
LinkedHashSet<String> tags = new LinkedHashSet<String>(cursor.getCount());
try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
String tag = cursor.get(TagService.TAG);
setTagSelected(tag);
tags.add(tag);
}
} finally {
cursor.close();
}
task.putTransitory("tags", tags); //$NON-NLS-1$
model.putTransitory("tags", tags); //$NON-NLS-1$
}
}
@Override
protected void readFromTaskPrivate() {
newTags.removeAllViews();
for (int i = 0; i < selectedTags.getCount(); i++) { // clear all selected items
selectedTags.setItemChecked(i, false);
}
if(model.getId() != AbstractModel.NO_ID) {
selectTagsFromModel();
}
addTag("", false); //$NON-NLS-1$
refreshDisplayView();
populated = true;
}
private void selectTagsFromModel() {
LinkedHashSet<String> tags = (LinkedHashSet<String>) model.getTransitory("tags");
if (tags != null) {
for (String tag : tags) {
setTagSelected(tag);
}
}
}
@Override
protected void afterInflate() {
Tag[] allTags = getTagArray();
allTagNames = getTagNames(allTags);
tagIndices = buildTagIndices(allTagNames);
selectedTags = (ListView) getView().findViewById(R.id.existingTags);
selectedTags.setAdapter(new ArrayAdapter<String>(activity,
R.layout.simple_list_item_multiple_choice_themed, allTagNames));
selectedTags.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
this.newTags = (LinearLayout) getView().findViewById(R.id.newTags);
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
// this is a case where we're asked to save but the UI was not yet populated
if(!populated)
return null;

@ -125,6 +125,22 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
};
}
@Override
protected void readFromTaskPrivate() {
// Nothing, we don't lazy load this control set yet
}
@Override
protected String writeToModelPrivate(Task task) {
// Nothing, we don't lazy load this control set yet
return null;
}
@Override
protected void afterInflate() {
// Nothing, we don't lazy load this control set yet
}
@Override
public String writeToModel(Task task) {
return null;

@ -83,6 +83,22 @@ public class TaskRabbitDeadlineControlSet extends PopupControlSet implements Tas
refreshDisplayView();
}
@Override
protected void afterInflate() {
// Nothing, we don't lazy load this control set yet
}
@Override
protected void readFromTaskPrivate() {
// Nothing, we don't lazy load this control set yet
}
@Override
protected String writeToModelPrivate(Task task) {
// Nothing, we don't lazy load this control set yet
return null;
}
@Override
public void saveToDatabase(JSONObject json, String key) throws JSONException {

@ -196,6 +196,22 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
//
}
@Override
protected void afterInflate() {
// Nothing, we don't lazy load this control set yet
}
@Override
protected void readFromTaskPrivate() {
// Nothing, we don't lazy load this control set yet
}
@Override
protected String writeToModelPrivate(Task task) {
// Nothing, we don't lazy load this control set yet
return null;
}
@Override
public String writeToModel(Task task) {
return null;

@ -155,11 +155,27 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
//
}
@Override
protected void readFromTaskPrivate() {
// Nothing, we don't lazy load this control set yet
}
@Override
public String writeToModel(Task task) {
return null;
}
@Override
protected String writeToModelPrivate(Task task) {
// Nothing, we don't lazy load this control set yet
return null;
}
@Override
protected void afterInflate() {
// Nothing, we don't lazy load this control set yet
}
@Override
protected void onOkClick() {
super.onOkClick();

@ -193,6 +193,22 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
return;
}
@Override
protected void readFromTaskPrivate() {
// Nothing, we don't lazy load this control set yet
}
@Override
protected String writeToModelPrivate(Task task) {
// Nothing, we don't lazy load this control set yet
return null;
}
@Override
protected void afterInflate() {
// Nothing, we don't lazy load this control set yet
}
@Override
public String writeToModel(Task task) {
return null;

@ -24,13 +24,10 @@ public class TimerActionControlSet extends TaskEditControlSet {
private final Chronometer chronometer;
private final LinearLayout timerContainer;
private boolean timerActive;
private Task task;
private final Activity activity;
private final List<TimerActionListener> listeners = new LinkedList<TimerActionListener>();
public TimerActionControlSet(Activity activity, View parent) {
super(activity, -1);
this.activity = activity;
timerContainer = (LinearLayout) parent.findViewById(R.id.timer_container);
timerButton = (ImageView) parent.findViewById(R.id.timer_button);
timerContainer.setOnClickListener(timerListener);
@ -39,19 +36,23 @@ public class TimerActionControlSet extends TaskEditControlSet {
@Override
@SuppressWarnings("hiding")
public void readFromTask(Task task) {
if (task.getValue(Task.TIMER_START) == 0)
protected void readFromTaskPrivate() {
if (model.getValue(Task.TIMER_START) == 0)
timerActive = false;
else
timerActive = true;
this.task = task;
updateDisplay();
}
@Override
protected void afterInflate() {
// Do nothing
}
@Override
@SuppressWarnings("hiding")
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
// Nothing to do here
return null;
}
@ -60,15 +61,15 @@ public class TimerActionControlSet extends TaskEditControlSet {
@Override
public void onClick(View v) {
if (timerActive) {
TimerPlugin.updateTimer(activity, task, false);
TimerPlugin.updateTimer(activity, model, false);
for(TimerActionListener listener : listeners)
listener.timerStopped(task);
listener.timerStopped(model);
chronometer.stop();
} else {
TimerPlugin.updateTimer(activity, task, true);
TimerPlugin.updateTimer(activity, model, true);
for(TimerActionListener listener : listeners)
listener.timerStarted(task);
listener.timerStarted(model);
chronometer.start();
}
timerActive = !timerActive;
@ -86,10 +87,10 @@ public class TimerActionControlSet extends TaskEditControlSet {
timerButton.setImageResource(drawable);
long elapsed = task.getValue(Task.ELAPSED_SECONDS) * 1000L;
long elapsed = model.getValue(Task.ELAPSED_SECONDS) * 1000L;
if (timerActive) {
chronometer.setVisibility(View.VISIBLE);
elapsed += DateUtilities.now() - task.getValue(Task.TIMER_START);
elapsed += DateUtilities.now() - model.getValue(Task.TIMER_START);
chronometer.setBase(SystemClock.elapsedRealtime() - elapsed);
if (elapsed > DateUtilities.ONE_DAY); {
chronometer.setOnChronometerTickListener(new OnChronometerTickListener() {

@ -25,6 +25,19 @@ public class TimerControlSet extends PopupControlSet implements TimerActionListe
super(activity, viewLayout, displayViewLayout, title);
this.displayText.setText(activity.getString(R.string.TEA_timer_controls));
}
@Override
protected void readFromTaskPrivate() {
estimated.readFromTask(model);
estimated.getView(); // force load
elapsed.readFromTask(model);
elapsed.getView(); // force load
}
@Override
protected void afterInflate() {
estimated = new TimeDurationTaskEditControlSet(activity, getView(), Task.ESTIMATED_SECONDS,
R.id.estimatedDuration, 0, R.string.DLG_hour_minutes
);
@ -34,15 +47,11 @@ public class TimerControlSet extends PopupControlSet implements TimerActionListe
}
@Override
public void readFromTask(Task task) {
estimated.readFromTask(task);
elapsed.readFromTask(task);
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
if (initialized) {
estimated.writeToModel(task);
elapsed.writeToModel(task);
}
return null;
}
@ -66,12 +75,17 @@ public class TimerControlSet extends PopupControlSet implements TimerActionListe
}
@Override
public void readFromTask(Task task) {
controlSet.setTimeDuration(task.getValue(property));
public void readFromTaskPrivate() {
controlSet.setTimeDuration(model.getValue(property));
}
@Override
protected void afterInflate() {
// Nothing
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
task.setValue(property, controlSet.getTimeDurationInSeconds());
return null;
}

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:color="#444"/>
<item android:state_pressed="false"
android:color="#888"/>
<item android:state_pressed="false"
android:color="#fff"/>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 726 B

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="false" android:drawable="@drawable/timepicker_down_normal" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/timepicker_down_pressed" />
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="true" android:drawable="@drawable/timepicker_down_selected" />
<item android:state_pressed="false" android:state_enabled="false"
android:state_focused="false" android:drawable="@drawable/timepicker_down_disabled" />
<item android:state_pressed="false" android:state_enabled="false"
android:state_focused="true" android:drawable="@drawable/timepicker_down_normal" />
</selector>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="false" android:drawable="@drawable/timepicker_up_normal" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/timepicker_up_pressed" />
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="true" android:drawable="@drawable/timepicker_up_selected" />
<item android:state_pressed="false" android:state_enabled="false"
android:state_focused="false" android:drawable="@drawable/timepicker_up_disabled" />
<item android:state_pressed="false" android:state_enabled="false"
android:state_focused="true" android:drawable="@drawable/timepicker_up_normal" />
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 92 KiB

@ -23,24 +23,20 @@
android:id="@+id/lists_footer"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:padding="5dip"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_alignParentBottom="true">
<ImageView
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="8dip"
android:src="?attr/asAddButtonImg"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/new_list_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:gravity="left|center_vertical"
android:background="?attr/asThemeTextColor"
android:paddingLeft="12dip"
android:drawableLeft="@drawable/filter_plus_button"
android:drawablePadding="13dip"
android:text="@string/FLA_new_list"
style="@style/TextAppearance.FLA_Button"/>

@ -23,24 +23,20 @@
android:id="@+id/lists_footer"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:padding="5dip"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_alignParentBottom="true">
<ImageView
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="8dip"
android:src="?attr/asAddButtonImg"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/new_list_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:gravity="left|center_vertical"
android:background="?attr/asThemeTextColor"
android:paddingLeft="12dip"
android:drawableLeft="@drawable/filter_plus_button"
android:drawablePadding="13dip"
android:text="@string/FLA_new_list"
style="@style/TextAppearance.FLA_Button"/>

@ -15,32 +15,21 @@
<include layout="@layout/fla_separator"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical">
<ImageView
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="8dip"
android:src="?attr/asAddButtonImg"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/new_list_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dip"
android:layout_margin="6dip"
android:gravity="left|center_vertical"
android:background="?attr/asThemeTextColor"
android:paddingLeft="8dip"
android:drawableLeft="@drawable/filter_plus_button"
android:drawablePadding="13dip"
android:text="@string/FLA_new_list"
style="@style/TextAppearance.FLA_Button"/>
</LinearLayout>
</LinearLayout>
<!-- List -->
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"

@ -21,6 +21,7 @@
<com.todoroo.astrid.ui.NumberPickerButton android:id="@+id/increment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/timepicker_up_btn"
/>
<EditText android:id="@+id/timepicker_input"
@ -36,6 +37,7 @@
<com.todoroo.astrid.ui.NumberPickerButton android:id="@+id/decrement"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/timepicker_down_btn"
/>
</merge>

@ -19,7 +19,7 @@
<!-- hint when opening repeat interval -->
<string name="repeat_interval_prompt">Repeat Interval</string>
<string name="repeat_never">No Repeat</string>
<string name="repeat_never">Make Repeating?</string>
<string name="repeat_dont">Don\'t repeat</string>

@ -161,7 +161,7 @@ public class FilterListFragment extends ListFragment {
getActivity().setDefaultKeyMode(Activity.DEFAULT_KEYS_SEARCH_LOCAL);
//ImageView backButton = (ImageView) getView().findViewById(R.id.back);
newListButton = getView().findViewById(R.id.lists_footer);
newListButton = getView().findViewById(R.id.new_list_button);
newListButton.setOnClickListener(new OnClickListener() {
@Override

@ -538,7 +538,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
// Order matters!
DeadlineControlSet deadlineControl = new DeadlineControlSet(
getActivity(), R.layout.control_set_deadline,
R.layout.control_set_default_display,
R.layout.control_set_default_display, repeatControls,
repeatControls.getDisplayView(), gcalControl.getDisplayView());
controlSetMap.put(getString(R.string.TEA_ctrl_when_pref),
deadlineControl);

@ -639,7 +639,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
deadlineControl = new DeadlineControlSet(
getActivity(), R.layout.control_set_deadline,
R.layout.control_set_default_display,
R.layout.control_set_default_display, null,
repeatControl.getDisplayView(), gcalControl.getDisplayView());
deadlineControl.setIsQuickadd(true);

@ -162,6 +162,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
private final int resource;
private final LayoutInflater inflater;
private DetailLoaderThread detailLoader;
private ActionsLoaderThread actionsLoader;
private int fontSize;
protected boolean applyListenersToRowBody = false;
private long mostRecentlyMade = -1;
@ -214,6 +215,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
this.minRowHeight = (int) (57 * displayMetrics.density);
startDetailThread();
startTaskActionsThread();
decorationManager = new DecorationManager();
@ -230,6 +232,11 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
}
}
private void startTaskActionsThread() {
actionsLoader = new ActionsLoaderThread();
actionsLoader.start();
}
/* ======================================================================
* =========================================================== filterable
* ====================================================================== */
@ -633,7 +640,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
// a large number of tasks to load, since it all goes into memory.
// it's best to do this, though, in order to append details to each other
private final Map<Long, StringBuilder> taskDetailLoader = Collections.synchronizedMap(new HashMap<Long, StringBuilder>(0));
private final Map<Long, TaskAction> taskActionLoader = Collections.synchronizedMap(new HashMap<Long, TaskAction>());
public class DetailLoaderThread extends Thread {
@Override
@ -647,7 +653,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
Random random = new Random();
Task task = new Task();
LinkActionExposer linkActionExposer = new LinkActionExposer();
for(fetchCursor.moveToFirst(); !fetchCursor.isAfterLast(); fetchCursor.moveToNext()) {
task.clear();
@ -655,10 +660,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
if(task.isCompleted())
continue;
List<TaskAction> actions = linkActionExposer.getActionsForTask(ContextManager.getContext(), task.getId());
if (actions.size() > 0)
taskActionLoader.put(task.getId(), actions.get(0));
if(detailsAreRecentAndUpToDate(task)) {
// even if we are up to date, randomly load a fraction
if(random.nextFloat() < 0.1) {
@ -682,7 +683,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
requestNewDetails(task);
}
if(taskDetailLoader.size() > 0 || taskActionLoader.size() > 0) {
if(taskDetailLoader.size() > 0) {
Activity activity = fragment.getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@ -719,6 +720,46 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
}
}
private final Map<Long, TaskAction> taskActionLoader = Collections.synchronizedMap(new HashMap<Long, TaskAction>());
public class ActionsLoaderThread extends Thread {
@Override
public void run() {
AndroidUtilities.sleepDeep(500L);
TodorooCursor<Task> fetchCursor = taskService.fetchFiltered(
query.get(), null, Task.ID, Task.TITLE, Task.DETAILS, Task.DETAILS_DATE,
Task.MODIFICATION_DATE, Task.COMPLETION_DATE);
try {
Task task = new Task();
LinkActionExposer linkActionExposer = new LinkActionExposer();
for(fetchCursor.moveToFirst(); !fetchCursor.isAfterLast(); fetchCursor.moveToNext()) {
task.clear();
task.readFromCursor(fetchCursor);
if(task.isCompleted())
continue;
List<TaskAction> actions = linkActionExposer.getActionsForTask(ContextManager.getContext(), task.getId());
if (actions.size() > 0)
taskActionLoader.put(task.getId(), actions.get(0));
}
if(taskActionLoader.size() > 0) {
Activity activity = fragment.getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
notifyDataSetChanged();
}
});
}
}
} finally {
fetchCursor.close();
}
}
}
/**
* Add detail to a task
*
@ -796,6 +837,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
taskDetailLoader.clear();
taskActionLoader.clear();
startDetailThread();
startTaskActionsThread();
}
/**

@ -13,16 +13,27 @@ import com.todoroo.astrid.data.Task;
*/
public abstract class TaskEditControlSet {
private final View view;
protected final Activity activity;
private final int viewLayout;
private View view;
protected Task model;
protected boolean initialized = false;
public TaskEditControlSet(Activity activity, int viewLayout) {
if (viewLayout != -1)
this.view = LayoutInflater.from(activity).inflate(viewLayout, null);
else
this.view = null;
this.activity = activity;
this.viewLayout = viewLayout;
}
public View getView() {
if (view == null && !initialized) {
if (viewLayout != -1) {
view = LayoutInflater.from(activity).inflate(viewLayout, null);
afterInflate();
}
if (model != null)
readFromTaskPrivate();
this.initialized = true;
}
return view;
}
@ -33,12 +44,30 @@ public abstract class TaskEditControlSet {
/**
* Read data from model to update the control set
*/
public abstract void readFromTask(Task task);
public void readFromTask(Task task) {
this.model = task;
if (initialized)
readFromTaskPrivate();
}
/**
* Called once to setup the ui with data from the task
*/
protected abstract void readFromTaskPrivate();
/**
* Write data from control set to model
* @return text appended to the toast
*/
public abstract String writeToModel(Task task);
public String writeToModel(Task task) {
if (initialized) {
return writeToModelPrivate(task);
}
return null;
}
protected abstract String writeToModelPrivate(Task task);
protected abstract void afterInflate();
}

@ -1,6 +1,7 @@
package com.todoroo.astrid.ui;
import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@ -12,18 +13,46 @@ import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.repeats.RepeatControlSet;
public class DeadlineControlSet extends PopupControlSet {
private boolean isQuickadd = false;
private final DateAndTimePicker dateAndTimePicker;
private DateAndTimePicker dateAndTimePicker;
private final View[] extraViews;
private final RepeatControlSet repeatControlSet;
public DeadlineControlSet(Activity activity, int viewLayout, int displayViewLayout, View...extraViews) {
public DeadlineControlSet(Activity activity, int viewLayout, int displayViewLayout,
RepeatControlSet repeatControlSet, View...extraViews) {
super(activity, viewLayout, displayViewLayout, 0);
this.extraViews = extraViews;
this.displayText.setText(activity.getString(R.string.TEA_when_header_label));
this.repeatControlSet = repeatControlSet;
}
@Override
protected void refreshDisplayView() {
StringBuilder displayString = new StringBuilder();
if (initialized)
displayString.append(dateAndTimePicker.getDisplayString(activity, isQuickadd, isQuickadd));
else
displayString.append(DateAndTimePicker.getDisplayString(activity, model.getValue(Task.DUE_DATE), isQuickadd, isQuickadd));
if (!isQuickadd && repeatControlSet != null) {
String repeatString = repeatControlSet.getStringForExternalDisplay();
if (!TextUtils.isEmpty(repeatString)) {
displayString.append("\n"); //$NON-NLS-1$
displayString.append(repeatString);
}
}
TextView dateDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
dateDisplay.setText(displayString);
}
@Override
protected void afterInflate() {
dateAndTimePicker = (DateAndTimePicker) getView().findViewById(R.id.date_and_time);
LinearLayout extras = (LinearLayout) getView().findViewById(R.id.datetime_extras);
this.displayText.setText(activity.getString(R.string.TEA_when_header_label));
for (View v : extraViews) {
LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f);
extras.addView(v, lp);
@ -42,32 +71,25 @@ public class DeadlineControlSet extends PopupControlSet {
}
@Override
protected void refreshDisplayView() {
TextView dateDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
String toDisplay = dateAndTimePicker.getDisplayString(activity, isQuickadd, isQuickadd);
dateDisplay.setText(toDisplay);
}
@Override
public void readFromTask(Task task) {
long dueDate = task.getValue(Task.DUE_DATE);
protected void readFromTaskPrivate() {
long dueDate = model.getValue(Task.DUE_DATE);
initializeWithDate(dueDate);
refreshDisplayView();
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
long dueDate = dateAndTimePicker.constructDueDate();
task.setValue(Task.DUE_DATE, dueDate);
return null;
}
public void initializeWithDate(long dueDate) {
private void initializeWithDate(long dueDate) {
dateAndTimePicker.initializeWithDate(dueDate);
}
public boolean isDeadlineSet() {
return dateAndTimePicker.constructDueDate() != 0;
return (dateAndTimePicker != null && dateAndTimePicker.constructDueDate() != 0);
}
/**

@ -18,28 +18,23 @@ import com.todoroo.astrid.ui.TextViewWithMeasureListener.OnTextMeasureListener;
public class EditNotesControlSet extends PopupControlSet {
protected final EditText editText;
protected final TextViewWithMeasureListener notesPreview;
private final LinearLayout notesBody;
protected EditText editText;
protected TextViewWithMeasureListener notesPreview;
private LinearLayout notesBody;
public EditNotesControlSet(Activity activity, int viewLayout, int displayViewLayout) {
super(activity, viewLayout, displayViewLayout, R.string.TEA_note_label);
editText = (EditText) getView().findViewById(R.id.notes);
notesPreview = (TextViewWithMeasureListener) getDisplayView().findViewById(R.id.display_row_edit);
notesBody = (LinearLayout) getDisplayView().findViewById(R.id.notes_body);
dialog.getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
notesPreview.setOnTextSizeChangedListener(new OnTextMeasureListener() {
@Override
public void onTextSizeChanged() {
setupGravity();
}
});
}
@Override
protected void refreshDisplayView() {
notesPreview.setText(editText.getText());
CharSequence textToUse;
if (initialized)
textToUse = editText.getText();
else
textToUse = model.getValue(Task.NOTES);
notesPreview.setText(textToUse);
setupGravity();
linkifyDisplayView();
}
@ -52,14 +47,35 @@ public class EditNotesControlSet extends PopupControlSet {
}
@Override
public void readFromTask(Task task) {
editText.setTextKeepState(task.getValue(Task.NOTES));
notesPreview.setText(task.getValue(Task.NOTES));
protected void afterInflate() {
editText = (EditText) getView().findViewById(R.id.notes);
notesPreview = (TextViewWithMeasureListener) getDisplayView().findViewById(R.id.display_row_edit);
notesBody = (LinearLayout) getDisplayView().findViewById(R.id.notes_body);
notesPreview.setOnTextSizeChangedListener(new OnTextMeasureListener() {
@Override
public void onTextSizeChanged() {
setupGravity();
}
});
}
@Override
protected void additionalDialogSetup() {
super.additionalDialogSetup();
dialog.getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
@Override
protected void readFromTaskPrivate() {
editText.setTextKeepState(model.getValue(Task.NOTES));
notesPreview.setText(model.getValue(Task.NOTES));
linkifyDisplayView();
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
task.setValue(Task.NOTES, editText.getText().toString());
return null;
}

@ -22,10 +22,10 @@ import com.todoroo.astrid.service.TaskService;
*
*/
public class EditTextControlSet extends TaskEditControlSet {
private final EditText editText;
private EditText editText;
private final StringProperty property;
protected Task model;
protected CheckBox completeBox;
private final int editTextId;
@Autowired
private TaskService taskService;
@ -34,16 +34,20 @@ public class EditTextControlSet extends TaskEditControlSet {
public EditTextControlSet(Activity activity, int layout, StringProperty property, int editText) {
super(activity, layout);
this.property = property;
this.editText = (EditText) getView().findViewById(editText);
this.completeBox = (CheckBox) getView().findViewById(R.id.completeBox);
this.editTextId = editText;
DependencyInjectionService.getInstance().inject(this);
}
@Override
public void readFromTask(Task task) {
model = task;
editText.setTextKeepState(task.getValue(property));
completeBox.setChecked(task.isCompleted());
protected void afterInflate() {
this.editText = (EditText) getView().findViewById(editTextId);
this.completeBox = (CheckBox) getView().findViewById(R.id.completeBox);
}
@Override
protected void readFromTaskPrivate() {
editText.setTextKeepState(model.getValue(property));
completeBox.setChecked(model.isCompleted());
completeBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -58,7 +62,7 @@ public class EditTextControlSet extends TaskEditControlSet {
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
task.setValue(property, editText.getText().toString());
boolean newState = completeBox.isChecked();
if (newState != task.isCompleted()) {

@ -5,7 +5,6 @@ import java.util.Date;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
@ -31,20 +30,17 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
private static final int EXISTING_TIME_UNSET = -2;
//private final CheckBox enabled;
private final Spinner spinner;
private Spinner spinner;
private int previousSetting = Task.HIDE_UNTIL_NONE;
private final int title;
private int selection;
private long existingDate = EXISTING_TIME_UNSET;
public HideUntilControlSet(Activity activity, int viewLayout, int displayViewLayout, int title) {
super(activity, viewLayout, displayViewLayout, title);
this.spinner = (Spinner) getView().findViewById(R.id.hideUntil);
this.spinner.setOnItemSelectedListener(this);
this.spinner.setPromptId(title);
this.title = title;
this.displayText.setText(activity.getString(R.string.TEA_hideUntil_label));
ViewGroup parent = (ViewGroup) getView().getParent();
parent.removeView(getView());
((LinearLayout) getDisplayView()).addView(getView()); // hack to make listeners work
}
private ArrayAdapter<HideUntilValue> adapter;
@ -145,6 +141,7 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
} else {
previousSetting = position;
}
selection = spinner.getSelectedItemPosition();
refreshDisplayView();
}
@ -171,7 +168,9 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
public void setDefaults() {
int setting = Preferences.getIntegerFromString(R.string.p_default_hideUntil_key,
Task.HIDE_UNTIL_NONE);
spinner.setSelection(setting);
selection = setting;
if (spinner != null)
spinner.setSelection(selection);
refreshDisplayView();
}
@ -180,6 +179,8 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
return new OnClickListener() {
@Override
public void onClick(View v) {
if (spinner == null) // Force load
getView();
spinner.performClick();
}
};
@ -187,9 +188,16 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
@Override
protected void refreshDisplayView() {
HideUntilValue value = adapter.getItem(spinner.getSelectedItemPosition());
TextView auxDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
auxDisplay.setText(value.toString());
auxDisplay.setText(adapter.getItem(selection).toString());
}
@Override
protected void afterInflate() {
this.spinner = (Spinner) getView().findViewById(R.id.hideUntil);
this.spinner.setOnItemSelectedListener(this);
this.spinner.setPromptId(title);
((LinearLayout) getDisplayView()).addView(getView()); // hack to make listeners work
}
@Override
@ -205,7 +213,6 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
// For the hide until due case, we need the time component
long dueTime = task.hasDueTime() ? task.getValue(Task.DUE_DATE)/1000L*1000L : dueDay.getTime();
int selection = 0;
if(date == 0) {
selection = 0;
date = 0;
@ -220,17 +227,15 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
date = 0;
}
if (selection == 0) {
//enabled.setChecked(false);
//spinner.setVisibility(View.GONE);
} else {
//enabled.setChecked(true);
//spinner.setVisibility(View.VISIBLE);
}
HideUntilValue[] list = createHideUntilList(date);
adapter = new ArrayAdapter<HideUntilValue>(
activity, android.R.layout.simple_spinner_item, list);
super.readFromTask(task);
}
@Override
protected void readFromTaskPrivate() {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
@ -239,7 +244,7 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
if(adapter == null || spinner == null)
return null;
HideUntilValue item = adapter.getItem(spinner.getSelectedItemPosition());

@ -24,7 +24,7 @@ import com.todoroo.astrid.producteev.ProducteevUtilities;
*/
public class ImportanceControlSet extends TaskEditControlSet {
private final List<CompoundButton> buttons = new LinkedList<CompoundButton>();
private final int[] colors;
private int[] colors;
//private final int grayColor;
private final List<ImportanceChangedListener> listeners = new LinkedList<ImportanceChangedListener>();
@ -34,6 +34,54 @@ public class ImportanceControlSet extends TaskEditControlSet {
public ImportanceControlSet(Activity activity, int layout) {
super(activity, layout);
}
public void setImportance(Integer i) {
for(CompoundButton b : buttons) {
if(b.getTag() == i) {
b.setTextSize(getTextSize());
b.setChecked(true);
//if (i.intValue() == Task.IMPORTANCE_LEAST)
// b.setTextColor(grayColor);
b.setBackgroundResource(R.drawable.importance_background_selected);
} else {
b.setTextSize(getTextSize());
b.setChecked(false);
b.setTextColor(colors[(Integer)b.getTag()]);
b.setBackgroundResource(0);
}
}
for (ImportanceChangedListener l : listeners) {
l.importanceChanged(i, colors[i]);
}
}
private int getTextSize() {
if (ProducteevUtilities.INSTANCE.isLoggedIn())
return 14;
else
return 24;
}
public Integer getImportance() {
for(CompoundButton b : buttons)
if(b.isChecked())
return (Integer) b.getTag();
return null;
}
public void addListener(ImportanceChangedListener listener) {
listeners.add(listener);
}
public void removeListener(ImportanceChangedListener listener) {
if (listeners.contains(listener))
listeners.remove(listener);
}
@Override
protected void afterInflate() {
LinearLayout container = (LinearLayout) getView().findViewById(R.id.importance_container);
colors = Task.getImportanceColors(activity.getResources());
@ -96,57 +144,13 @@ public class ImportanceControlSet extends TaskEditControlSet {
}
}
public void setImportance(Integer i) {
for(CompoundButton b : buttons) {
if(b.getTag() == i) {
b.setTextSize(getTextSize());
b.setChecked(true);
//if (i.intValue() == Task.IMPORTANCE_LEAST)
// b.setTextColor(grayColor);
b.setBackgroundResource(R.drawable.importance_background_selected);
} else {
b.setTextSize(getTextSize());
b.setChecked(false);
b.setTextColor(colors[(Integer)b.getTag()]);
b.setBackgroundResource(0);
}
}
for (ImportanceChangedListener l : listeners) {
l.importanceChanged(i, colors[i]);
}
}
private int getTextSize() {
if (ProducteevUtilities.INSTANCE.isLoggedIn())
return 14;
else
return 24;
}
public Integer getImportance() {
for(CompoundButton b : buttons)
if(b.isChecked())
return (Integer) b.getTag();
return null;
}
public void addListener(ImportanceChangedListener listener) {
listeners.add(listener);
}
public void removeListener(ImportanceChangedListener listener) {
if (listeners.contains(listener))
listeners.remove(listener);
}
@Override
public void readFromTask(Task task) {
setImportance(task.getValue(Task.IMPORTANCE));
protected void readFromTaskPrivate() {
setImportance(model.getValue(Task.IMPORTANCE));
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
if(getImportance() != null)
task.setValue(Task.IMPORTANCE, getImportance());
return null;

@ -16,29 +16,16 @@ import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.service.ThemeService;
public abstract class PopupControlSet extends TaskEditControlSet {
protected final View displayView;
protected final Activity activity;
protected final Dialog dialog;
protected Dialog dialog;
protected final TextView displayText;
public PopupControlSet(Activity activity, int viewLayout, int displayViewLayout, final int title) {
super(activity, viewLayout);
if (displayViewLayout != -1){
this.displayView = LayoutInflater.from(activity).inflate(displayViewLayout, null);
displayText = (TextView) displayView.findViewById(R.id.display_row_title);
if (displayText != null) {
displayText.setMaxLines(2);
}
}
else {
this.displayView = null;
this.displayText = null;
}
private final String titleString;
final DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@Override
@ -54,13 +41,21 @@ public abstract class PopupControlSet extends TaskEditControlSet {
}
};
this.activity = activity;
String titleString = (title > 0) ? activity.getString(title) : "";
dialog = buildDialog(titleString, okListener, cancelListener);
public PopupControlSet(Activity activity, int viewLayout, int displayViewLayout, final int title) {
super(activity, viewLayout);
if (displayViewLayout != -1){
this.displayView = LayoutInflater.from(activity).inflate(displayViewLayout, null);
displayText = (TextView) displayView.findViewById(R.id.display_row_title);
if (displayText != null) {
displayText.setMaxLines(2);
}
}
else {
this.displayView = null;
this.displayText = null;
}
titleString = (title > 0) ? activity.getString(title) : "";
if (displayView != null) {
displayView.setOnClickListener(getDisplayClickListener());
@ -71,27 +66,29 @@ public abstract class PopupControlSet extends TaskEditControlSet {
return displayView;
}
protected Dialog buildDialog(String title, final DialogInterface.OnClickListener okListener, DialogInterface.OnCancelListener cancelListener) {
protected Dialog buildDialog(String title, final DialogInterface.OnClickListener okClickListener, DialogInterface.OnCancelListener cancelClickListener) {
int theme = ThemeService.getEditDialogTheme();
final Dialog d = new Dialog(activity, theme);
dialog = new Dialog(activity, theme);
if (title.length() == 0)
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
else
d.setTitle(title);
dialog.setTitle(title);
View v = getView();
d.setContentView(v, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
dialog.setContentView(v, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Button dismiss = (Button) v.findViewById(R.id.edit_dlg_ok);
if (dismiss != null) {
dismiss.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
okListener.onClick(d, 0);
DialogUtilities.dismissDialog(activity, d);
okClickListener.onClick(dialog, 0);
DialogUtilities.dismissDialog(activity, dialog);
}
});
}
LayoutParams params = d.getWindow().getAttributes();
LayoutParams params = dialog.getWindow().getAttributes();
params.width = LayoutParams.FILL_PARENT;
params.height = LayoutParams.WRAP_CONTENT;
Configuration config = activity.getResources().getConfiguration();
@ -100,22 +97,31 @@ public abstract class PopupControlSet extends TaskEditControlSet {
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
params.width = metrics.widthPixels / 2;
}
d.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
dialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
d.setOnCancelListener(cancelListener);
d.setOwnerActivity(PopupControlSet.this.activity);
return d;
dialog.setOnCancelListener(cancelClickListener);
dialog.setOwnerActivity(PopupControlSet.this.activity);
additionalDialogSetup();
return dialog;
}
protected OnClickListener getDisplayClickListener() {
return new OnClickListener() {
@Override
public void onClick(View v) {
if (dialog == null) {
buildDialog(titleString, okListener, cancelListener);
}
dialog.show();
}
};
}
protected void additionalDialogSetup() {
// Will be called after dialog is set up.
// Subclasses can override
}
protected void onOkClick() {
refreshDisplayView();
}
@ -124,5 +130,11 @@ public abstract class PopupControlSet extends TaskEditControlSet {
refreshDisplayView();
}
@Override
public void readFromTask(Task task) {
super.readFromTask(task);
refreshDisplayView();
}
protected abstract void refreshDisplayView();
}

@ -25,12 +25,14 @@ public class RandomReminderControlSet extends TaskEditControlSet {
private final CheckBox settingCheckbox;
private final Spinner periodSpinner;
private final View parentView;
private boolean periodSpinnerInitialized = false;
private final int[] hours;
public RandomReminderControlSet(Activity activity, View parentView, int layout) {
super(activity, layout);
this.parentView = parentView;
settingCheckbox = (CheckBox) parentView.findViewById(R.id.reminder_random);
periodSpinner = (Spinner) parentView.findViewById(R.id.reminder_random_interval);
periodSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@ -63,8 +65,13 @@ public class RandomReminderControlSet extends TaskEditControlSet {
}
@Override
public void readFromTask(Task task) {
long time = task.getValue(Task.REMINDER_PERIOD);
protected void afterInflate() {
// Nothing to do here
}
@Override
protected void readFromTaskPrivate() {
long time = model.getValue(Task.REMINDER_PERIOD);
boolean enabled = time > 0;
if(time <= 0) {
@ -80,7 +87,7 @@ public class RandomReminderControlSet extends TaskEditControlSet {
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
if(settingCheckbox.isChecked()) {
int hourValue = hours[periodSpinner.getSelectedItemPosition()];
task.setValue(Task.REMINDER_PERIOD, hourValue * DateUtilities.ONE_HOUR);

@ -1,5 +1,8 @@
package com.todoroo.astrid.ui;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.view.View;
import android.widget.ArrayAdapter;
@ -18,44 +21,26 @@ import com.todoroo.astrid.data.Task;
*
*/
public class ReminderControlSet extends PopupControlSet {
private final CheckBox during, after;
private final Spinner mode;
private final LinearLayout remindersBody;
private CheckBox during, after;
private Spinner mode;
private LinearLayout remindersBody;
private final List<View> extraViews;
private final RandomReminderControlSet randomControlSet;
private final AlarmControlSet alarmControl;
private RandomReminderControlSet randomControlSet;
private AlarmControlSet alarmControl;
public ReminderControlSet(Activity activity, int viewLayout, int displayViewLayout) {
super(activity, viewLayout, displayViewLayout, R.string.TEA_reminders_group_label);
during = (CheckBox) getView().findViewById(R.id.reminder_due);
after = (CheckBox) getView().findViewById(R.id.reminder_overdue);
mode = (Spinner) getView().findViewById(R.id.reminder_alarm);
randomControlSet = new RandomReminderControlSet(activity, getView(), -1);
alarmControl = new AlarmControlSet(activity, R.layout.control_set_alarms);
remindersBody = (LinearLayout) getView().findViewById(R.id.reminders_body);
remindersBody.addView(alarmControl.getView());
extraViews = new ArrayList<View>();
displayText.setText(activity.getString(R.string.TEA_reminders_group_label));
String[] list = new String[] {
activity.getString(R.string.TEA_reminder_mode_once),
activity.getString(R.string.TEA_reminder_mode_five),
activity.getString(R.string.TEA_reminder_mode_nonstop),
};
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
activity, android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
mode.setAdapter(adapter);
}
});
}
public void addViewToBody(View v) {
if (remindersBody != null)
remindersBody.addView(v, 0);
else
extraViews.add(v);
}
public void setValue(int flags) {
@ -88,14 +73,47 @@ public class ReminderControlSet extends PopupControlSet {
}
@Override
public void readFromTask(Task task) {
setValue(task.getValue(Task.REMINDER_FLAGS));
randomControlSet.readFromTask(task);
alarmControl.readFromTask(task);
protected void afterInflate() {
during = (CheckBox) getView().findViewById(R.id.reminder_due);
after = (CheckBox) getView().findViewById(R.id.reminder_overdue);
mode = (Spinner) getView().findViewById(R.id.reminder_alarm);
randomControlSet = new RandomReminderControlSet(activity, getView(), -1);
alarmControl = new AlarmControlSet(activity, R.layout.control_set_alarms);
alarmControl.readFromTask(model);
remindersBody = (LinearLayout) getView().findViewById(R.id.reminders_body);
remindersBody.addView(alarmControl.getView());
while (extraViews.size() > 0) {
addViewToBody(extraViews.remove(0));
}
String[] list = new String[] {
activity.getString(R.string.TEA_reminder_mode_once),
activity.getString(R.string.TEA_reminder_mode_five),
activity.getString(R.string.TEA_reminder_mode_nonstop),
};
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
activity, android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
mode.setAdapter(adapter);
}
});
}
@Override
protected void readFromTaskPrivate() {
setValue(model.getValue(Task.REMINDER_FLAGS));
// Calls to get view will force other control sets to load
randomControlSet.readFromTask(model);
randomControlSet.readFromTaskPrivate();
}
@Override
public String writeToModel(Task task) {
protected String writeToModelPrivate(Task task) {
task.setValue(Task.REMINDER_FLAGS, getValue());
// clear snooze if task is being edited
task.setValue(Task.REMINDER_SNOOZE, 0L);

@ -1,297 +0,0 @@
package com.todoroo.astrid.ui;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.atomic.AtomicBoolean;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.ui.DeadlineTimePickerDialog.OnDeadlineTimeSetListener;
public class UrgencyControlSet extends TaskEditControlSet implements OnDeadlineTimeSetListener {
private static final int SPECIFIC_DATE = -1;
private final Button dateButton;
private final Button timeButton;
private ArrayAdapter<UrgencyValue> urgencyAdapter;
private final TextView auxDisplay;
private final Activity activity;
private long dueDateValue = 0;
private long dueTimeValue = 0;
/**
* Container class for urgencies
*
* @author Tim Su <tim@todoroo.com>
*
*/
private class UrgencyValue {
public String label;
public int setting;
public long dueDate;
public UrgencyValue(String label, int setting) {
this.label = label;
this.setting = setting;
dueDate = Task.createDueDate(setting, 0);
}
public UrgencyValue(String label, int setting, long dueDate) {
this.label = label;
this.setting = setting;
this.dueDate = dueDate;
}
@Override
public String toString() {
return label;
}
}
public UrgencyControlSet(Activity activity, int layout, int extensionViewId, int auxDisplayId, int...quickWhenIds) {
super(activity, layout);
this.activity = activity;
this.dateButton = (Button) getView().findViewById(R.id.urgency_date);
this.timeButton = (Button) getView().findViewById(R.id.urgency_time);
View extensionView = activity.findViewById(extensionViewId);
for (int id : quickWhenIds) {
View quickWhen = extensionView.findViewById(id);
if (quickWhen != null) {
quickWhen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dateButton.performClick();
}
});
}
}
auxDisplay = (TextView) extensionView.findViewById(auxDisplayId);
dateButton.setOnClickListener(dateButtonClick);
timeButton.setOnClickListener(timeButtonClick);
}
// --- events
View.OnClickListener dateButtonClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
showUrgencySpinner(dueDateValue);
}
};
View.OnClickListener timeButtonClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean hasTime = Task.hasDueTime(dueTimeValue);
int hour = 18, minute = 0;
if(hasTime) {
Date date = new Date(dueTimeValue);
hour = date.getHours();
minute = date.getMinutes();
}
DeadlineTimePickerDialog timePicker = new DeadlineTimePickerDialog(activity,
UrgencyControlSet.this,
hour, minute,
DateUtilities.is24HourFormat(activity), true);
timePicker.show();
}
};
/**
* set up urgency adapter and picks the right selected item
* @param dueDate
*/
private void showUrgencySpinner(long dueDate) {
// set up base urgency list
String[] labels = activity.getResources().getStringArray(R.array.TEA_urgency);
UrgencyValue[] urgencyValues = new UrgencyValue[labels.length];
urgencyValues[0] = new UrgencyValue(labels[0],
Task.URGENCY_NONE);
urgencyValues[1] = new UrgencyValue(labels[1],
Task.URGENCY_SPECIFIC_DAY_TIME, SPECIFIC_DATE);
urgencyValues[2] = new UrgencyValue(labels[2],
Task.URGENCY_TODAY);
urgencyValues[3] = new UrgencyValue(labels[3],
Task.URGENCY_TOMORROW);
String dayAfterTomorrow = DateUtils.getDayOfWeekString(
new Date(DateUtilities.now() + 2 * DateUtilities.ONE_DAY).getDay() +
Calendar.SUNDAY, DateUtils.LENGTH_LONG);
urgencyValues[4] = new UrgencyValue(dayAfterTomorrow,
Task.URGENCY_DAY_AFTER);
urgencyValues[5] = new UrgencyValue(labels[5],
Task.URGENCY_NEXT_WEEK);
urgencyValues[6] = new UrgencyValue(labels[6],
Task.URGENCY_IN_TWO_WEEKS);
urgencyValues[7] = new UrgencyValue(labels[7],
Task.URGENCY_NEXT_MONTH);
// search for setting
int selection = -1;
for(int i = 0; i < urgencyValues.length; i++)
if(urgencyValues[i].dueDate == dueDate) {
selection = i;
break;
}
if(selection == -1) {
UrgencyValue[] updated = new UrgencyValue[labels.length + 1];
for(int i = 0; i < labels.length; i++)
updated[i+1] = urgencyValues[i];
if(Task.hasDueTime(dueDate)) {
Date dueDateAsDate = new Date(dueDate);
updated[0] = new UrgencyValue(DateUtilities.getDateStringWithTime(activity, dueDateAsDate),
Task.URGENCY_SPECIFIC_DAY_TIME, dueDate);
} else {
updated[0] = new UrgencyValue(DateUtilities.getDateString(activity, new Date(dueDate)),
Task.URGENCY_SPECIFIC_DAY, dueDate);
}
selection = 0;
urgencyValues = updated;
}
urgencyAdapter = new ArrayAdapter<UrgencyValue>(
activity, android.R.layout.simple_dropdown_item_1line,
urgencyValues);
new AlertDialog.Builder(activity)
.setTitle(R.string.TEA_urgency_label)
.setAdapter(urgencyAdapter, spinnerClickListener)
.setIcon(R.drawable.gl_date_blue)
.show().setOwnerActivity(activity);
}
DialogInterface.OnClickListener spinnerClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int position) {
UrgencyValue item = urgencyAdapter.getItem(position);
if(item.dueDate == SPECIFIC_DATE) {
customSetting = item.setting;
Date date = new Date(dueDateValue == 0 ? DateUtilities.now() : dueDateValue);
date.setSeconds(0);
final CalendarDialog calendarDialog = new CalendarDialog(activity, date);
final AtomicBoolean cancelled = new AtomicBoolean(false);
calendarDialog.show();
calendarDialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
if (!cancelled.get())
setDateFromCalendar(calendarDialog);
}
});
calendarDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
cancelled.set(true);
}
});
} else {
dueDateValue = item.dueDate;
if(dueDateValue == 0)
dueTimeValue = 0;
updateButtons();
}
}
};
// --- date setting logic
int customSetting;
private void setDateFromCalendar(CalendarDialog calendarDialog) {
Date date = calendarDialog.getCalendarDate();
date.setMinutes(0);
dueDateValue = Task.createDueDate(customSetting, date.getTime());
updateButtons();
}
public void onTimeSet(TimePicker view, boolean hasTime, int hourOfDay, int minute) {
if(!hasTime)
dueTimeValue = 0;
else {
Date date = new Date();
date.setHours(hourOfDay);
date.setMinutes(minute);
date.setSeconds(0);
dueTimeValue = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, date.getTime());
if(dueDateValue == 0)
dueDateValue = DateUtilities.now();
}
updateButtons();
}
@SuppressWarnings("nls")
private void updateButtons() {
String auxString = "";
if(dueDateValue == 0) {
dateButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.gl_date, 0, 0, 0);
dateButton.setText(R.string.TEA_urgency_none);
} else {
dateButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.gl_date_blue, 0, 0, 0);
dateButton.setText(DateUtilities.getDateString(activity, new Date(dueDateValue)));
auxString += dateButton.getText();
}
if(dueTimeValue == 0 || !Task.hasDueTime(dueTimeValue)) {
timeButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.gl_time, 0, 0, 0);
timeButton.setText(R.string.TEA_urgency_none);
} else {
timeButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.gl_time_blue, 0, 0, 0);
timeButton.setText(DateUtilities.getTimeString(activity, new Date(dueTimeValue)));
auxString += (", " + timeButton.getText());
}
if (auxDisplay != null) {
auxDisplay.setText(auxString);
}
}
// --- setting up values
@Override
public void readFromTask(Task task) {
dueTimeValue = dueDateValue = task.getValue(Task.DUE_DATE);
updateButtons();
}
@Override
public String writeToModel(Task task) {
Date date = new Date(dueDateValue);
if(dueTimeValue > 0) {
Date time = new Date(dueTimeValue);
date.setHours(time.getHours());
date.setMinutes(time.getMinutes());
date.setSeconds(time.getSeconds());
} else {
date.setTime(Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDateValue));
}
task.setValue(Task.DUE_DATE, date.getTime());
return null;
}
}
Loading…
Cancel
Save