mirror of https://github.com/tasks/tasks
Move old task dialogs into activities
parent
034b71ec92
commit
ddfa3c479d
@ -0,0 +1,44 @@
|
|||||||
|
package org.tasks.activities;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.utility.DialogUtilities;
|
||||||
|
import com.todoroo.astrid.dao.Database;
|
||||||
|
|
||||||
|
import org.tasks.R;
|
||||||
|
import org.tasks.injection.InjectingActivity;
|
||||||
|
import org.tasks.preferences.Preferences;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class ClearAllDataActivity extends InjectingActivity {
|
||||||
|
|
||||||
|
@Inject Database database;
|
||||||
|
@Inject Preferences preferences;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
DialogUtilities.okCancelDialog(
|
||||||
|
this,
|
||||||
|
getResources().getString(R.string.EPr_manage_clear_all_message),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
deleteDatabase(database.getName());
|
||||||
|
|
||||||
|
preferences.reset();
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
package org.tasks.activities;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.andlib.sql.Query;
|
||||||
|
import com.todoroo.andlib.utility.DialogUtilities;
|
||||||
|
import com.todoroo.astrid.data.Task;
|
||||||
|
import com.todoroo.astrid.gcal.GCalHelper;
|
||||||
|
import com.todoroo.astrid.service.TaskService;
|
||||||
|
|
||||||
|
import org.tasks.R;
|
||||||
|
import org.tasks.injection.InjectingActivity;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class DeleteAllCalendarEventsActivity extends InjectingActivity {
|
||||||
|
|
||||||
|
@Inject TaskService taskService;
|
||||||
|
@Inject GCalHelper gcalHelper;
|
||||||
|
|
||||||
|
private ProgressDialog pd;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
DialogUtilities.okCancelDialog(
|
||||||
|
this,
|
||||||
|
getResources().getString(
|
||||||
|
R.string.EPr_manage_delete_all_gcal_message),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
pd = DialogUtilities.runWithProgressDialog(DeleteAllCalendarEventsActivity.this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int deletedEventCount = 0;
|
||||||
|
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
|
||||||
|
Task.CALENDAR_URI.isNotNull()));
|
||||||
|
try {
|
||||||
|
int length = cursor.getCount();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
cursor.moveToNext();
|
||||||
|
Task task = new Task(cursor);
|
||||||
|
if (gcalHelper.deleteTaskEvent(task)) {
|
||||||
|
deletedEventCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
// mass update the CALENDAR_URI here,
|
||||||
|
// since the GCalHelper doesnt save it due to performance-reasons
|
||||||
|
Task template = new Task();
|
||||||
|
template.setCalendarUri(""); //$NON-NLS-1$
|
||||||
|
taskService.update(
|
||||||
|
Task.CALENDAR_URI.isNotNull(),
|
||||||
|
template);
|
||||||
|
showResult(R.string.EPr_manage_delete_all_gcal_status, deletedEventCount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
DialogUtilities.dismissDialog(this, pd);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showResult(int resourceText, int result) {
|
||||||
|
DialogUtilities.okDialog(this, getString(resourceText, result), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package org.tasks.activities;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
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.astrid.data.Task;
|
||||||
|
import com.todoroo.astrid.gcal.GCalHelper;
|
||||||
|
import com.todoroo.astrid.service.TaskService;
|
||||||
|
|
||||||
|
import org.tasks.R;
|
||||||
|
import org.tasks.injection.InjectingActivity;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class DeleteCompletedActivity extends InjectingActivity {
|
||||||
|
|
||||||
|
@Inject TaskService taskService;
|
||||||
|
@Inject GCalHelper gcalHelper;
|
||||||
|
|
||||||
|
private ProgressDialog pd;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
DialogUtilities.okCancelDialog(
|
||||||
|
this,
|
||||||
|
getResources().getString(
|
||||||
|
R.string.EPr_manage_delete_completed_message),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
pd = DialogUtilities.runWithProgressDialog(DeleteCompletedActivity.this, 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 {
|
||||||
|
int length = cursor.getCount();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
cursor.moveToNext();
|
||||||
|
Task task = new Task(cursor);
|
||||||
|
gcalHelper.deleteTaskEvent(task);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
Task template = new Task();
|
||||||
|
template.setDeletionDate(
|
||||||
|
DateUtilities.now());
|
||||||
|
int result = taskService.update(
|
||||||
|
Task.COMPLETION_DATE.gt(0), template);
|
||||||
|
showResult(
|
||||||
|
R.string.EPr_manage_delete_completed_status,
|
||||||
|
result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
DialogUtilities.dismissDialog(this, pd);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void showResult(int resourceText, int result) {
|
||||||
|
DialogUtilities.okDialog(this, getString(resourceText, result), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
package org.tasks.activities;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.andlib.sql.Criterion;
|
||||||
|
import com.todoroo.andlib.sql.Query;
|
||||||
|
import com.todoroo.andlib.utility.DialogUtilities;
|
||||||
|
import com.todoroo.astrid.data.Task;
|
||||||
|
import com.todoroo.astrid.gcal.GCalHelper;
|
||||||
|
import com.todoroo.astrid.service.TaskService;
|
||||||
|
|
||||||
|
import org.tasks.R;
|
||||||
|
import org.tasks.injection.InjectingActivity;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class DeleteCompletedEventsActivity extends InjectingActivity {
|
||||||
|
|
||||||
|
@Inject TaskService taskService;
|
||||||
|
@Inject GCalHelper gcalHelper;
|
||||||
|
|
||||||
|
private ProgressDialog pd;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
DialogUtilities.okCancelDialog(
|
||||||
|
this,
|
||||||
|
getResources().getString(
|
||||||
|
R.string.EPr_manage_delete_completed_gcal_message),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
pd = DialogUtilities.runWithProgressDialog(DeleteCompletedEventsActivity.this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int deletedEventCount = 0;
|
||||||
|
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 {
|
||||||
|
int length = cursor.getCount();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
cursor.moveToNext();
|
||||||
|
Task task = new Task(cursor);
|
||||||
|
if (gcalHelper.deleteTaskEvent(task)) {
|
||||||
|
deletedEventCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
// mass update the CALENDAR_URI here,
|
||||||
|
// since the GCalHelper doesnt save it due to performance-reasons
|
||||||
|
Task template = new Task();
|
||||||
|
template.setCalendarUri(""); //$NON-NLS-1$
|
||||||
|
taskService.update(
|
||||||
|
Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull()),
|
||||||
|
template);
|
||||||
|
showResult(R.string.EPr_manage_delete_completed_gcal_status, deletedEventCount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
DialogUtilities.dismissDialog(this, pd);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showResult(int resourceText, int result) {
|
||||||
|
DialogUtilities.okDialog(this, getString(resourceText, result), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
package org.tasks.activities;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.todoroo.andlib.data.TodorooCursor;
|
||||||
|
import com.todoroo.andlib.sql.Criterion;
|
||||||
|
import com.todoroo.andlib.sql.Query;
|
||||||
|
import com.todoroo.andlib.utility.DialogUtilities;
|
||||||
|
import com.todoroo.astrid.dao.MetadataDao;
|
||||||
|
import com.todoroo.astrid.data.Task;
|
||||||
|
import com.todoroo.astrid.gcal.GCalHelper;
|
||||||
|
import com.todoroo.astrid.service.TaskDeleter;
|
||||||
|
import com.todoroo.astrid.service.TaskService;
|
||||||
|
|
||||||
|
import org.tasks.R;
|
||||||
|
import org.tasks.injection.InjectingActivity;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class PurgeDeletedActivity extends InjectingActivity {
|
||||||
|
|
||||||
|
@Inject TaskService taskService;
|
||||||
|
@Inject TaskDeleter taskDeleter;
|
||||||
|
@Inject GCalHelper gcalHelper;
|
||||||
|
@Inject MetadataDao metadataDao;
|
||||||
|
|
||||||
|
private ProgressDialog pd;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
DialogUtilities.okCancelDialog(
|
||||||
|
this,
|
||||||
|
getResources().getString(
|
||||||
|
R.string.EPr_manage_purge_deleted_message),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
pd = DialogUtilities.runWithProgressDialog(PurgeDeletedActivity.this, 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 {
|
||||||
|
int length = cursor.getCount();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
cursor.moveToNext();
|
||||||
|
Task task = new Task(cursor);
|
||||||
|
gcalHelper.deleteTaskEvent(task);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
int result = taskDeleter.purgeDeletedTasks();
|
||||||
|
metadataDao.removeDanglingMetadata();
|
||||||
|
showResult(R.string.EPr_manage_purge_deleted_status, result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
DialogUtilities.dismissDialog(this, pd);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void showResult(int resourceText, int result) {
|
||||||
|
DialogUtilities.okDialog(this, getString(resourceText, result), new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,33 +1,51 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
** Copyright (c) 2012 Todoroo Inc
|
||||||
**
|
**
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
** See the file "LICENSE" for the full license governing this code.
|
||||||
-->
|
-->
|
||||||
<PreferenceScreen
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:title="@string/EPr_manage_header">
|
android:title="@string/EPr_manage_header">
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
<com.todoroo.astrid.ui.MultilinePreference
|
||||||
android:title="@string/EPr_manage_delete_completed"
|
|
||||||
android:key="@string/EPr_manage_delete_completed"
|
android:key="@string/EPr_manage_delete_completed"
|
||||||
android:summary="@string/EPr_manage_delete_completed_summary"/>
|
android:summary="@string/EPr_manage_delete_completed_summary"
|
||||||
|
android:title="@string/EPr_manage_delete_completed">
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.tasks.activities.DeleteCompletedActivity"
|
||||||
|
android:targetPackage="org.tasks" />
|
||||||
|
</com.todoroo.astrid.ui.MultilinePreference>
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
<com.todoroo.astrid.ui.MultilinePreference
|
||||||
android:title="@string/EPr_manage_purge_deleted"
|
|
||||||
android:key="@string/EPr_manage_purge_deleted"
|
android:key="@string/EPr_manage_purge_deleted"
|
||||||
android:summary="@string/EPr_manage_purge_deleted_summary"/>
|
android:summary="@string/EPr_manage_purge_deleted_summary"
|
||||||
|
android:title="@string/EPr_manage_purge_deleted">
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.tasks.activities.PurgeDeletedActivity"
|
||||||
|
android:targetPackage="org.tasks" />
|
||||||
|
</com.todoroo.astrid.ui.MultilinePreference>
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
<com.todoroo.astrid.ui.MultilinePreference
|
||||||
android:title="@string/EPr_manage_delete_completed_gcal"
|
android:key="@string/EPr_manage_delete_completed_gcal"
|
||||||
android:key="@string/EPr_manage_delete_completed_gcal"/>
|
android:title="@string/EPr_manage_delete_completed_gcal">
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.tasks.activities.DeleteCompletedEventsActivity"
|
||||||
|
android:targetPackage="org.tasks" />
|
||||||
|
</com.todoroo.astrid.ui.MultilinePreference>
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
<com.todoroo.astrid.ui.MultilinePreference
|
||||||
android:title="@string/EPr_manage_delete_all_gcal"
|
android:key="@string/EPr_manage_delete_all_gcal"
|
||||||
android:key="@string/EPr_manage_delete_all_gcal"/>
|
android:title="@string/EPr_manage_delete_all_gcal">
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.tasks.activities.DeleteAllCalendarEventsActivity"
|
||||||
|
android:targetPackage="org.tasks" />
|
||||||
|
</com.todoroo.astrid.ui.MultilinePreference>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:title="@string/EPr_manage_clear_all"
|
android:key="@string/EPr_manage_clear_all"
|
||||||
android:key="@string/EPr_manage_clear_all" />
|
android:title="@string/EPr_manage_clear_all">
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.tasks.activities.ClearAllDataActivity"
|
||||||
|
android:targetPackage="org.tasks" />
|
||||||
|
</Preference>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
Loading…
Reference in New Issue