Partial Fix for 13186793 (GCal-default setting, create a new event for new tasks). Also, events are now deleted when you delete a single task or delete completed or purge deleted tasks.

pull/14/head
Arne Jans 13 years ago
parent b168ca1a28
commit 84625149b1

@ -12,12 +12,16 @@ import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.TodorooPreferenceActivity;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalControlSet;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TaskService;
@ -73,6 +77,19 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
runWithDialog(new Runnable() {
@Override
public void run() {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try {
Task task = new Task();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
GCalControlSet.deleteTaskEvent(task);
}
} finally {
cursor.close();
}
Task template = new Task();
template.setValue(Task.DELETION_DATE,
DateUtilities.now());
@ -99,6 +116,19 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
runWithDialog(new Runnable() {
@Override
public void run() {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.TITLE, Task.CALENDAR_URI).where(
Criterion.and(Task.DELETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try {
Task task = new Task();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
GCalControlSet.deleteTaskEvent(task);
}
} finally {
cursor.close();
}
int result = taskService.deleteWhere(Task.DELETION_DATE.gt(0));
metadataService.cleanup();
showResult(

@ -22,10 +22,13 @@ import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.Calendars.CalendarResult;
import com.todoroo.astrid.service.StatisticsService;
@ -115,6 +118,34 @@ public class GCalControlSet implements TaskEditControlSet {
});
}
public static void deleteTaskEvent(Task task) {
String uri = task.getValue(Task.CALENDAR_URI);
Uri calendarUri = null;
if (TextUtils.isEmpty(uri)) {
task = PluginServices.getTaskService().fetchById(task.getId(), Task.ID, Task.CALENDAR_URI);
uri = task.getValue(Task.CALENDAR_URI);
}
if(!TextUtils.isEmpty(uri)) {
try {
calendarUri = Uri.parse(uri);
// try to load calendar
ContentResolver cr = ContextManager.getContext().getContentResolver();
Cursor cursor = cr.query(calendarUri, new String[] { "dtstart" }, null, null, null); //$NON-NLS-1$
boolean deleted = cursor.getCount() == 0;
cursor.close();
if (!deleted) {
cr.delete(calendarUri, null, null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void readFromTask(Task task) {
this.myTask = task;
@ -146,7 +177,9 @@ public class GCalControlSet implements TaskEditControlSet {
@SuppressWarnings("nls")
@Override
public String writeToModel(Task task) {
if(addToCalendar.isChecked() && calendarUri == null) {
if (((Preferences.getBoolean(R.string.p_default_addtocalendar_key, false) && !task.isSaved())
|| addToCalendar.isChecked()) &&
calendarUri == null) {
StatisticsService.reportEvent("create-calendar-event");
try{
@ -166,13 +199,19 @@ public class GCalControlSet implements TaskEditControlSet {
createStartAndEndDate(task, values);
calendarUri = cr.insert(uri, values);
cr.notifyChange(uri, null);
task.setValue(Task.CALENDAR_URI, calendarUri.toString());
// pop up the new event
Intent intent = new Intent(Intent.ACTION_EDIT, calendarUri);
intent.putExtra("beginTime", values.getAsLong("dtstart"));
intent.putExtra("endTime", values.getAsLong("dtend"));
activity.startActivity(intent);
// if the default-setting says so, create the gcal-event silently
if (!Preferences.getBoolean(R.string.p_default_addtocalendar_key, false) ||
(addToCalendar.isChecked() && addToCalendar.isShown())) {
// pop up the new event
Intent intent = new Intent(Intent.ACTION_EDIT, calendarUri);
intent.putExtra("beginTime", values.getAsLong("dtstart"));
intent.putExtra("endTime", values.getAsLong("dtend"));
activity.startActivity(intent);
}
} catch (Exception e) {
exceptionService.displayAndReportError(activity,
activity.getString(R.string.gcal_TEA_error), e);
@ -205,6 +244,7 @@ public class GCalControlSet implements TaskEditControlSet {
@SuppressWarnings("nls")
private void createStartAndEndDate(Task task, ContentValues values) {
long dueDate = task.getValue(Task.DUE_DATE);
// FIXME: doesnt respect timezones, see story 17443653
if(task.hasDueDate()) {
if(task.hasDueTime()) {
long estimatedTime = task.getValue(Task.ESTIMATED_SECONDS);

@ -693,9 +693,12 @@
<!-- Preference: Default Reminders Title -->
<string name="EPr_default_reminders_title">Standarderinnerungen</string>
<!-- Preference: Default Hide Until Description (%s => setting) -->
<!-- Preference: Default Reminders Description (%s => setting) -->
<string name="EPr_default_reminders_desc">Momentan: %s</string>
<!-- Preference: Default Add To Calendar Title -->
<string name="EPr_default_addtocalendar_title">Standard Kalendereintrag</string>
<string-array name="EPr_default_importance">
<!-- importance: labels for "Task Defaults" preference item. -->
<item>!!!! (Höchste)</item>

@ -241,6 +241,9 @@
<!-- default reminders setting (corresponds to reminder flags) -->
<string name="p_default_reminders_key">p_def_reminders</string>
<!-- default Add To Calendar setting (corresponds to entry in gcal_TEA_addToCalendar) -->
<string name="p_default_addtocalendar_key">p_def_addtocalendar</string>
<!-- ============================================================ SYNC == -->
<string-array name="sync_SPr_interval_values">

@ -393,9 +393,12 @@
<!-- Preference: Default Reminders Title -->
<string name="EPr_default_reminders_title">Default Reminders</string>
<!-- Preference: Default Hide Until Description (%s => setting) -->
<!-- Preference: Default Reminders Description (%s => setting) -->
<string name="EPr_default_reminders_desc">Currently: %s</string>
<!-- Preference: Default Add To Calendar Title -->
<string name="EPr_default_addtocalendar_title">Default Add To Calendar</string>
<string-array name="EPr_default_importance">
<!-- importance: labels for "Task Defaults" preference item. -->
<item>!!!! (Highest)</item>

@ -3,29 +3,32 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/EPr_defaults_header">
<ListPreference
android:key="@string/p_default_importance_key"
android:entries="@array/EPr_default_importance"
android:entryValues="@array/EPr_default_importance_values"
android:key="@string/p_default_importance_key"
android:entries="@array/EPr_default_importance"
android:entryValues="@array/EPr_default_importance_values"
android:title="@string/EPr_default_importance_title" />
<ListPreference
android:key="@string/p_default_urgency_key"
android:entries="@array/EPr_default_urgency"
android:entryValues="@array/EPr_default_urgency_values"
android:key="@string/p_default_urgency_key"
android:entries="@array/EPr_default_urgency"
android:entryValues="@array/EPr_default_urgency_values"
android:title="@string/EPr_default_urgency_title" />
<ListPreference
android:key="@string/p_default_hideUntil_key"
android:entries="@array/EPr_default_hideUntil"
android:entryValues="@array/EPr_default_hideUntil_values"
android:key="@string/p_default_hideUntil_key"
android:entries="@array/EPr_default_hideUntil"
android:entryValues="@array/EPr_default_hideUntil_values"
android:title="@string/EPr_default_hideUntil_title" />
<ListPreference
android:key="@string/p_default_reminders_key"
android:entries="@array/EPr_default_reminders"
android:entryValues="@array/EPr_default_reminders_values"
android:key="@string/p_default_reminders_key"
android:entries="@array/EPr_default_reminders"
android:entryValues="@array/EPr_default_reminders_values"
android:title="@string/EPr_default_reminders_title" />
<ListPreference
android:key="@string/p_rmd_default_random_hours"
android:title="@string/rmd_EPr_defaultRemind_title"
android:entries="@array/EPr_reminder_random"
android:entryValues="@array/EPr_reminder_random_hours"/>
</PreferenceScreen>
android:entryValues="@array/EPr_reminder_random_hours" />
<CheckBoxPreference
android:title="@string/EPr_default_addtocalendar_title"
android:key="@string/p_default_addtocalendar_key"
android:defaultValue="false"/>
</PreferenceScreen>

@ -24,6 +24,7 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalControlSet;
import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.opencrx.OpencrxCoreUtils;
import com.todoroo.astrid.producteev.ProducteevUtilities;
@ -150,12 +151,14 @@ public class TaskService {
if(!item.isSaved())
return;
else if(item.containsValue(Task.TITLE) && item.getValue(Task.TITLE).length() == 0) {
GCalControlSet.deleteTaskEvent(item);
taskDao.delete(item.getId());
item.setId(Task.NO_ID);
} else {
long id = item.getId();
item.clear();
item.setId(id);
GCalControlSet.deleteTaskEvent(item);
item.setValue(Task.DELETION_DATE, DateUtilities.now());
taskDao.save(item);
}

Loading…
Cancel
Save