Correctly parse share api

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2021-03-01 15:01:24 +01:00
parent 9b1e0f3e8a
commit 6a0b91e2c3
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7

View file

@ -166,22 +166,23 @@ public final class ErrorMessageAdapter {
return message; return message;
} }
private static String getMessageForSynchronizeFolderOperation( private static @Nullable
RemoteOperationResult result, String getMessageForSynchronizeFolderOperation(
SynchronizeFolderOperation operation, RemoteOperationResult result,
Resources res SynchronizeFolderOperation operation,
) { Resources res
) {
if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND) { if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND) {
return String.format( return String.format(
res.getString(R.string.sync_current_folder_was_removed), res.getString(R.string.sync_current_folder_was_removed),
new File(operation.getFolderPath()).getName() new File(operation.getFolderPath()).getName()
); );
} }
return return null;
null;
} }
private static String getMessageForMoveFileOperation(RemoteOperationResult result, Resources res) { private static @Nullable
String getMessageForMoveFileOperation(RemoteOperationResult result, Resources res) {
if (result.getCode() == ResultCode.FILE_NOT_FOUND) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
return res.getString(R.string.move_file_not_found); return res.getString(R.string.move_file_not_found);
} else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) { } else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) {
@ -192,7 +193,7 @@ public final class ErrorMessageAdapter {
} else if (result.getCode() == ResultCode.FORBIDDEN) { } else if (result.getCode() == ResultCode.FORBIDDEN) {
return String.format(res.getString(R.string.forbidden_permissions), return String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.forbidden_permissions_move)); res.getString(R.string.forbidden_permissions_move));
} else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
return res.getString(R.string.filename_forbidden_charaters_from_server); return res.getString(R.string.filename_forbidden_charaters_from_server);
@ -200,39 +201,36 @@ public final class ErrorMessageAdapter {
return null; return null;
} }
private static String getMessageForUpdateShareOperations(RemoteOperationResult result, Resources res) { private static @Nullable
if (result.getData() != null && result.getData().size() > 0) { String getMessageForUpdateShareOperations(RemoteOperationResult result, Resources res) {
return (String) result.getData().get(0); // share API sends its own error messages if (!TextUtils.isEmpty(result.getMessage())) {
return result.getMessage(); // share API sends its own error messages
} else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
return res.getString(R.string.update_link_file_no_exist); return res.getString(R.string.update_link_file_no_exist);
} else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
// Error --> No permissions // Error --> No permissions
return String.format(res.getString(R.string.forbidden_permissions), return String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.update_link_forbidden_permissions)); res.getString(R.string.update_link_forbidden_permissions));
} }
return null; return null;
} }
private static String getMessageForUnshareOperation(RemoteOperationResult result, Resources res) { private static @Nullable
if (result.getData() != null && result.getData().size() > 0) { String getMessageForUnshareOperation(RemoteOperationResult result, Resources res) {
return (String) result.getData().get(0); // share API sends its own error messages if (!TextUtils.isEmpty(result.getMessage())) {
return result.getMessage(); // share API sends its own error messages
} else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
return res.getString(R.string.unshare_link_file_no_exist); return res.getString(R.string.unshare_link_file_no_exist);
} else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
// Error --> No permissions // Error --> No permissions
return String.format(res.getString(R.string.forbidden_permissions), return String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.unshare_link_forbidden_permissions)); res.getString(R.string.unshare_link_forbidden_permissions));
} }
return null; return null;
} }
private static String getMessageForCopyFileOperation(RemoteOperationResult result, Resources res) { private static @Nullable
String getMessageForCopyFileOperation(RemoteOperationResult result, Resources res) {
if (result.getCode() == ResultCode.FILE_NOT_FOUND) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
return res.getString(R.string.copy_file_not_found); return res.getString(R.string.copy_file_not_found);
@ -264,13 +262,14 @@ public final class ErrorMessageAdapter {
return null; return null;
} }
private static String getMessageForCreateFolderOperation(RemoteOperationResult result, Resources res) { private static @Nullable
String getMessageForCreateFolderOperation(RemoteOperationResult result, Resources res) {
if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) { if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
return res.getString(R.string.filename_forbidden_characters); return res.getString(R.string.filename_forbidden_characters);
} else if (result.getCode().equals(ResultCode.FORBIDDEN)) { } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
return String.format(res.getString(R.string.forbidden_permissions), return String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.forbidden_permissions_create)); res.getString(R.string.forbidden_permissions_create));
} else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) { } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
return res.getString(R.string.filename_forbidden_charaters_from_server); return res.getString(R.string.filename_forbidden_charaters_from_server);
@ -279,14 +278,15 @@ public final class ErrorMessageAdapter {
return null; return null;
} }
private static String getMessageForRenameFileOperation(RemoteOperationResult result, Resources res) { private static @Nullable
String getMessageForRenameFileOperation(RemoteOperationResult result, Resources res) {
if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) { if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
return res.getString(R.string.rename_local_fail_msg); return res.getString(R.string.rename_local_fail_msg);
} else if (result.getCode().equals(ResultCode.FORBIDDEN)) { } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
// Error --> No permissions // Error --> No permissions
return String.format(res.getString(R.string.forbidden_permissions), return String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.forbidden_permissions_rename)); res.getString(R.string.forbidden_permissions_rename));
} else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) { } else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
return res.getString(R.string.filename_forbidden_characters); return res.getString(R.string.filename_forbidden_characters);
@ -299,7 +299,8 @@ public final class ErrorMessageAdapter {
return null; return null;
} }
private static String getMessageForRemoveFileOperation(RemoteOperationResult result, Resources res) { private static @Nullable
String getMessageForRemoveFileOperation(RemoteOperationResult result, Resources res) {
if (result.isSuccess()) { if (result.isSuccess()) {
return res.getString(R.string.remove_success_msg); return res.getString(R.string.remove_success_msg);
@ -307,22 +308,23 @@ public final class ErrorMessageAdapter {
if (result.getCode().equals(ResultCode.FORBIDDEN)) { if (result.getCode().equals(ResultCode.FORBIDDEN)) {
// Error --> No permissions // Error --> No permissions
return String.format(res.getString(R.string.forbidden_permissions), return String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.forbidden_permissions_delete)); res.getString(R.string.forbidden_permissions_delete));
} }
} }
return null; return null;
} }
private static String getMessageForDownloadFileOperation( private static @Nullable
RemoteOperationResult result, String getMessageForDownloadFileOperation(
DownloadFileOperation operation, RemoteOperationResult result,
Resources res DownloadFileOperation operation,
) { Resources res
) {
if (result.isSuccess()) { if (result.isSuccess()) {
return String.format( return String.format(
res.getString(R.string.downloader_download_succeeded_content), res.getString(R.string.downloader_download_succeeded_content),
new File(operation.getSavePath()).getName()); new File(operation.getSavePath()).getName());
} else { } else {
if (result.getCode() == ResultCode.FILE_NOT_FOUND) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
@ -333,15 +335,16 @@ public final class ErrorMessageAdapter {
return null; return null;
} }
private static String getMessageForUploadFileOperation( private static @Nullable
RemoteOperationResult result, String getMessageForUploadFileOperation(
UploadFileOperation operation, RemoteOperationResult result,
Resources res UploadFileOperation operation,
) { Resources res
) {
if (result.isSuccess()) { if (result.isSuccess()) {
return String.format( return String.format(
res.getString(R.string.uploader_upload_succeeded_content_single), res.getString(R.string.uploader_upload_succeeded_content_single),
operation.getFileName()); operation.getFileName());
} else { } else {
if (result.getCode() == ResultCode.LOCAL_STORAGE_FULL if (result.getCode() == ResultCode.LOCAL_STORAGE_FULL