use of com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException in project android by owncloud.
the class AuthenticatorActivity method onGetUserNameFinish.
private void onGetUserNameFinish(RemoteOperationResult result) {
mWaitingForOpId = Long.MAX_VALUE;
if (result.isSuccess()) {
boolean success = false;
String username = ((UserInfo) result.getData().get(0)).mDisplayName;
if (mAction == ACTION_CREATE) {
mUsernameInput.setText(username);
success = createAccount(result);
} else {
if (!mUsernameInput.getText().toString().trim().equals(username)) {
// fail - not a new account, but an existing one; disallow
result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);
mAuthToken = "";
updateAuthStatusIconAndText(result);
showAuthStatus();
Log_OC.d(TAG, result.getLogMessage());
} else {
try {
updateAccountAuthentication();
success = true;
} catch (AccountNotFoundException e) {
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);
Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
// don't use a Snackbar, finishing right now
finish();
}
}
}
if (success)
finish();
} else {
int failedStatusText = result.getCode() == ResultCode.SERVICE_UNAVAILABLE ? R.string.service_unavailable : R.string.auth_fail_get_user_name;
updateFailedAuthStatusIconAndText(failedStatusText);
showAuthStatus();
Log_OC.e(TAG, "Access to user name failed: " + result.getLogMessage());
}
}
use of com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException in project android by owncloud.
the class PreviewVideoActivity method onAccountSet.
@Override
protected void onAccountSet(boolean stateWasRecovered) {
super.onAccountSet(stateWasRecovered);
if (getAccount() != null) {
OCFile file = getFile();
/// Validate handled file (first image to preview)
if (file == null) {
throw new IllegalStateException("Instanced with a NULL OCFile");
}
if (!file.isVideo()) {
throw new IllegalArgumentException("Non-video file passed as argument");
}
file = getStorageManager().getFileById(file.getFileId());
if (file != null) {
if (file.isDown()) {
mVideoPlayer.setVideoURI(file.getStorageUri());
} else {
// not working yet
String url;
try {
url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
mVideoPlayer.setVideoURI(Uri.parse(url));
} catch (AccountNotFoundException e) {
onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
}
}
// create and prepare control panel for the user
mMediaController = new MediaController(this);
mMediaController.setMediaPlayer(mVideoPlayer);
mMediaController.setAnchorView(mVideoPlayer);
mVideoPlayer.setMediaController(mMediaController);
} else {
finish();
}
} else {
finish();
}
}
use of com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException in project android by nextcloud.
the class PreviewVideoActivity method onAccountSet.
@Override
protected void onAccountSet(boolean stateWasRecovered) {
super.onAccountSet(stateWasRecovered);
if (getAccount() != null) {
OCFile file = getFile();
// / Validate handled file (first image to preview)
if (file == null) {
throw new IllegalStateException("Instanced with a NULL OCFile");
}
if (!MimeTypeUtil.isVideo(file)) {
throw new IllegalArgumentException("Non-video file passed as argument");
}
file = getStorageManager().getFileById(file.getFileId());
if (file != null) {
if (file.isDown()) {
mVideoPlayer.setVideoURI(file.getStorageUri());
} else {
// not working yet
String url;
try {
url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
mVideoPlayer.setVideoURI(Uri.parse(url));
} catch (AccountNotFoundException e) {
onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
}
}
// create and prepare control panel for the user
mMediaController = new MediaController(this);
mMediaController.setMediaPlayer(mVideoPlayer);
mMediaController.setAnchorView(mVideoPlayer);
mVideoPlayer.setMediaController(mMediaController);
} else {
finish();
}
} else {
finish();
}
}
use of com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException in project android by nextcloud.
the class AuthenticatorActivity method onAuthenticatorTaskCallback.
/**
* Processes the result of the access check performed to try the user credentials.
*
* Creates a new account through the AccountManager.
*
* @param result Result of the operation.
*/
@Override
public void onAuthenticatorTaskCallback(RemoteOperationResult result) {
mWaitingForOpId = Long.MAX_VALUE;
dismissDialog(WAIT_DIALOG_TAG);
mAsyncTask = null;
if (result.isSuccess()) {
Log_OC.d(TAG, "Successful access - time to save the account");
boolean success = false;
if (mAction == ACTION_CREATE) {
success = createAccount(result);
} else {
try {
updateAccountAuthentication();
success = true;
} catch (AccountNotFoundException e) {
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);
Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
finish();
}
}
// Reset webView
webViewPassword = null;
webViewUser = null;
forceOldLoginMethod = false;
deleteCookies();
if (success) {
finish();
} else {
// init webView again
if (mLoginWebView != null) {
mLoginWebView.setVisibility(View.GONE);
}
setContentView(R.layout.account_setup);
initOverallUi();
CustomEditText serverAddressField = findViewById(R.id.hostUrlInput);
serverAddressField.setText(mServerInfo.mBaseUrl);
findViewById(R.id.oauth_onOff_check).setVisibility(View.GONE);
findViewById(R.id.server_status_text).setVisibility(View.GONE);
mAuthStatusView = findViewById(R.id.auth_status_text);
showAuthStatus();
}
} else if (result.isServerFail() || result.isException()) {
// / server errors or exceptions in authorization take to requiring a new check of
// / the server
mServerIsChecked = true;
mServerIsValid = false;
mServerInfo = new GetServerInfoOperation.ServerInfo();
// update status icon and text
updateServerStatusIconAndText(result);
showServerStatus();
mAuthStatusIcon = 0;
mAuthStatusText = "";
if (!webViewLoginMethod) {
showAuthStatus();
// update input controls state
showRefreshButton(true);
mOkButton.setEnabled(false);
}
// very special case (TODO: move to a common place for all the remote operations)
if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {
showUntrustedCertDialog(result);
}
} else {
// authorization fail due to client side - probably wrong credentials
if (webViewLoginMethod) {
mLoginWebView = findViewById(R.id.login_webview);
initWebViewLogin(mServerInfo.mBaseUrl);
Snackbar.make(mLoginWebView, getString(R.string.auth_access_failed) + ": " + result.getLogMessage(), Snackbar.LENGTH_LONG).show();
} else {
updateAuthStatusIconAndText(result);
showAuthStatus();
}
// reset webview
webViewPassword = null;
webViewUser = null;
deleteCookies();
Log_OC.d(TAG, "Access failed: " + result.getLogMessage());
}
}
use of com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException in project android by nextcloud.
the class AuthenticatorActivity method onGetUserNameFinish.
private void onGetUserNameFinish(RemoteOperationResult result) {
mWaitingForOpId = Long.MAX_VALUE;
if (result.isSuccess()) {
boolean success = false;
String username;
if (result.getData().get(0) instanceof UserInfo) {
username = ((UserInfo) result.getData().get(0)).getDisplayName();
} else {
username = (String) result.getData().get(0);
}
if (mAction == ACTION_CREATE) {
if (!webViewLoginMethod) {
mUsernameInput.setText(username);
}
success = createAccount(result);
} else {
if (!webViewLoginMethod && !mUsernameInput.getText().toString().trim().equals(username)) {
// fail - not a new account, but an existing one; disallow
result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);
mAuthToken = "";
updateAuthStatusIconAndText(result);
showAuthStatus();
Log_OC.d(TAG, result.getLogMessage());
} else {
try {
updateAccountAuthentication();
success = true;
} catch (AccountNotFoundException e) {
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);
Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
finish();
}
}
}
if (success) {
finish();
}
} else {
if (!webViewLoginMethod) {
int statusText = result.getCode() == ResultCode.MAINTENANCE_MODE ? R.string.maintenance_mode : R.string.auth_fail_get_user_name;
updateStatusIconFailUserName(statusText);
showAuthStatus();
}
Log_OC.e(TAG, "Access to user name failed: " + result.getLogMessage());
}
}
Aggregations