Merge pull request #918 from owncloud/share_password_support
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AccountUtils.java
index 33c7e6a..bd3a8e7 100644 (file)
@@ -1,6 +1,8 @@
-/* ownCloud Android client application\r
+/**\r
+ *   ownCloud Android client application\r
+ *\r
  *   Copyright (C) 2012  Bartek Przybylski\r
- *   Copyright (C) 2012-2013 ownCloud Inc.\r
+ *   Copyright (C) 2015 ownCloud Inc.\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 version 2,\r
 \r
 package com.owncloud.android.authentication;\r
 \r
+import java.util.Locale;\r
+\r
 import com.owncloud.android.MainApp;\r
-import com.owncloud.android.oc_framework.accounts.AccountTypeUtils;\r
-import com.owncloud.android.oc_framework.utils.OwnCloudVersion;\r
+import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
+import com.owncloud.android.lib.resources.status.OwnCloudVersion;\r
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
@@ -81,8 +85,18 @@ public class AccountUtils {
                 MainApp.getAccountType());\r
 \r
         if (account != null && account.name != null) {\r
-            for (Account ac : ocAccounts) {\r
-                if (ac.name.equals(account.name)) {\r
+            int lastAtPos = account.name.lastIndexOf("@");\r
+            String hostAndPort = account.name.substring(lastAtPos + 1);\r
+            String username = account.name.substring(0, lastAtPos);\r
+            String otherHostAndPort, otherUsername;\r
+            Locale currentLocale = context.getResources().getConfiguration().locale;\r
+            for (Account otherAccount : ocAccounts) {\r
+                lastAtPos = otherAccount.name.lastIndexOf("@");\r
+                otherHostAndPort = otherAccount.name.substring(lastAtPos + 1);\r
+                otherUsername = otherAccount.name.substring(0, lastAtPos);\r
+                if (otherHostAndPort.equals(hostAndPort) &&\r
+                        otherUsername.toLowerCase(currentLocale).\r
+                            equals(username.toLowerCase(currentLocale))) {\r
                     return true;\r
                 }\r
             }\r