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