X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/fbd720e8874d5adcfd0dcc5aa8c602ecb54ef83c..2a95f59adc2bdd8f8a90cab8fd8d28f90bf9fc68:/src/com/owncloud/android/AccountUtils.java diff --git a/src/com/owncloud/android/AccountUtils.java b/src/com/owncloud/android/AccountUtils.java index 49b0a62d..f064ce2d 100644 --- a/src/com/owncloud/android/AccountUtils.java +++ b/src/com/owncloud/android/AccountUtils.java @@ -1,10 +1,10 @@ /* ownCloud Android client application * Copyright (C) 2012 Bartek Przybylski + * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -60,7 +60,9 @@ public class AccountUtils { break; } } - } else if (ocAccounts.length != 0) { + } + + if (defaultAccount == null && ocAccounts.length != 0) { // we at least need to take first account as fallback defaultAccount = ocAccounts[0]; } @@ -83,11 +85,26 @@ public class AccountUtils { } - public static void setCurrentOwnCloudAccount(Context context, String name) { - SharedPreferences.Editor appPrefs = PreferenceManager - .getDefaultSharedPreferences(context).edit(); - appPrefs.putString("select_oc_account", name); - appPrefs.commit(); + public static boolean setCurrentOwnCloudAccount(Context context, String accountName) { + boolean result = false; + if (accountName != null) { + Account[] ocAccounts = AccountManager.get(context).getAccountsByType( + AccountAuthenticator.ACCOUNT_TYPE); + boolean found = false; + for (Account account : ocAccounts) { + found = (account.name.equals(accountName)); + if (found) { + SharedPreferences.Editor appPrefs = PreferenceManager + .getDefaultSharedPreferences(context).edit(); + appPrefs.putString("select_oc_account", accountName); + + appPrefs.commit(); + result = true; + break; + } + } + } + return result; } /** @@ -107,5 +124,27 @@ public class AccountUtils { } return null; } + + /** + * Constructs full url to host and webdav resource basing on host version + * @param context + * @param account + * @return url or null on failure + */ + public static String constructFullURLForAccount(Context context, Account account) { + try { + AccountManager ama = AccountManager.get(context); + String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL); + String strver = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION); + OwnCloudVersion ver = new OwnCloudVersion(strver); + String webdavpath = getWebdavPath(ver); + + if (webdavpath == null) return null; + return baseurl + webdavpath; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } }