瀏覽代碼

Merge pull request #502 from nextcloud/recognizeMaintenanceMode

Recognize maintenance mode
Andy Scherzinger 7 年之前
父節點
當前提交
6409e22228

+ 2 - 1
build.gradle

@@ -49,6 +49,7 @@ repositories {
     }
 }
 
+
 android {
     lintOptions {
         abortOnError true
@@ -182,7 +183,7 @@ dependencies {
     compile name: 'touch-image-view'
     compile 'com.android.support:multidex:1.0.1'
 
-    compile 'com.github.nextcloud:android-library:1.0.15'
+    compile 'com.github.nextcloud:android-library:1.0.16'
     compile "com.android.support:support-v4:${supportLibraryVersion}"
     compile "com.android.support:design:${supportLibraryVersion}"
     compile 'com.jakewharton:disklrucache:2.0.2'

+ 7 - 4
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -1252,7 +1252,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             }
         } else {
             if (!webViewLoginMethod) {
-                updateStatusIconFailUserName();
+                int statusText = result.getCode() == ResultCode.MAINTENANCE_MODE ? R.string.maintenance_mode : R.string.auth_fail_get_user_name;
+                updateStatusIconFailUserName(statusText);
                 showAuthStatus();
             }
             Log_OC.e(TAG, "Access to user name failed: " + result.getLogMessage());
@@ -1452,6 +1453,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 mServerStatusIcon = R.drawable.ic_lock_open_white;
                 mServerStatusText = R.string.auth_redirect_non_secure_connection_title;
                 break;
+            case MAINTENANCE_MODE:
+                mServerStatusText = R.string.maintenance_mode;
+                break;
             default:
                 mServerStatusText = 0;
                 mServerStatusIcon = 0;
@@ -1541,10 +1545,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         }
     }
 
-
-    private void updateStatusIconFailUserName() {
+    private void updateStatusIconFailUserName(int failedStatusText){
         mAuthStatusIcon = R.drawable.ic_alert;
-        mAuthStatusText = R.string.auth_fail_get_user_name;
+        mAuthStatusText = failedStatusText;
     }
 
     private void updateServerStatusIconNoRegularAuth() {

+ 6 - 1
src/main/java/com/owncloud/android/db/UploadResult.java

@@ -34,7 +34,8 @@ public enum UploadResult {
     FILE_NOT_FOUND(8),
     DELAYED_FOR_WIFI(9),
     SERVICE_INTERRUPTED(10),
-    DELAYED_FOR_CHARGING(11);
+    DELAYED_FOR_CHARGING(11),
+    MAINTENANCE_MODE(12);
 
     private final int value;
 
@@ -74,6 +75,8 @@ public enum UploadResult {
                 return SERVICE_INTERRUPTED;
             case 11:
                 return DELAYED_FOR_CHARGING;
+            case 12:
+                return MAINTENANCE_MODE;
         }
         return null;
     }
@@ -115,6 +118,8 @@ public enum UploadResult {
                     return FILE_ERROR;
                 }
                 return UNKNOWN;
+            case MAINTENANCE_MODE:
+                return MAINTENANCE_MODE;
             default:
                 return UNKNOWN;
         }

+ 2 - 2
src/main/java/com/owncloud/android/operations/UnshareOperation.java

@@ -89,8 +89,8 @@ public class UnshareOperation extends SyncOperation {
 
                 getStorageManager().saveFile(file);
                 getStorageManager().removeShare(share);
-                
-            } else if (!existsFile(client, file.getRemotePath())) {
+
+            } else if (result.getCode() != ResultCode.MAINTENANCE_MODE && !existsFile(client, file.getRemotePath())) {
                 // unshare failed because file was deleted before
                 getStorageManager().removeFile(file, true, true);
             }

+ 1 - 0
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -323,6 +323,7 @@ public class UploadFileOperation extends SyncOperation {
             remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
                     remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;
             result = grantFolderExistence(remoteParentPath, client);
+
             if (!result.isSuccess()) {
 
                 return result;

+ 1 - 0
src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java

@@ -265,6 +265,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
                 // The Toast must be shown in the main thread to grant that will be hidden correctly; otherwise
                 // the thread may die before, an exception will occur, and the message will be left on the screen
                 // until the app dies
+
                 Toast.makeText(
                         getContext().getApplicationContext(),
                         ErrorMessageAdapter.getErrorCauseMessage(

+ 4 - 0
src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -514,6 +514,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
      * @return              Text describing the status of the given upload.
      */
     private String getStatusText(OCUpload upload) {
+
         String status;
         switch (upload.getUploadStatus()) {
 
@@ -596,6 +597,9 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                         // should not get here ; status should be UPLOAD_SUCCESS
                         status =  mParentActivity.getString(R.string.uploads_view_upload_status_succeeded);
                         break;
+                    case MAINTENANCE_MODE:
+                        status = mParentActivity.getString(R.string.maintenance_mode);
+                        break;
                     default:
                         status = "Naughty devs added a new fail result but no description for the user";
                         break;

+ 0 - 2
src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java

@@ -74,6 +74,4 @@ public class NotificationUtils {
         }, delayInMillis); 
     
     }
-    
-
 }

+ 14 - 6
src/main/java/com/owncloud/android/utils/ErrorMessageAdapter.java

@@ -17,7 +17,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 package com.owncloud.android.utils;
 
 import android.content.res.Resources;
@@ -57,8 +56,8 @@ public class ErrorMessageAdapter {
 
         String message = null;
 
-        if (!result.isSuccess() && isNetworkError(result.getCode())) {
-            message = getErrorMessage(result, res);
+        if (!result.isSuccess() && isCommonError(result.getCode())) {
+            message = getCommonErrorMessage(result, res);
 
         } else if (operation instanceof UploadFileOperation) {
 
@@ -119,6 +118,7 @@ public class ErrorMessageAdapter {
                     // Error --> No permissions
                     message = String.format(res.getString(R.string.forbidden_permissions),
                             res.getString(R.string.forbidden_permissions_delete));
+
                 } else {
                     message = res.getString(R.string.remove_fail_msg);
                 }
@@ -158,9 +158,11 @@ public class ErrorMessageAdapter {
 
             } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
                 message = res.getString(R.string.filename_forbidden_charaters_from_server);
+
             } else {
                 message = res.getString(R.string.create_dir_fail_msg);
             }
+
         } else if (operation instanceof CreateShareViaLinkOperation ||
                 operation instanceof CreateShareWithShareeOperation) {
 
@@ -238,6 +240,7 @@ public class ErrorMessageAdapter {
                 // Show a Message, operation finished without success
                 message = res.getString(R.string.move_file_error);
             }
+
         } else if (operation instanceof SynchronizeFolderOperation) {
 
             if (!result.isSuccess()) {
@@ -253,9 +256,11 @@ public class ErrorMessageAdapter {
                             folderPathName);
                 }
             }
+
         } else if (operation instanceof CopyFileOperation) {
             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);
 
@@ -275,7 +280,7 @@ public class ErrorMessageAdapter {
         return message;
     }
 
-    private static String getErrorMessage(RemoteOperationResult result, Resources res) {
+    private static String getCommonErrorMessage(RemoteOperationResult result, Resources res) {
 
         String message = null;
 
@@ -295,15 +300,18 @@ public class ErrorMessageAdapter {
 
             } else if (result.getCode() == ResultCode.HOST_NOT_AVAILABLE) {
                 message = res.getString(R.string.network_host_not_available);
+            } else if (result.getCode() == ResultCode.MAINTENANCE_MODE) {
+                message = res.getString(R.string.maintenance_mode);
             }
         }
 
         return message;
     }
 
-    private static boolean isNetworkError(RemoteOperationResult.ResultCode code) {
+    private static boolean isCommonError(RemoteOperationResult.ResultCode code) {
         return code == ResultCode.WRONG_CONNECTION ||
                 code == ResultCode.TIMEOUT ||
-                code == ResultCode.HOST_NOT_AVAILABLE;
+                code == ResultCode.HOST_NOT_AVAILABLE ||
+                code == ResultCode.MAINTENANCE_MODE;
     }
 }

+ 4 - 1
src/main/res/values/strings.xml

@@ -276,7 +276,8 @@
 	<string name="auth_fail_get_user_name">Your server is not returning a correct user ID, please contact an administrator</string>
 	<string name="auth_can_not_auth_against_server">Cannot authenticate to this server</string>
     <string name="auth_account_does_not_exist">Account does not exist on the device yet</string>
-    
+
+
     <string name="favorite">Set as available offline</string>
     <string name="unfavorite">Unset as available offline</string>
     <string name="favorite_real">Set as favorite</string>
@@ -543,6 +544,8 @@
     <string name="local_file_not_found_toast">File not found in local file system</string>
     <string name="confirmation_remove_files_alert">Do you really want to remove the selected items?</string>
     <string name="confirmation_remove_folders_alert">Do you really want to remove the selected items and their contents?</string>
+    <string name="maintenance_mode">Server in maintenance mode</string>
+
     <string name="uploads_view_upload_status_waiting_for_charging">Awaiting charge</string>
     <string name="actionbar_search">Search</string>
     <string name="files_drop_not_supported">This is a Nextcloud feature, please update.</string>