Эх сурвалжийг харах

Customize upload sync conflict notification strings

Signed-off-by: Alice Gaudon <alice@gaudon.pro>
Alice Gaudon 5 жил өмнө
parent
commit
a4ff1f11d7

+ 6 - 2
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -739,8 +739,12 @@ public class FileUploader extends Service
             String content;
 
             // check credentials error
-            boolean needsToUpdateCredentials = ResultCode.UNAUTHORIZED.equals(uploadResult.getCode());
-            tickerId = needsToUpdateCredentials ? R.string.uploader_upload_failed_credentials_error : tickerId;
+            boolean needsToUpdateCredentials = uploadResult.getCode() == ResultCode.UNAUTHORIZED;
+            if (needsToUpdateCredentials) {
+                tickerId = R.string.uploader_upload_failed_credentials_error;
+            } else if (uploadResult.getCode() == ResultCode.SYNC_CONFLICT) { // check file conflict
+                tickerId = R.string.uploader_upload_failed_sync_conflict_error;
+            }
 
             mNotificationBuilder
                 .setTicker(getString(tickerId))

+ 9 - 7
src/main/java/com/owncloud/android/utils/ErrorMessageAdapter.java

@@ -76,14 +76,14 @@ public final class ErrorMessageAdapter {
             RemoteOperation operation,
             Resources res
     ) {
-        String message = getSpecificMessageForResultAndOperation(result, operation, res);
+        String message = getMessageForResultAndOperation(result, operation, res);
 
         if (TextUtils.isEmpty(message)) {
-            message = getCommonMessageForResult(result, res);
+            message = getMessageForResult(result, res);
         }
 
         if (TextUtils.isEmpty(message)) {
-            message = getGenericErrorMessageForOperation(operation, res);
+            message = getMessageForOperation(operation, res);
         }
 
         if (message == null) {
@@ -109,7 +109,7 @@ public final class ErrorMessageAdapter {
      *                      specific message for both.
      */
     @Nullable
-    private static String getSpecificMessageForResultAndOperation(
+    private static String getMessageForResultAndOperation(
             RemoteOperationResult result,
             RemoteOperation operation,
             Resources res
@@ -360,6 +360,9 @@ public final class ErrorMessageAdapter {
             } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
                 return res.getString(R.string.filename_forbidden_charaters_from_server);
 
+            } else if(result.getCode() == ResultCode.SYNC_CONFLICT) {
+                return String.format(res.getString(R.string.uploader_upload_failed_sync_conflict_error_content),
+                                        operation.getFileName());
             }
         }
 
@@ -376,8 +379,7 @@ public final class ErrorMessageAdapter {
      * @return              User message corresponding to 'result'.
      */
     @Nullable
-    private static String getCommonMessageForResult(RemoteOperationResult result, Resources res) {
-
+    private static String getMessageForResult(RemoteOperationResult result, Resources res) {
         String message = null;
 
         if (!result.isSuccess()) {
@@ -452,7 +454,7 @@ public final class ErrorMessageAdapter {
      * @return              User message corresponding to a generic error of 'operation'.
      */
     @Nullable
-    private static String getGenericErrorMessageForOperation(RemoteOperation operation, Resources res) {
+    private static String getMessageForOperation(RemoteOperation operation, Resources res) {
         String message = null;
 
         if (operation instanceof UploadFileOperation) {

+ 2 - 0
src/main/res/values/strings.xml

@@ -914,6 +914,8 @@
     <string name="create_rich_workspace">Add folder info</string>
     <string name="creates_rich_workspace">creates folder info</string>
     <string name="edit_rich_workspace">edit folder info</string>
+    <string name="uploader_upload_failed_sync_conflict_error">File upload conflict</string>
+    <string name="uploader_upload_failed_sync_conflict_error_content">Pick which version to keep of %1$s</string>
     <string name="create_new">Create new</string>
     <string name="editor_placeholder" translatable="false">%1$s %2$s</string>