Fixed error messages related with network in ShareActivity

This commit is contained in:
David A. Velasco 2015-10-28 09:38:29 +01:00
parent fc2ac6445d
commit aa4f47cbe0
7 changed files with 56 additions and 141 deletions

View file

@ -69,6 +69,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CreateShareViaLinkOperation;
import com.owncloud.android.operations.CreateShareWithShareeOperation;
import com.owncloud.android.operations.GetSharesForFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareOperation;
@ -712,6 +713,8 @@ public class FileActivity extends AppCompatActivity
mFileOperationsHelper.setOpIdWaitingFor(Long.MAX_VALUE);
dismissLoadingDialog();
if (!result.isSuccess() && (
result.getCode() == ResultCode.UNAUTHORIZED ||
result.isIdPRedirection() ||
@ -729,21 +732,37 @@ public class FileActivity extends AppCompatActivity
}
mTryShareAgain = false;
} else if (operation == null ||
operation instanceof CreateShareWithShareeOperation ||
operation instanceof UnshareOperation ||
operation instanceof SynchronizeFolderOperation
) {
if (result.isSuccess()) {
updateFileFromDB();
} else if (result.getCode() != ResultCode.CANCELLED) {
Toast t = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
t.show();
}
} else if (operation instanceof CreateShareViaLinkOperation) {
onCreateShareViaLinkOperationFinish((CreateShareViaLinkOperation) operation, result);
} else if (operation instanceof CreateShareWithShareeOperation) {
onCreateShareWithShareeOperationFinish((CreateShareWithShareeOperation) operation, result);
} else if (operation instanceof SynchronizeFileOperation) {
onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result);
} else if (operation instanceof UnshareOperation) {
onUnshareLinkOperationFinish((UnshareOperation) operation, result);
} else if (operation instanceof SynchronizeFolderOperation) {
onSynchronizeFolderOperationFinish((SynchronizeFolderOperation) operation, result);
}else if (operation instanceof SynchronizeFileOperation) {
onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
} else if (operation instanceof GetSharesForFileOperation) {
if (result.isSuccess()) {
updateFileFromDB();
} else if (result.getCode() != ResultCode.SHARE_NOT_FOUND) {
Toast t = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
t.show();
}
}
}
@ -761,7 +780,6 @@ public class FileActivity extends AppCompatActivity
private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
if (result.isSuccess()) {
mTryShareAgain = false;
updateFileFromDB();
@ -792,47 +810,8 @@ public class FileActivity extends AppCompatActivity
}
}
private void onCreateShareWithShareeOperationFinish(CreateShareWithShareeOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
if (result.isSuccess()) {
updateFileFromDB();
} else {
Toast t = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
t.show();
}
}
private void onUnshareLinkOperationFinish(UnshareOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
if (result.isSuccess()){
updateFileFromDB();
} else {
Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
operation, getResources()), Toast.LENGTH_LONG);
t.show();
}
}
private void onSynchronizeFolderOperationFinish(
SynchronizeFolderOperation operation, RemoteOperationResult result
) {
if (!result.isSuccess() && result.getCode() != ResultCode.CANCELLED){
Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
operation, getResources()), Toast.LENGTH_LONG);
t.show();
}
}
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
OCFile syncedFile = operation.getLocalFile();
if (!result.isSuccess()) {
if (result.getCode() == ResultCode.SYNC_CONFLICT) {

View file

@ -1418,8 +1418,6 @@ public class FileDisplayActivity extends HookActivity
*/
private void onRemoveFileOperationFinish(RemoveFileOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
Toast msg = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
@ -1458,10 +1456,8 @@ public class FileDisplayActivity extends HookActivity
private void onMoveFileOperationFinish(MoveFileOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
dismissLoadingDialog();
refreshListOfFilesFragment();
} else {
dismissLoadingDialog();
try {
Toast msg = Toast.makeText(FileDisplayActivity.this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
@ -1483,10 +1479,8 @@ public class FileDisplayActivity extends HookActivity
*/
private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
dismissLoadingDialog();
refreshListOfFilesFragment();
} else {
dismissLoadingDialog();
try {
Toast msg = Toast.makeText(FileDisplayActivity.this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
@ -1508,7 +1502,6 @@ public class FileDisplayActivity extends HookActivity
*/
private void onRenameFileOperationFinish(RenameFileOperation operation,
RemoteOperationResult result) {
dismissLoadingDialog();
OCFile renamedFile = operation.getFile();
if (result.isSuccess()) {
FileFragment details = getSecondFragment();
@ -1577,10 +1570,8 @@ public class FileDisplayActivity extends HookActivity
private void onCreateFolderOperationFinish(CreateFolderOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
dismissLoadingDialog();
refreshListOfFilesFragment();
} else {
dismissLoadingDialog();
try {
Toast msg = Toast.makeText(FileDisplayActivity.this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),

View file

@ -408,10 +408,8 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
) {
if (result.isSuccess()) {
dismissLoadingDialog();
refreshListOfFilesFragment();
} else {
dismissLoadingDialog();
try {
Toast msg = Toast.makeText(FolderPickerActivity.this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),

View file

@ -51,8 +51,7 @@ import java.util.ArrayList;
*/
public class ShareActivity extends FileActivity
implements GetShareWithUsersAsyncTask.OnGetSharesWithUsersTaskListener,
ShareFileFragment.OnShareFragmentInteractionListener,
implements ShareFileFragment.OnShareFragmentInteractionListener,
SearchFragment.OnSearchFragmentInteractionListener {
private static final String TAG = ShareActivity.class.getSimpleName();
@ -200,38 +199,15 @@ public class ShareActivity extends FileActivity
@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
super.onRemoteOperationFinish(operation, result);
if (operation instanceof UnshareOperation ||
operation instanceof CreateShareWithShareeOperation) {
if (result.isSuccess()) {
refreshUsersInLists();
if (operation instanceof CreateShareWithShareeOperation) {
// Clean action
getIntent().setAction(null);
}
} else {
Toast.makeText(
this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG
).show();
}
/*} else if (operation instanceof GetSharesForFileOperation) {
onGetSharesForFileOperationFinish((GetSharesForFileOperation) operation, result);*/
}
}
@Override
public void onGetDataShareWithFinish(RemoteOperationResult result) {
// Remove loading
dismissLoadingDialog();
if (result.isSuccess()) {
Log_OC.d(TAG, "Get Data Share With finishes sucessfully");
} // else, ignore and use pre-cached shares in database
refreshUsersInLists();
if (operation instanceof CreateShareWithShareeOperation) {
// Clean action
getIntent().setAction(null);
}
}
// Data is on Database
refreshUsersInLists();
}
private void refreshUsersInLists(){

View file

@ -607,10 +607,8 @@ public class Uploader extends FileActivity
private void onCreateFolderOperationFinish(CreateFolderOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
dismissLoadingDialog();
populateDirectoryList();
} else {
dismissLoadingDialog();
try {
Toast msg = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),

View file

@ -61,7 +61,10 @@ public class ErrorMessageAdapter {
String message = null;
if (operation instanceof UploadFileOperation) {
if (!result.isSuccess() && isNetworkError(result.getCode())) {
message = getErrorMessage(result, res);
} else if (operation instanceof UploadFileOperation) {
if (result.isSuccess()) {
message = String.format(
@ -120,9 +123,6 @@ public class ErrorMessageAdapter {
// Error --> No permissions
message = String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.forbidden_permissions_delete));
} else if (isNetworkError(result.getCode())) {
message = getErrorMessage(result, res);
} else {
message = res.getString(R.string.remove_fail_msg);
}
@ -140,9 +140,6 @@ public class ErrorMessageAdapter {
} else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
message = res.getString(R.string.filename_forbidden_characters);
} else if (isNetworkError(result.getCode())) {
message = getErrorMessage(result, res);
} else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
message = res.getString(R.string.filename_forbidden_charaters_from_server);
@ -163,9 +160,6 @@ public class ErrorMessageAdapter {
message = String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.forbidden_permissions_create));
} else if (isNetworkError(result.getCode())) {
message = getErrorMessage(result, res);
} else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
message = res.getString(R.string.filename_forbidden_charaters_from_server);
} else {
@ -185,9 +179,6 @@ public class ErrorMessageAdapter {
message = String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.share_link_forbidden_permissions));
} else if (isNetworkError(result.getCode())) {
message = getErrorMessage(result, res);
} else { // Generic error
// Show a Message, operation finished without success
message = res.getString(R.string.share_link_file_error);
@ -206,18 +197,13 @@ public class ErrorMessageAdapter {
message = String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.unshare_link_forbidden_permissions));
} else if (isNetworkError(result.getCode())) {
message = getErrorMessage(result, res);
} else { // Generic error
// Show a Message, operation finished without success
message = res.getString(R.string.unshare_link_file_error);
}
} else if (operation instanceof MoveFileOperation) {
if(isNetworkError(result.getCode())){
message = getErrorMessage(result, res);
} else if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
message = res.getString(R.string.move_file_not_found);
} else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) {
message = res.getString(R.string.move_file_invalid_into_descendent);
@ -252,9 +238,7 @@ public class ErrorMessageAdapter {
}
}
} else if (operation instanceof CopyFileOperation) {
if(isNetworkError(result.getCode())){
message = getErrorMessage(result, res);
} else if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
message = res.getString(R.string.copy_file_not_found);
} else if (result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT) {
message = res.getString(R.string.copy_file_invalid_into_descendent);

View file

@ -22,6 +22,7 @@ package com.owncloud.android.utils;
import android.accounts.Account;
import android.os.AsyncTask;
import android.util.Pair;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.FileDataStorageManager;
@ -29,34 +30,30 @@ import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
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.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.operations.GetSharesForFileOperation;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
/**
* Async Task to get the users and groups which a file is shared with
*/
public class GetShareWithUsersAsyncTask extends AsyncTask<Object, Void, RemoteOperationResult> {
public class GetShareWithUsersAsyncTask extends AsyncTask<Object, Void, Pair<RemoteOperation, RemoteOperationResult>> {
private final String TAG = GetShareWithUsersAsyncTask.class.getSimpleName();
private final WeakReference<OnGetSharesWithUsersTaskListener> mListener;
private ArrayList<OCShare> mShares;
private final WeakReference<OnRemoteOperationListener> mListener;
public ArrayList<OCShare> getShares(){
return mShares;
}
public GetShareWithUsersAsyncTask(OnGetSharesWithUsersTaskListener listener) {
mListener = new WeakReference<OnGetSharesWithUsersTaskListener>(listener);
public GetShareWithUsersAsyncTask(OnRemoteOperationListener listener) {
mListener = new WeakReference<OnRemoteOperationListener>(listener);
}
@Override
protected RemoteOperationResult doInBackground(Object... params) {
protected Pair<RemoteOperation, RemoteOperationResult> doInBackground(Object... params) {
GetSharesForFileOperation operation = null;
RemoteOperationResult result = null;
if (params != null && params.length == 3) {
@ -66,8 +63,7 @@ public class GetShareWithUsersAsyncTask extends AsyncTask<Object, Void, RemoteOp
try {
// Get shares request
GetSharesForFileOperation operation =
new GetSharesForFileOperation(file.getRemotePath(), false, false);
operation = new GetSharesForFileOperation(file.getRemotePath(), false, false);
OwnCloudAccount ocAccount = new OwnCloudAccount(account,
MainApp.getAppContext());
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
@ -82,27 +78,20 @@ public class GetShareWithUsersAsyncTask extends AsyncTask<Object, Void, RemoteOp
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
}
return result;
return new Pair(operation, result);
}
@Override
protected void onPostExecute(RemoteOperationResult result) {
protected void onPostExecute(Pair<RemoteOperation, RemoteOperationResult> result) {
if (result!= null)
{
OnGetSharesWithUsersTaskListener listener = mListener.get();
OnRemoteOperationListener listener = mListener.get();
if (listener!= null)
{
listener.onGetDataShareWithFinish(result);
listener.onRemoteOperationFinish(result.first, result.second);
}
}
}
/*
* Interface to retrieve data from get shares task
*/
public interface OnGetSharesWithUsersTaskListener{
void onGetDataShareWithFinish(RemoteOperationResult result);
}
}