Login to astrid.com won't block the ui thread anymore

pull/14/head
Sam Bosley 13 years ago
parent d1ec1b0954
commit 7d77af5bf9

@ -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 {

@ -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

@ -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);

Loading…
Cancel
Save