-/* ownCloud Android client application\r
+/**\r
+ * ownCloud Android client application\r
+ *\r
+ * @author Bartek Przybylski\r
+ * @author David A. Velasco\r
+ * @author masensio\r
* Copyright (C) 2012 Bartek Przybylski\r
- * Copyright (C) 2012-2015 ownCloud Inc.\r
+ * Copyright (C) 2015 ownCloud Inc.\r
*\r
* This program is free software: you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License version 2,\r
import android.os.Handler;\r
import android.os.IBinder;\r
import android.preference.PreferenceManager;\r
+import android.support.v4.app.DialogFragment;\r
import android.support.v4.app.Fragment;\r
import android.support.v4.app.FragmentManager;\r
import android.support.v4.app.FragmentTransaction;\r
import android.widget.TextView.OnEditorActionListener;\r
import android.widget.Toast;\r
\r
-import com.actionbarsherlock.app.SherlockDialogFragment;\r
import com.owncloud.android.MainApp;\r
import com.owncloud.android.R;\r
import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
\r
/**\r
* This Activity is used to add an ownCloud account to the App\r
- * \r
- * @author Bartek Przybylski\r
- * @author David A. Velasco\r
- * @author masensio\r
*/\r
public class AuthenticatorActivity extends AccountAuthenticatorActivity\r
implements OnRemoteOperationListener, OnFocusChangeListener, OnEditorActionListener,\r
/// Identifier of operation in progress which result shouldn't be lost \r
private long mWaitingForOpId = Long.MAX_VALUE;\r
\r
- private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());\r
- private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());\r
+ private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(\r
+ MainApp.getAccountType());\r
+ private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(\r
+ MainApp.getAccountType());\r
private final String SAML_TOKEN_TYPE =\r
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());\r
\r
protected void onCreate(Bundle savedInstanceState) {\r
//Log_OC.wtf(TAG, "onCreate init");\r
super.onCreate(savedInstanceState);\r
- getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
+\r
+ // Workaround, for fixing a problem with Android Library Suppor v7 19\r
+ //getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
+ if (getSupportActionBar() != null) {\r
+ getSupportActionBar().hide();\r
+\r
+ getSupportActionBar().setDisplayHomeAsUpEnabled(false);\r
+ getSupportActionBar().setDisplayShowHomeEnabled(false);\r
+ getSupportActionBar().setDisplayShowTitleEnabled(false);\r
+ }\r
\r
mIsFirstAuthAttempt = true;\r
\r
findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);\r
mRefreshButton = findViewById(R.id.centeredRefreshButton);\r
}\r
- showRefreshButton(mServerIsChecked && !mServerIsValid && \r
+ showRefreshButton(mServerIsChecked && !mServerIsValid &&\r
mWaitingForOpId > Integer.MAX_VALUE);\r
mServerStatusView = (TextView) findViewById(R.id.server_status_text);\r
showServerStatus();\r
mOkButton.setEnabled(false);\r
mServerInfo = new GetServerInfoOperation.ServerInfo();\r
showRefreshButton(false);\r
- \r
+\r
if (uri.length() != 0) {\r
// Handle internationalized domain names\r
uri = DisplayUtils.convertIdn(uri, true);\r
+\r
mServerStatusText = R.string.auth_testing_connection;\r
mServerStatusIcon = R.drawable.progress_small;\r
showServerStatus();\r
Intent getServerInfoIntent = new Intent();\r
getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);\r
getServerInfoIntent.putExtra(\r
- OperationsService.EXTRA_SERVER_URL, \r
+ OperationsService.EXTRA_SERVER_URL,\r
normalizeUrlSuffix(uri)\r
);\r
if (mOperationsServiceBinder != null) {\r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
/// validate credentials accessing the root folder\r
- OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);\r
+ OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username,\r
+ password);\r
accessRootFolder(credentials);\r
}\r
\r
\r
if ( mAction == ACTION_CREATE) {\r
mUsernameInput.setText(username);\r
- success = createAccount();\r
+ success = createAccount(result);\r
} else {\r
\r
if (!mUsernameInput.getText().toString().equals(username)) {\r
\r
} catch (AccountNotFoundException e) {\r
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\r
- Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();\r
+ Toast.makeText(this, R.string.auth_account_does_not_exist,\r
+ Toast.LENGTH_SHORT).show();\r
finish();\r
}\r
}\r
url = "http://" + url;\r
}\r
}\r
- \r
+\r
url = normalizeUrlSuffix(url);\r
}\r
return (url != null ? url : "");\r
\r
// TODO remove, if possible\r
private String trimUrlWebdav(String url){ \r
- if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0)){\r
- url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0.length()); \r
- } else if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_2_0)){\r
- url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_2_0.length()); \r
- } else if (url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_1_2)){\r
- url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_1_2.length()); \r
- } \r
+ if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0_AND_LATER)){\r
+ url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0_AND_LATER.length());\r
+ }\r
return (url != null ? url : "");\r
}\r
\r
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
\r
/// validate token accessing to root folder / getting session\r
- OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);\r
+ OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(\r
+ mAuthToken);\r
accessRootFolder(credentials);\r
\r
} else {\r
Log_OC.d(TAG, "Successful access - time to save the account");\r
\r
boolean success = false;\r
+\r
if (mAction == ACTION_CREATE) {\r
- success = createAccount();\r
+ success = createAccount(result);\r
\r
} else {\r
try {\r
\r
} catch (AccountNotFoundException e) {\r
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\r
- Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();\r
+ Toast.makeText(this, R.string.auth_account_does_not_exist,\r
+ Toast.LENGTH_SHORT).show();\r
finish();\r
}\r
}\r
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);\r
\r
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).\r
- equals(mAuthTokenType)) { \r
+ equals(mAuthTokenType)) {\r
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);\r
// the next line is necessary, notifications are calling directly to the \r
// AuthenticatorActivity to update, without AccountManager intervention\r
* \r
* TODO Decide how to name the OAuth accounts\r
*/\r
- private boolean createAccount() {\r
+ private boolean createAccount(RemoteOperationResult authResult) {\r
/// create and save new ownCloud account\r
boolean isOAuth = AccountTypeUtils.\r
getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType);\r
boolean isSaml = AccountTypeUtils.\r
getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType);\r
\r
+ String lastPermanentLocation = authResult.getLastPermanentLocation();\r
+ if (lastPermanentLocation != null) {\r
+ mServerInfo.mBaseUrl = AccountUtils.trimWebdavSuffix(lastPermanentLocation);\r
+ }\r
+\r
Uri uri = Uri.parse(mServerInfo.mBaseUrl);\r
String username = mUsernameInput.getText().toString().trim();\r
if (isOAuth) {\r
);\r
}\r
\r
+ // include account version with the new account\r
+ mAccountMgr.setUserData(\r
+ mAccount,\r
+ Constants.KEY_OC_ACCOUNT_VERSION,\r
+ Integer.toString(AccountUtils.ACCOUNT_VERSION)\r
+ );\r
+\r
/// add the new account as default in preferences, if there is none already\r
Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
if (defaultAccount == null) {\r
/// add user data to the new account; TODO probably can be done in the last parameter \r
// addAccountExplicitly, or in KEY_USERDATA\r
mAccountMgr.setUserData(\r
- mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()\r
+ mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()\r
);\r
mAccountMgr.setUserData(\r
mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl\r
mAuthToken = sessionCookie;\r
getRemoteUserNameOperation(sessionCookie, true);\r
Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);\r
- if (fd != null && fd instanceof SherlockDialogFragment) {\r
- Dialog d = ((SherlockDialogFragment)fd).getDialog();\r
+ if (fd != null && fd instanceof DialogFragment) {\r
+ Dialog d = ((DialogFragment)fd).getDialog();\r
if (d != null && d.isShowing()) {\r
d.dismiss();\r
}\r
\r
private void dismissDialog(String dialogTag){\r
Fragment frag = getSupportFragmentManager().findFragmentByTag(dialogTag);\r
- if (frag != null && frag instanceof SherlockDialogFragment) {\r
- SherlockDialogFragment dialog = (SherlockDialogFragment) frag;\r
+ if (frag != null && frag instanceof DialogFragment) {\r
+ DialogFragment dialog = (DialogFragment) frag;\r
dialog.dismiss();\r
}\r
}\r
mIsFirstAuthAttempt = true;\r
}\r
\r
-\r
}\r