From 0bb5bef617c41042862c9f9cf187c34c7b714dd5 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Mon, 16 May 2011 17:21:09 -0700 Subject: [PATCH] Suppress EULA and startup tasks if you already have created tasks, in case preferences get overwritten (Galaxy S issue) --- .../src/com/todoroo/astrid/activity/Eula.java | 18 ++++++++++++++++-- .../todoroo/astrid/service/StartupService.java | 7 +++++++ .../todoroo/astrid/service/TaskService.java | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/activity/Eula.java b/astrid/src/com/todoroo/astrid/activity/Eula.java index be9886b7b..73f3c81a9 100644 --- a/astrid/src/com/todoroo/astrid/activity/Eula.java +++ b/astrid/src/com/todoroo/astrid/activity/Eula.java @@ -21,7 +21,11 @@ import android.content.DialogInterface; import android.content.SharedPreferences; import com.timsu.astrid.R; +import com.todoroo.andlib.service.Autowired; +import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.utility.AndroidUtilities; +import com.todoroo.astrid.service.StartupService; +import com.todoroo.astrid.service.TaskService; /** * Displays an EULA ("End User License Agreement") that the user has to accept @@ -35,6 +39,8 @@ class Eula { private static final String PREFERENCE_EULA_ACCEPTED = "eula.accepted"; //$NON-NLS-1$ private static final String PREFERENCES_EULA = "eula"; //$NON-NLS-1$ + @Autowired TaskService taskService; + /** * Displays the EULA if necessary. This method should be called from the * onCreate() method of your main Activity. @@ -45,9 +51,8 @@ class Eula { static void showEula(final Activity activity) { final SharedPreferences preferences = activity.getSharedPreferences( PREFERENCES_EULA, Activity.MODE_PRIVATE); - if (preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) { + if(!new Eula().shouldShowEula(preferences)) return; - } final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.DLG_eula_title); @@ -76,6 +81,14 @@ class Eula { builder.show(); } + private boolean shouldShowEula(SharedPreferences preferences) { + if(preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) + return false; + if(taskService.countTasks() > StartupService.INTRO_TASK_SIZE) + return false; + return true; + } + @SuppressWarnings("unused") private static void accept(Activity activity, SharedPreferences preferences) { preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true).commit(); @@ -87,5 +100,6 @@ class Eula { private Eula() { // don't construct me + DependencyInjectionService.getInstance().inject(this); } } diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index 28225760c..d5cdfb751 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -186,6 +186,11 @@ public class StartupService { try { database.openForWriting(); + + if(taskService.countTasks() > 0) + return; + + // change count below as well addIntroTask(r, R.string.intro_task_1_summary, R.string.intro_task_1_note); addIntroTask(r, R.string.intro_task_2_summary, R.string.intro_task_2_note); addIntroTask(r, R.string.intro_task_3_summary, R.string.intro_task_3_note); @@ -194,6 +199,8 @@ public class StartupService { } } + public static final int INTRO_TASK_SIZE = 3; + private void addIntroTask(Resources r, int summary, int note) { Task task = new Task(); task.setValue(Task.TITLE, r.getString(summary)); diff --git a/astrid/src/com/todoroo/astrid/service/TaskService.java b/astrid/src/com/todoroo/astrid/service/TaskService.java index 0cc08dc51..b9f63ba67 100644 --- a/astrid/src/com/todoroo/astrid/service/TaskService.java +++ b/astrid/src/com/todoroo/astrid/service/TaskService.java @@ -123,7 +123,7 @@ public class TaskService { metadata.setValue(MilkTaskFields.TASK_ID, 0L); metadata.setValue(MilkTaskFields.TASK_SERIES_ID, 0L); } - if(OpencrxCoreUtils.OPENCRX_ACTIVITY_METADATA_KEY.equals(metadata.getValue(Metadata.KEY))) { + if(OpencrxCoreUtils.OPENCRX_ACTIVITY_METADATA_KEY.equals(metadata.getValue(Metadata.KEY))) metadata.setValue(OpencrxCoreUtils.ACTIVITY_ID, 0L); metadata.setValue(Metadata.TASK, newId);