diff --git a/astrid/res/values/strings-core.xml b/astrid/res/values/strings-core.xml index db64f3a22..d0bbc9c67 100644 --- a/astrid/res/values/strings-core.xml +++ b/astrid/res/values/strings-core.xml @@ -312,6 +312,9 @@ What\'s New In Astrid? + + Latest Astrid News + diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index b3719fc71..2844521ca 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -136,7 +136,7 @@ public class StartupService { BackupService.scheduleService(context); // get and display update messages - new UpdateMessageService().processUpdates(); + new UpdateMessageService().processUpdates(context); } }).start(); diff --git a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java index c89b957d7..749dbfb2f 100644 --- a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java +++ b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java @@ -36,7 +36,7 @@ import com.todoroo.astrid.utility.Constants; @SuppressWarnings("nls") public class UpdateMessageService { - private static final String URL = "http://localhost/update.php"; + private static final String URL = "http://www.weloveastrid.com/updates.php"; private static final String PLUGIN_PDV = "pdv"; private static final String PLUGIN_GTASKS = "gtasks"; @@ -46,11 +46,15 @@ public class UpdateMessageService { @Autowired private GtasksPreferenceService gtasksPreferenceService; @Autowired private AddOnService addOnService; + private Context context; + public UpdateMessageService() { DependencyInjectionService.getInstance().inject(this); } - public void processUpdates() { + public void processUpdates(Context thisContext) { + context = thisContext; + if(shouldSkipUpdates()) return; @@ -59,9 +63,6 @@ public class UpdateMessageService { if(updates == null || updates.length() == 0) return; - if(updatesHaveNotChanged(updates)) - return; - StringBuilder builder = buildUpdateMessage(updates); if(builder.length() == 0) return; @@ -70,29 +71,33 @@ public class UpdateMessageService { } protected boolean shouldSkipUpdates() { - Context context = ContextManager.getContext(); return !(context instanceof Activity); } - private boolean updatesHaveNotChanged(JSONArray updates) { + private boolean updatesHaveNotChanged(String latest) { String savedUpdates = AstridPreferences.getLatestUpdates(); - String latest = updates.toString(); if(AndroidUtilities.equals(savedUpdates, latest)) return true; AstridPreferences.setLatestUpdates(latest); return false; } - protected void displayUpdateDialog(final StringBuilder builder) { - final Activity activity = (Activity) ContextManager.getContext(); + protected void displayUpdateDialog(StringBuilder builder) { + final Activity activity = (Activity) context; if(activity == null) return; + final String html = "" + + builder.append("").toString(); + + if(updatesHaveNotChanged(html)) + return; + activity.runOnUiThread(new Runnable() { @Override public void run() { DialogUtilities.htmlDialog(activity, - builder.toString(), R.string.UpS_changelog_title); + html, R.string.UpS_updates_title); } }); } diff --git a/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java b/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java index 70f571e03..2a476b167 100644 --- a/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java +++ b/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java @@ -28,7 +28,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { assertTrue(url.contains("version=")); return ""; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testIOException() { @@ -45,7 +45,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { throw new IOException("yayaya"); } - }.processUpdates(); + }.processUpdates(getContext()); } public void testNewUpdate() { @@ -62,7 +62,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'yo'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testMultipleUpdates() { @@ -80,7 +80,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'yo'},{message:'cat'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testExistingUpdate() { @@ -97,7 +97,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'yo'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); new TestUpdateMessageService() { @@ -115,7 +115,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'yo'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testUpdateWithDate() { @@ -133,7 +133,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'yo',date:'date'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testUpdateWithInternalPluginOn() { @@ -151,7 +151,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'rmilk man',plugin:'rmilk'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testUpdateWithInternalPluginOff() { @@ -174,7 +174,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'rmilk man',plugin:'rmilk'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testUpdateWithExternalPluginOn() { @@ -191,7 +191,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'astrid man',plugin:'" + Constants.PACKAGE + "'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } public void testUpdateWithExternalPluginOff() { @@ -213,7 +213,7 @@ public class UpdateMessageServiceTest extends TodorooTestCase { String getUpdates(String url) throws IOException { return "[{message:'astrid man',plugin:'com.bogus.package'}]"; } - }.processUpdates(); + }.processUpdates(getContext()); } // ---