adjusting design to holo, stability for account setup
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / AccountUtils.java
index 4077775..9e1b124 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
@@ -29,15 +30,18 @@ import android.preference.PreferenceManager;
 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 WEBDAV_PATH_4_0 = "/remote/webdav.php";\r
   public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";\r
-  \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 preferences\r
    * \r
    * @param context The current appContext\r
-   * @return The current account or null, if there is none yet.\r
+   * @return The current account or first available, if none is available, then null.\r
    */\r
-  public static Account getCurrentOwnCloudAccount(Context context){\r
+  public static Account getCurrentOwnCloudAccount(Context context) {\r
          Account[] ocAccounts = AccountManager.get(context).getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);\r
          Account defaultAccount = null;\r
          \r
@@ -58,4 +62,27 @@ public class AccountUtils {
          \r
        return defaultAccount;\r
   }\r
+  \r
+  public static void setCurrentOwnCloudAccount(Context context, String name) {\r
+    SharedPreferences.Editor appPrefs = PreferenceManager.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