From f96963c2a145b319163bb4a81f4129d8cc3cfb2c Mon Sep 17 00:00:00 2001 From: Tim Su Date: Wed, 4 Aug 2010 00:03:18 -0700 Subject: [PATCH] Continued making upgrade a more pleasant process - now the task list auto refreshes after update, etc. --- astrid/AndroidManifest.xml | 2 +- astrid/res/values/strings-core.xml | 3 +++ .../service/Astrid2To3UpgradeHelper.java | 15 +++++++----- .../astrid/service/StartupService.java | 2 +- .../astrid/service/UpgradeService.java | 24 ++++++++++++------- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 185cab729..361e7e7ec 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -1,7 +1,7 @@ diff --git a/astrid/res/values/strings-core.xml b/astrid/res/values/strings-core.xml index 8faca89a1..fc2a8c522 100644 --- a/astrid/res/values/strings-core.xml +++ b/astrid/res/values/strings-core.xml @@ -123,6 +123,9 @@ Please wait... + + Upgrading your tasks... + Time (hours : minutes) diff --git a/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java b/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java index 44af38380..14961af5d 100644 --- a/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java +++ b/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java @@ -31,6 +31,7 @@ import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DialogUtilities; +import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.alarms.Alarm; import com.todoroo.astrid.alarms.AlarmDatabase; import com.todoroo.astrid.backup.TasksXmlImporter; @@ -112,9 +113,9 @@ public class Astrid2To3UpgradeHelper { /** * Perform the upgrade from Astrid 2 to Astrid 3 + * @param context2 */ - public void upgrade2To3(final UpgradeService upgradeService, final int from) { - final Context context = ContextManager.getContext(); + public void upgrade2To3(final Context context, final UpgradeService upgradeService, final int from) { // if from < 1 (we don't know what version, and database exists, leave it alone) if(from < 1 && Arrays.asList(context.databaseList()).contains(database.getName())) @@ -123,11 +124,13 @@ public class Astrid2To3UpgradeHelper { // else, if there's already a database table, clear it out (!!!) if(Arrays.asList(context.databaseList()).contains(database.getName())) context.deleteDatabase(database.getName()); + database.openForWriting(); // pop up a progress dialog final ProgressDialog dialog; if(context instanceof Activity) - dialog = dialogUtilities.progressDialog(context, context.getString(R.string.DLG_wait)); + dialog = dialogUtilities.progressDialog(context, + context.getString(R.string.DLG_upgrading)); else dialog = null; @@ -136,7 +139,6 @@ public class Astrid2To3UpgradeHelper { public void run() { // initiate a backup String backupFile = legacyBackup(); - database.openForWriting(); try { @@ -201,13 +203,14 @@ public class Astrid2To3UpgradeHelper { TasksXmlImporter.importTasks(context, backupFile, null); } } finally { - database.close(); if(context instanceof Activity) { ((Activity)context).runOnUiThread(new Runnable() { public void run() { if(dialog != null) dialog.dismiss(); - upgradeService.showChangeLog(from); + upgradeService.showChangeLog(context, from); + if(context instanceof TaskListActivity) + ((TaskListActivity)context).loadTaskListContent(true); } }); } diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index be264d48d..a9f19c83a 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -90,7 +90,7 @@ public class StartupService { // invoke upgrade service boolean justUpgraded = latestSetVersion != version; if(justUpgraded && version > 0) { - upgradeService.performUpgrade(latestSetVersion); + upgradeService.performUpgrade(context, latestSetVersion); Preferences.setCurrentVersion(version); } diff --git a/astrid/src/com/todoroo/astrid/service/UpgradeService.java b/astrid/src/com/todoroo/astrid/service/UpgradeService.java index fb028cd6e..785022399 100644 --- a/astrid/src/com/todoroo/astrid/service/UpgradeService.java +++ b/astrid/src/com/todoroo/astrid/service/UpgradeService.java @@ -2,10 +2,10 @@ package com.todoroo.astrid.service; import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.webkit.WebView; import com.timsu.astrid.R; -import com.todoroo.andlib.service.ContextManager; public final class UpgradeService { @@ -18,15 +18,15 @@ public final class UpgradeService { * @param from * @param to */ - public void performUpgrade(int from) { + public void performUpgrade(Context context, int from) { if(from == 135) AddOnService.recordOem(); if(from < 136) { - new Astrid2To3UpgradeHelper().upgrade2To3(this, from); + new Astrid2To3UpgradeHelper().upgrade2To3(context, this, from); } else { // display changelog - showChangeLog(from); + showChangeLog(context, from); } } @@ -39,8 +39,8 @@ public final class UpgradeService { * @return */ @SuppressWarnings("nls") - public void showChangeLog(int from) { - if(!(ContextManager.getContext() instanceof Activity) || from == 0) + public void showChangeLog(Context context, int from) { + if(!(context instanceof Activity) || from == 0) return; StringBuilder changeLog = new StringBuilder(); @@ -52,7 +52,7 @@ public final class UpgradeService { "more powerful, while other improvements have made it faster " + "and easier to use. Hope you like it!", }); - if(from > 135 && from <= 140) + else if(from > 135 && from <= 140) newVersionString(changeLog, "3.0.2 (8/4/10)", new String[] { "Upgrade note: if you are missing old repeating tasks, " + "search for them, there was a bug where they were marked " + @@ -60,6 +60,12 @@ public final class UpgradeService { "This update also fixes widget issues with Android 1.5. ", "Thanks for your patience!", }); + else if(from > 140 && from <= 142) + newVersionString(changeLog, "3.0.4 (8/4/10)", new String[] { + "Making upgrade easier for new Astrid 3 users.", + "Fixed some user-reported crashes", + "We love you!!", + }); if(changeLog.length() == 0) return; @@ -67,11 +73,11 @@ public final class UpgradeService { changeLog.append(""); String changeLogHtml = "" + changeLog; - WebView webView = new WebView(ContextManager.getContext()); + WebView webView = new WebView(context); webView.loadData(changeLogHtml, "text/html", "utf-8"); webView.setBackgroundColor(0); - new AlertDialog.Builder(ContextManager.getContext()) + new AlertDialog.Builder(context) .setTitle(R.string.UpS_changelog_title) .setView(webView) .setIcon(android.R.drawable.ic_dialog_info)