forked from upstream-mirrors/OpenTracks
Making the target account be selected only once.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.accounts.Account;
|
||||
import com.google.android.apps.mytracks.io.AuthManager;
|
||||
import com.google.android.apps.mytracks.io.AuthManagerFactory;
|
||||
@@ -25,6 +27,7 @@ import com.google.android.maps.mytracks.R;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
@@ -40,6 +43,9 @@ import android.widget.TextView;
|
||||
public class MyMapsList extends Activity implements MapsFacade.MapsListCallback {
|
||||
private static final int GET_LOGIN = 1;
|
||||
|
||||
public static final String EXTRA_ACCOUNT_NAME = "accountName";
|
||||
public static final String EXTRA_ACCOUNT_TYPE = "accountType";
|
||||
|
||||
private MapsFacade mapsClient;
|
||||
private AuthManager auth;
|
||||
private MyMapsListAdapter listAdapter;
|
||||
@@ -79,22 +85,18 @@ public class MyMapsList extends Activity implements MapsFacade.MapsListCallback
|
||||
// Starts in the UI thread.
|
||||
// TODO fix this for non-froyo devices.
|
||||
if (AuthManagerFactory.useModernAuthManager()) {
|
||||
AccountChooser accountChooser = new AccountChooser();
|
||||
accountChooser.chooseAccount(
|
||||
MyMapsList.this,
|
||||
new AccountChooser.AccountHandler() {
|
||||
@Override
|
||||
public void onAccountSelected(Account account) {
|
||||
// Account selection happens in the UI thread.
|
||||
if (account != null) {
|
||||
// The user did not quit and there was a valid google
|
||||
// account.
|
||||
doLogin(account);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
Intent intent = getIntent();
|
||||
String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME);
|
||||
String accountType = intent.getStringExtra(EXTRA_ACCOUNT_TYPE);
|
||||
if (accountName == null || accountType == null) {
|
||||
Log.e(TAG, "Didn't receive account name or type");
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Account account = new Account(accountName, accountType);
|
||||
doLogin(account);
|
||||
} else {
|
||||
doLogin(null);
|
||||
}
|
||||
|
||||
@@ -107,6 +107,8 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
||||
private final HashMap<String, AuthManager> authMap =
|
||||
new HashMap<String, AuthManager>();
|
||||
private final AccountChooser accountChooser = new AccountChooser();
|
||||
private String lastAccountName;
|
||||
private String lastAccountType;
|
||||
|
||||
// Send request information.
|
||||
private boolean shareRequested = false;
|
||||
@@ -225,6 +227,9 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
||||
|
||||
sendToMyMapsMapId = savedInstanceState.getString("mapId");
|
||||
sendToFusionTablesTableId = savedInstanceState.getString("tableId");
|
||||
|
||||
lastAccountName = savedInstanceState.getString("accountName");
|
||||
lastAccountType = savedInstanceState.getString("accountType");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -244,6 +249,9 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
||||
outState.putString("mapId", sendToMyMapsMapId);
|
||||
outState.putString("tableId", sendToFusionTablesTableId);
|
||||
|
||||
outState.putString("accountName", lastAccountName);
|
||||
outState.putString("accountType", lastAccountType);
|
||||
|
||||
// TODO: Ideally we should serialize/restore the authenticator map and lastAuth somehow,
|
||||
// but it's highly unlikely we'll get killed while an auth dialog is displayed.
|
||||
}
|
||||
@@ -370,6 +378,8 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
||||
if (!sendDialog.getCreateNewMap()) {
|
||||
// Ask the user to choose a map to upload into
|
||||
Intent listIntent = new Intent(this, MyMapsList.class);
|
||||
listIntent.putExtra(MyMapsList.EXTRA_ACCOUNT_NAME, lastAccountName);
|
||||
listIntent.putExtra(MyMapsList.EXTRA_ACCOUNT_TYPE, lastAccountType);
|
||||
startActivityForResult(listIntent, Constants.GET_MAP);
|
||||
// The callback for GET_MAP calls authenticateToGoogleMaps
|
||||
return SendState.NOT_READY;
|
||||
@@ -738,12 +748,14 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
||||
return;
|
||||
}
|
||||
|
||||
lastAccountName = account.name;
|
||||
lastAccountType = account.type;
|
||||
doLogin(requestCode, service, account);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doLogin(final int requestCode, final String service, final Account account) {
|
||||
private void doLogin(final int requestCode, final String service, final Object account) {
|
||||
// There's a chance that we go to a different activity, so close the dialog.
|
||||
lastAuth.doLogin(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
Reference in New Issue
Block a user