Loading build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.android.tools.build:gradle:2.1.2' } } Loading src/com/owncloud/android/lib/common/OwnCloudAccount.java +46 −49 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.content.Context; Loading @@ -47,6 +48,8 @@ public class OwnCloudAccount { private OwnCloudCredentials mCredentials; private String mDisplayName; private String mSavedAccountName; private Account mSavedAccount; Loading @@ -68,52 +71,17 @@ public class OwnCloudAccount { mSavedAccount = savedAccount; mSavedAccountName = savedAccount.name; mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount)); mCredentials = null; } /** * Method for deferred load of account attributes from AccountManager * * @param context * @throws AccountNotFoundException * @throws AuthenticatorException * @throws IOException * @throws OperationCanceledException */ public void loadCredentials(Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } mCredentials = null; // load of credentials is delayed if (mSavedAccount != null) { mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount); } } /* public OwnCloudAccount(Account savedAccount, Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException { if (savedAccount == null) { throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null"); AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseUrl = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_OC_BASE_URL); if (baseUrl == null ) { throw new AccountNotFoundException(mSavedAccount, "Account not found", null); } if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount)); mDisplayName = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME); } mSavedAccountName = savedAccount.name; mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount)); mCredentials = AccountUtils.getCredentialsForAccount(context, savedAccount); if (mCredentials == null) { mCredentials = OwnCloudCredentialsFactory.getAnonymousCredentials(); } } */ /** * Constructor for non yet saved OC accounts. Loading @@ -137,9 +105,27 @@ public class OwnCloudAccount { } public boolean isAnonymous() { return (mCredentials == null); } // TODO no more /** * Method for deferred load of account attributes from AccountManager * * @param context * @throws AccountNotFoundException * @throws AuthenticatorException * @throws IOException * @throws OperationCanceledException */ public void loadCredentials(Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } if (mSavedAccount != null) { mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount); } } public Uri getBaseUri() { return mBaseUri; Loading @@ -153,5 +139,16 @@ public class OwnCloudAccount { return mSavedAccountName; } public String getDisplayName() { if (mDisplayName != null && mDisplayName.length() > 0) { return mDisplayName; } else if (mCredentials != null) { return mCredentials.getUsername(); } else if (mSavedAccount != null) { return AccountUtils.getUsernameForAccount(mSavedAccount); } else { return null; } } } No newline at end of file src/com/owncloud/android/lib/common/accounts/AccountUtils.java +6 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,12 @@ public class AccountUtils { * OC account version */ public static final String KEY_OC_ACCOUNT_VERSION = "oc_account_version"; /** * User's display name */ public static final String KEY_DISPLAY_NAME = "oc_display_name"; } } src/com/owncloud/android/lib/resources/users/GetRemoteUserNameOperation.java→src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java +129 −0 Original line number Diff line number Diff line Loading @@ -37,17 +37,15 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** * @author masensio * Gets information (id, display name, and e-mail address) about the user logged in. * * Get the UserName for a SAML connection, from a JSON with the format: * id * display-name * email * @author masensio * @author David A. Velasco */ public class GetRemoteUserNameOperation extends RemoteOperation { public class GetRemoteUserInfoOperation extends RemoteOperation { private static final String TAG = GetRemoteUserNameOperation.class.getSimpleName(); private static final String TAG = GetRemoteUserInfoOperation.class.getSimpleName(); // OCS Route private static final String OCS_ROUTE = "/index.php/ocs/cloud/user?format=json"; Loading @@ -59,14 +57,7 @@ public class GetRemoteUserNameOperation extends RemoteOperation { private static final String NODE_DISPLAY_NAME = "display-name"; private static final String NODE_EMAIL = "email"; private String mUserName; public String getUserName() { return mUserName; } public GetRemoteUserNameOperation() { public GetRemoteUserInfoOperation() { } @Override Loading @@ -88,19 +79,18 @@ public class GetRemoteUserNameOperation extends RemoteOperation { JSONObject respJSON = new JSONObject(response); JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); JSONObject respData = respOCS.getJSONObject(NODE_DATA); String id = respData.getString(NODE_ID); String displayName = respData.getString(NODE_DISPLAY_NAME); String email = respData.getString(NODE_EMAIL); UserInfo userInfo = new UserInfo(); userInfo.mId = respData.getString(NODE_ID); userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME); userInfo.mEmail = respData.getString(NODE_EMAIL); // Result result = new RemoteOperationResult(true, status, get.getResponseHeaders()); // Username in result.data ArrayList<Object> data = new ArrayList<Object>(); data.add(displayName); data.add(userInfo); result.setData(data); mUserName = displayName; Log_OC.d(TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email); } else { result = new RemoteOperationResult(false, status, get.getResponseHeaders()); Loading @@ -117,8 +107,10 @@ public class GetRemoteUserNameOperation extends RemoteOperation { Log_OC.e(TAG, "Exception while getting OC user information", e); } finally { if (get != null) { get.releaseConnection(); } } return result; } Loading @@ -127,4 +119,11 @@ public class GetRemoteUserNameOperation extends RemoteOperation { return (status == HttpStatus.SC_OK); } public static class UserInfo { public String mId = ""; public String mDisplayName = ""; public String mEmail = ""; } } Loading
build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.android.tools.build:gradle:2.1.2' } } Loading
src/com/owncloud/android/lib/common/OwnCloudAccount.java +46 −49 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.content.Context; Loading @@ -47,6 +48,8 @@ public class OwnCloudAccount { private OwnCloudCredentials mCredentials; private String mDisplayName; private String mSavedAccountName; private Account mSavedAccount; Loading @@ -68,52 +71,17 @@ public class OwnCloudAccount { mSavedAccount = savedAccount; mSavedAccountName = savedAccount.name; mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount)); mCredentials = null; } /** * Method for deferred load of account attributes from AccountManager * * @param context * @throws AccountNotFoundException * @throws AuthenticatorException * @throws IOException * @throws OperationCanceledException */ public void loadCredentials(Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } mCredentials = null; // load of credentials is delayed if (mSavedAccount != null) { mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount); } } /* public OwnCloudAccount(Account savedAccount, Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException { if (savedAccount == null) { throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null"); AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseUrl = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_OC_BASE_URL); if (baseUrl == null ) { throw new AccountNotFoundException(mSavedAccount, "Account not found", null); } if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount)); mDisplayName = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME); } mSavedAccountName = savedAccount.name; mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, savedAccount)); mCredentials = AccountUtils.getCredentialsForAccount(context, savedAccount); if (mCredentials == null) { mCredentials = OwnCloudCredentialsFactory.getAnonymousCredentials(); } } */ /** * Constructor for non yet saved OC accounts. Loading @@ -137,9 +105,27 @@ public class OwnCloudAccount { } public boolean isAnonymous() { return (mCredentials == null); } // TODO no more /** * Method for deferred load of account attributes from AccountManager * * @param context * @throws AccountNotFoundException * @throws AuthenticatorException * @throws IOException * @throws OperationCanceledException */ public void loadCredentials(Context context) throws AccountNotFoundException, AuthenticatorException, IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } if (mSavedAccount != null) { mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount); } } public Uri getBaseUri() { return mBaseUri; Loading @@ -153,5 +139,16 @@ public class OwnCloudAccount { return mSavedAccountName; } public String getDisplayName() { if (mDisplayName != null && mDisplayName.length() > 0) { return mDisplayName; } else if (mCredentials != null) { return mCredentials.getUsername(); } else if (mSavedAccount != null) { return AccountUtils.getUsernameForAccount(mSavedAccount); } else { return null; } } } No newline at end of file
src/com/owncloud/android/lib/common/accounts/AccountUtils.java +6 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,12 @@ public class AccountUtils { * OC account version */ public static final String KEY_OC_ACCOUNT_VERSION = "oc_account_version"; /** * User's display name */ public static final String KEY_DISPLAY_NAME = "oc_display_name"; } }
src/com/owncloud/android/lib/resources/users/GetRemoteUserNameOperation.java→src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java +129 −0 Original line number Diff line number Diff line Loading @@ -37,17 +37,15 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** * @author masensio * Gets information (id, display name, and e-mail address) about the user logged in. * * Get the UserName for a SAML connection, from a JSON with the format: * id * display-name * email * @author masensio * @author David A. Velasco */ public class GetRemoteUserNameOperation extends RemoteOperation { public class GetRemoteUserInfoOperation extends RemoteOperation { private static final String TAG = GetRemoteUserNameOperation.class.getSimpleName(); private static final String TAG = GetRemoteUserInfoOperation.class.getSimpleName(); // OCS Route private static final String OCS_ROUTE = "/index.php/ocs/cloud/user?format=json"; Loading @@ -59,14 +57,7 @@ public class GetRemoteUserNameOperation extends RemoteOperation { private static final String NODE_DISPLAY_NAME = "display-name"; private static final String NODE_EMAIL = "email"; private String mUserName; public String getUserName() { return mUserName; } public GetRemoteUserNameOperation() { public GetRemoteUserInfoOperation() { } @Override Loading @@ -88,19 +79,18 @@ public class GetRemoteUserNameOperation extends RemoteOperation { JSONObject respJSON = new JSONObject(response); JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); JSONObject respData = respOCS.getJSONObject(NODE_DATA); String id = respData.getString(NODE_ID); String displayName = respData.getString(NODE_DISPLAY_NAME); String email = respData.getString(NODE_EMAIL); UserInfo userInfo = new UserInfo(); userInfo.mId = respData.getString(NODE_ID); userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME); userInfo.mEmail = respData.getString(NODE_EMAIL); // Result result = new RemoteOperationResult(true, status, get.getResponseHeaders()); // Username in result.data ArrayList<Object> data = new ArrayList<Object>(); data.add(displayName); data.add(userInfo); result.setData(data); mUserName = displayName; Log_OC.d(TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email); } else { result = new RemoteOperationResult(false, status, get.getResponseHeaders()); Loading @@ -117,8 +107,10 @@ public class GetRemoteUserNameOperation extends RemoteOperation { Log_OC.e(TAG, "Exception while getting OC user information", e); } finally { if (get != null) { get.releaseConnection(); } } return result; } Loading @@ -127,4 +119,11 @@ public class GetRemoteUserNameOperation extends RemoteOperation { return (status == HttpStatus.SC_OK); } public static class UserInfo { public String mId = ""; public String mDisplayName = ""; public String mEmail = ""; } }