mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Added util method to extract username from saved Account
This commit is contained in:
parent
740f0deb82
commit
19e30a6236
@ -53,7 +53,7 @@ public class OwnCloudClientFactory {
|
|||||||
/** Default timeout for establishing a connection */
|
/** Default timeout for establishing a connection */
|
||||||
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
|
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a OwnCloudClient setup for an ownCloud account
|
* Creates a OwnCloudClient setup for an ownCloud account
|
||||||
*
|
*
|
||||||
@ -83,7 +83,7 @@ public class OwnCloudClientFactory {
|
|||||||
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||||
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
||||||
|
|
||||||
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
String username = AccountUtils.getUsernameForAccount(account);
|
||||||
if (isOauth2) {
|
if (isOauth2) {
|
||||||
String accessToken = am.blockingGetAuthToken(
|
String accessToken = am.blockingGetAuthToken(
|
||||||
account,
|
account,
|
||||||
@ -137,7 +137,7 @@ public class OwnCloudClientFactory {
|
|||||||
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||||
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
|
||||||
|
|
||||||
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
String username = AccountUtils.getUsernameForAccount(account);
|
||||||
if (isOauth2) { // TODO avoid a call to getUserData here
|
if (isOauth2) { // TODO avoid a call to getUserData here
|
||||||
AccountManagerFuture<Bundle> future = am.getAuthToken(
|
AccountManagerFuture<Bundle> future = am.getAuthToken(
|
||||||
account,
|
account,
|
||||||
|
@ -145,7 +145,23 @@ public class AccountUtils {
|
|||||||
|
|
||||||
return baseurl;
|
return baseurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the username corresponding to an OC account.
|
||||||
|
*
|
||||||
|
* @param account An OC account
|
||||||
|
* @return Username for the given account, extracted from the account.name
|
||||||
|
*/
|
||||||
|
public static String getUsernameForAccount(Account account) {
|
||||||
|
String username = null;
|
||||||
|
try {
|
||||||
|
username = account.name.substring(0, account.name.lastIndexOf('@'));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log_OC.e(TAG, "Couldn't get a username for the given account", e);
|
||||||
|
}
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -168,7 +184,7 @@ public class AccountUtils {
|
|||||||
account,
|
account,
|
||||||
AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||||
|
|
||||||
String username = account.name.substring(0, account.name.lastIndexOf('@'));
|
String username = AccountUtils.getUsernameForAccount(account);
|
||||||
|
|
||||||
if (isOauth2) {
|
if (isOauth2) {
|
||||||
String accessToken = am.blockingGetAuthToken(
|
String accessToken = am.blockingGetAuthToken(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user