Browse Source

Add specific message(s) for network error(s) in strings.xml

masensio 11 years ago
parent
commit
db43531874
2 changed files with 38 additions and 1 deletions
  1. 7 0
      res/values/strings.xml
  2. 31 1
      src/com/owncloud/android/utils/ErrorMessageAdapter.java

+ 7 - 0
res/values/strings.xml

@@ -274,4 +274,11 @@
 	<string name="clipboard_text_copied">Copied to clipboard</string>
 	<string name="clipboard_text_copied">Copied to clipboard</string>
 
 
 	<string name="error_cant_bind_to_operations_service">Critical error: can not perform operations</string>
 	<string name="error_cant_bind_to_operations_service">Critical error: can not perform operations</string>
+	
+	<string name="network_error_socket_exception">An error occurred while connecting with the server.</string>
+	<string name="network_error_socket_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
+	<string name="network_error_connect_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
+	<string name="unexpected_exception">Unexpected exception</string>
+	
+	
 </resources>
 </resources>

+ 31 - 1
src/com/owncloud/android/utils/ErrorMessageAdapter.java

@@ -19,7 +19,8 @@
 package com.owncloud.android.utils;
 package com.owncloud.android.utils;
 
 
 import java.io.File;
 import java.io.File;
-
+import java.net.SocketTimeoutException;
+import org.apache.commons.httpclient.ConnectTimeoutException;
 import android.content.res.Resources;
 import android.content.res.Resources;
 
 
 import com.owncloud.android.R;
 import com.owncloud.android.R;
@@ -75,6 +76,35 @@ public class ErrorMessageAdapter {
             }
             }
         }
         }
         
         
+        
+        return message;
+    }
+    
+    public static String getErrorMessage(RemoteOperationResult result , Resources res) {
+        
+        String message = null;
+        
+        if (!result.isSuccess()) {
+            
+            switch (result.getCode()) {
+            case WRONG_CONNECTION:
+                message = res.getString(R.string.network_error_socket_exception);
+                break;
+                
+            case TIMEOUT:
+                if (result.getException() instanceof SocketTimeoutException) {
+                    message = res.getString(R.string.network_error_socket_timeout_exception);
+                } else if(result.getException() instanceof ConnectTimeoutException) {
+                    message = res.getString(R.string.network_error_connect_timeout_exception);
+                } 
+                break;
+                
+            default:
+                message = res.getString(R.string.unexpected_exception);
+                break;
+            }
+        }
+        
         return message;
         return message;
     }
     }
 }
 }