cached instant upload
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / AccountUtils.java
index 4077775..090dec3 100644 (file)
@@ -1,5 +1,5 @@
 /* ownCloud Android client application\r
- *   Copyright (C) 2011  Bartek Przybylski\r
+ *   Copyright (C) 2012  Bartek Przybylski\r
  *\r
  *   This program is free software: you can redistribute it and/or modify\r
  *   it under the terms of the GNU General Public License as published by\r
@@ -19,6 +19,7 @@
 package eu.alefzero.owncloud;\r
 \r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
+import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
@@ -27,35 +28,67 @@ import android.content.SharedPreferences;
 import android.preference.PreferenceManager;\r
 \r
 public class AccountUtils {\r
-  public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";\r
-  public static final String WEBDAV_PATH_2_0 = "/files/webdav.php";\r
-  public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";\r
-  \r
-  /**\r
-   * Can be used to get the currently selected ownCloud account in the preferences\r
-   * \r
-   * @param context The current appContext\r
-   * @return The current account or null, if there is none yet.\r
-   */\r
-  public static Account getCurrentOwnCloudAccount(Context context){\r
-         Account[] ocAccounts = AccountManager.get(context).getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);\r
-         Account defaultAccount = null;\r
-         \r
-         SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);\r
-         String accountName = appPreferences.getString("select_oc_account", null);\r
-         \r
-         if(accountName != null){\r
-                 for(Account account : ocAccounts){\r
-                         if(account.name.equals(accountName)){\r
-                                 defaultAccount = account;\r
-                                 break;\r
-                         }\r
-                 }\r
-         } else if (ocAccounts.length != 0) {\r
-           // we at least need to take first account as fallback\r
-           defaultAccount = ocAccounts[0];\r
-         }\r
-         \r
-       return defaultAccount;\r
-  }\r
+    public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";\r
+    public static final String WEBDAV_PATH_2_0 = "/files/webdav.php";\r
+    public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";\r
+    public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";\r
+    public static final String CARDDAV_PATH_4_0 = "/remote/carddav.php";\r
+    public static final String STATUS_PATH = "/status.php";\r
+\r
+    /**\r
+     * Can be used to get the currently selected ownCloud account in the\r
+     * preferences\r
+     * \r
+     * @param context The current appContext\r
+     * @return The current account or first available, if none is available,\r
+     *         then null.\r
+     */\r
+    public static Account getCurrentOwnCloudAccount(Context context) {\r
+        Account[] ocAccounts = AccountManager.get(context).getAccountsByType(\r
+                AccountAuthenticator.ACCOUNT_TYPE);\r
+        Account defaultAccount = null;\r
+\r
+        SharedPreferences appPreferences = PreferenceManager\r
+                .getDefaultSharedPreferences(context);\r
+        String accountName = appPreferences\r
+                .getString("select_oc_account", null);\r
+\r
+        if (accountName != null) {\r
+            for (Account account : ocAccounts) {\r
+                if (account.name.equals(accountName)) {\r
+                    defaultAccount = account;\r
+                    break;\r
+                }\r
+            }\r
+        } else if (ocAccounts.length != 0) {\r
+            // we at least need to take first account as fallback\r
+            defaultAccount = ocAccounts[0];\r
+        }\r
+\r
+        return defaultAccount;\r
+    }\r
+\r
+    public static void setCurrentOwnCloudAccount(Context context, String name) {\r
+        SharedPreferences.Editor appPrefs = PreferenceManager\r
+                .getDefaultSharedPreferences(context).edit();\r
+        appPrefs.putString("select_oc_account", name);\r
+        appPrefs.commit();\r
+    }\r
+\r
+    /**\r
+     * \r
+     * @param version version of owncloud\r
+     * @return webdav path for given OC version, null if OC version unknown\r
+     */\r
+    public static String getWebdavPath(OwnCloudVersion version) {\r
+        if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0)\r
+            return WEBDAV_PATH_4_0;\r
+        if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0\r
+                || version.compareTo(OwnCloudVersion.owncloud_v2) >= 0)\r
+            return WEBDAV_PATH_2_0;\r
+        if (version.compareTo(OwnCloudVersion.owncloud_v1) >= 0)\r
+            return WEBDAV_PATH_1_2;\r
+        return null;\r
+    }\r
+\r
 }\r