Suppress EULA and startup tasks if you already have created tasks, in case preferences get overwritten (Galaxy S issue)

pull/14/head
Tim Su 14 years ago
parent 5f84f0c85b
commit 0bb5bef617

@ -21,7 +21,11 @@ import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import com.timsu.astrid.R; 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.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 * 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 PREFERENCE_EULA_ACCEPTED = "eula.accepted"; //$NON-NLS-1$
private static final String PREFERENCES_EULA = "eula"; //$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 * Displays the EULA if necessary. This method should be called from the
* onCreate() method of your main Activity. * onCreate() method of your main Activity.
@ -45,9 +51,8 @@ class Eula {
static void showEula(final Activity activity) { static void showEula(final Activity activity) {
final SharedPreferences preferences = activity.getSharedPreferences( final SharedPreferences preferences = activity.getSharedPreferences(
PREFERENCES_EULA, Activity.MODE_PRIVATE); PREFERENCES_EULA, Activity.MODE_PRIVATE);
if (preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) { if(!new Eula().shouldShowEula(preferences))
return; return;
}
final AlertDialog.Builder builder = new AlertDialog.Builder(activity); final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.DLG_eula_title); builder.setTitle(R.string.DLG_eula_title);
@ -76,6 +81,14 @@ class Eula {
builder.show(); 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") @SuppressWarnings("unused")
private static void accept(Activity activity, SharedPreferences preferences) { private static void accept(Activity activity, SharedPreferences preferences) {
preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true).commit(); preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true).commit();
@ -87,5 +100,6 @@ class Eula {
private Eula() { private Eula() {
// don't construct me // don't construct me
DependencyInjectionService.getInstance().inject(this);
} }
} }

@ -186,6 +186,11 @@ public class StartupService {
try { try {
database.openForWriting(); 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_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_2_summary, R.string.intro_task_2_note);
addIntroTask(r, R.string.intro_task_3_summary, R.string.intro_task_3_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) { private void addIntroTask(Resources r, int summary, int note) {
Task task = new Task(); Task task = new Task();
task.setValue(Task.TITLE, r.getString(summary)); task.setValue(Task.TITLE, r.getString(summary));

@ -123,7 +123,7 @@ public class TaskService {
metadata.setValue(MilkTaskFields.TASK_ID, 0L); metadata.setValue(MilkTaskFields.TASK_ID, 0L);
metadata.setValue(MilkTaskFields.TASK_SERIES_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(OpencrxCoreUtils.ACTIVITY_ID, 0L);
metadata.setValue(Metadata.TASK, newId); metadata.setValue(Metadata.TASK, newId);

Loading…
Cancel
Save