package com.owncloud.android.ui.activity;
+import java.io.IOException;
+
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
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.accounts.AccountUtils.AccountNotFoundException;
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.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.dialog.LoadingDialog;
+import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.Log_OC;
if (mAccountWasSet) {
onAccountSet(mAccountWasRestored);
}
- if (mOperationsServiceBinder != null) {
- mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
- }
}
@Override
@Override
protected void onPause() {
- if (mOperationsServiceBinder != null) {
- mOperationsServiceBinder.removeOperationListener(this);
+ // Save cookies here
+ Log_OC.wtf(TAG, "Saving Cookies" );
+ if (mAccount != null) {
+ try {
+ ((MainApp)getApplicationContext()).getOwnCloudClientManager().
+ saveClient(mAccount, this);
+
+ // TODO get rid of the exceptions
+ } catch (AccountNotFoundException e) {
+ e.printStackTrace();
+ } catch (AuthenticatorException e) {
+ e.printStackTrace();
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
- 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();
- }
-
+ }
}
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();
+ }
}
}