package com.owncloud.android.ui.activity;
-import org.apache.commons.httpclient.Credentials;
-
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
-import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.lib.common.network.BearerCredentials;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.dialog.LoadingDialog;
-import com.owncloud.android.utils.Log_OC;
+import com.owncloud.android.utils.ErrorMessageAdapter;
/**
private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";;
+ protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
+
/** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located. */
private Account mAccount;
if (mAccountWasSet) {
onAccountSet(mAccountWasRestored);
}
- if (mOperationsServiceBinder != null) {
- mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
- }
}
@Override
@Override
protected void onPause() {
- if (mOperationsServiceBinder != null) {
- mOperationsServiceBinder.removeOperationListener(this);
- }
- super.onPause();
- }
-
- @Override
- protected void onStop() {
-
if (mOperationsServiceBinder != null) {
mOperationsServiceBinder.removeOperationListener(this);
}
- super.onStop();
+ super.onPause();
}
@Override
protected void onDestroy() {
- super.onDestroy();
if (mOperationsServiceConnection != null) {
unbindService(mOperationsServiceConnection);
mOperationsServiceBinder = null;
unbindService(mUploadServiceConnection);
mUploadServiceConnection = null;
}
+ super.onDestroy();
}
)) {
requestCredentialsUpdate();
+
+ if (result.getCode() == ResultCode.UNAUTHORIZED) {
+ dismissLoadingDialog();
+ Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ t.show();
+ }
} else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
}
}
- private void requestCredentialsUpdate() {
+ protected void requestCredentialsUpdate() {
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
updateAccountCredentials.putExtra(
Intent sendIntent = operation.getSendIntent();
startActivity(sendIntent);
- } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
- Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG);
- t.show();
- } else { // Generic error
- // Show a Message, operation finished without success
- Toast t = Toast.makeText(this, getString(R.string.share_link_file_error), Toast.LENGTH_LONG);
+ } else {
+ Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
t.show();
- }
+ }
}
if (result.isSuccess()){
updateFileFromDB();
- } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
- Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_no_exist), Toast.LENGTH_LONG);
- t.show();
- } else { // Generic error
- // Show a Message, operation finished without success
- Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_error), Toast.LENGTH_LONG);
+ } else {
+ Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
t.show();
- }
-
+ }
}
- private void updateFileFromDB(){
- OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
- if (file != null) {
- setFile(file);
- }
+ protected void updateFileFromDB(){
+ OCFile file = getFile();
+ if (file != null) {
+ file = getStorageManager().getFileByPath(file.getRemotePath());
+ setFile(file);
+ }
}
/**
mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
long waitingForOpId = mFileOperationsHelper.getOpIdWaitingFor();
if (waitingForOpId <= Integer.MAX_VALUE) {
- mOperationsServiceBinder.dispatchResultIfFinished((int)waitingForOpId, this);
+ boolean wait = mOperationsServiceBinder.dispatchResultIfFinished((int)waitingForOpId, this);
+ if (!wait ) {
+ dismissLoadingDialog();
+ }
}
}