diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java index d48c34421..56146ec33 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java @@ -355,26 +355,43 @@ public class ActFmLoginActivity extends Activity implements AuthListener { // --- utilities @SuppressWarnings("nls") - public void authenticate(String email, String name, String provider, - String secret) { + public void authenticate(final String email, final String name, final String provider, + final String secret) { if (progressDialog == null) progressDialog = DialogUtilities.progressDialog(this, getString(R.string.DLG_please_wait)); - try { - JSONObject result = actFmInvoker.authenticate(email, name, - provider, secret); - String token = actFmInvoker.getToken(); - - if (result.optBoolean("new")) { // Report new user statistic - StatisticsService.reportEvent(StatisticsConstants.ACTFM_NEW_USER, "provider", provider); + new Thread() { + @Override + public void run() { + try { + final JSONObject result = actFmInvoker.authenticate(email, name, + provider, secret); + final String token = actFmInvoker.getToken(); + + if (result.optBoolean("new")) { // Report new user statistic + StatisticsService.reportEvent(StatisticsConstants.ACTFM_NEW_USER, "provider", provider); + } + runOnUiThread(new Runnable() { + public void run() { + DialogUtilities.dismissDialog(ActFmLoginActivity.this, progressDialog); + progressDialog = null; + postAuthenticate(result, token); + } + }); + } catch (IOException e) { + handleError(e); + } finally { + runOnUiThread(new Runnable() { + public void run() { + if (progressDialog != null) { + DialogUtilities.dismissDialog(ActFmLoginActivity.this, progressDialog); + } + } + }); + } } - postAuthenticate(result, token); - } catch (IOException e) { - handleError(e); - } finally { - DialogUtilities.dismissDialog(this, progressDialog); - } + }.start(); } @SuppressWarnings("nls") @@ -394,7 +411,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener { finishAndShowNext(); if (!noSync) { - new ActFmSyncProvider().synchronize(this); + new ActFmSyncProvider().synchronize(ActFmLoginActivity.this); } try { diff --git a/astrid/src/com/todoroo/astrid/welcome/WelcomeGraphic.java b/astrid/src/com/todoroo/astrid/welcome/WelcomeGraphic.java index 076687dd7..a5cffa569 100644 --- a/astrid/src/com/todoroo/astrid/welcome/WelcomeGraphic.java +++ b/astrid/src/com/todoroo/astrid/welcome/WelcomeGraphic.java @@ -13,6 +13,7 @@ import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.utility.AndroidUtilities; +import com.todoroo.astrid.actfm.sync.ActFmSyncProvider; import com.todoroo.astrid.activity.Eula; import com.todoroo.astrid.activity.FilterListActivity; import com.todoroo.astrid.activity.TaskListActivity; @@ -25,6 +26,8 @@ public class WelcomeGraphic extends Activity { public static final String KEY_SHOW_EULA = "show_eula"; //$NON-NLS-1$ + public static final String START_SYNC = "start_sync"; //$NON-NLS-1$ + @Autowired ABChooser abChooser; @Override @@ -40,6 +43,7 @@ public class WelcomeGraphic extends Activity { if (getIntent().getBooleanExtra(KEY_SHOW_EULA, false)) Eula.showEula(this); + final ImageView image = (ImageView)findViewById(R.id.welcome_image); image.setOnClickListener(new OnClickListener() { @Override @@ -59,6 +63,9 @@ public class WelcomeGraphic extends Activity { }.start(); } }); + + if (getIntent().getBooleanExtra(START_SYNC, false)) + new ActFmSyncProvider().synchronize(this); } @Override diff --git a/astrid/src/com/todoroo/astrid/welcome/WelcomeLogin.java b/astrid/src/com/todoroo/astrid/welcome/WelcomeLogin.java index 2f94f1f90..dad736b54 100644 --- a/astrid/src/com/todoroo/astrid/welcome/WelcomeLogin.java +++ b/astrid/src/com/todoroo/astrid/welcome/WelcomeLogin.java @@ -61,6 +61,8 @@ public class WelcomeLogin extends ActFmLoginActivity implements AuthListener { @Override protected void finishAndShowNext() { Intent welcomeScreen = new Intent(this, WelcomeGraphic.class); + welcomeScreen.putExtra(WelcomeGraphic.START_SYNC, true); + noSync = true; // For superclass startActivity(welcomeScreen); finish(); Preferences.setBoolean(KEY_SHOWED_WELCOME_LOGIN, true);