got the updates stuff to work with the actual Astrid app.

pull/14/head
Tim Su 14 years ago
parent aee861c390
commit 335597866d

@ -312,6 +312,9 @@
<!-- Changelog Window Title -->
<string name="UpS_changelog_title">What\'s New In Astrid?</string>
<!-- Updates Window Title -->
<string name="UpS_updates_title">Latest Astrid News</string>
<!-- ================================================== EditPreferences == -->
<!-- Preference Window Title -->

@ -136,7 +136,7 @@ public class StartupService {
BackupService.scheduleService(context);
// get and display update messages
new UpdateMessageService().processUpdates();
new UpdateMessageService().processUpdates(context);
}
}).start();

@ -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 = "<html><body style='color: white'>" +
builder.append("</body></html>").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);
}
});
}

@ -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());
}
// ---

Loading…
Cancel
Save