Add specific message(s) for network error(s) in strings.xml
authormasensio <masensio@solidgear.es>
Mon, 26 May 2014 11:00:22 +0000 (13:00 +0200)
committermasensio <masensio@solidgear.es>
Mon, 26 May 2014 11:00:22 +0000 (13:00 +0200)
res/values/strings.xml
src/com/owncloud/android/utils/ErrorMessageAdapter.java

index 19d006d..23a001a 100644 (file)
        <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="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>
index 3baf72b..411ade5 100644 (file)
@@ -19,7 +19,8 @@
 package com.owncloud.android.utils;
 
 import java.io.File;
-
+import java.net.SocketTimeoutException;
+import org.apache.commons.httpclient.ConnectTimeoutException;
 import android.content.res.Resources;
 
 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;
     }
 }