Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /** |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * If you own a pjsip commercial license you can also redistribute it |
| 11 | * and/or modify it under the terms of the GNU Lesser General Public License |
| 12 | * as an android library. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 22 | package org.sflphone.account; |
| 23 | |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.HashMap; |
| 26 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
| 29 | public class AccountCredentials implements AccountDetail { |
| 30 | |
Alexandre Lision | 06412a3 | 2014-02-05 17:33:04 -0500 | [diff] [blame] | 31 | @SuppressWarnings("unused") |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 32 | private static final String TAG = AccountCredentials.class.getSimpleName(); |
| 33 | |
| 34 | public static final String CONFIG_ACCOUNT_USERNAME = "Account.username"; |
| 35 | public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password"; |
| 36 | public static final String CONFIG_ACCOUNT_REALM = "Account.realm"; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 37 | |
| 38 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
| 39 | |
| 40 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() { |
| 41 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 42 | |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 43 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERNAME)); |
| 44 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_PASSWORD)); |
| 45 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REALM)); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 46 | |
| 47 | return preference; |
| 48 | } |
| 49 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 50 | public AccountCredentials(HashMap<String, String> pref) { |
| 51 | privateArray = getPreferenceEntries(); |
| 52 | |
| 53 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 54 | p.mValue = pref.get(p.mKey); |
| 55 | } |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 56 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 57 | } |
| 58 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 59 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() { |
| 60 | return privateArray; |
| 61 | } |
| 62 | |
| 63 | public ArrayList<String> getValuesOnly() { |
| 64 | ArrayList<String> valueList = new ArrayList<String>(); |
| 65 | |
| 66 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 67 | valueList.add(p.mValue); |
| 68 | } |
| 69 | |
| 70 | return valueList; |
| 71 | } |
| 72 | |
| 73 | public HashMap<String, String> getDetailsHashMap() { |
| 74 | HashMap<String, String> map = new HashMap<String, String>(); |
| 75 | |
| 76 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 77 | map.put(p.mKey, p.mValue); |
| 78 | } |
| 79 | |
| 80 | return map; |
| 81 | } |
| 82 | |
| 83 | public String getDetailString(String key) { |
| 84 | String value = ""; |
| 85 | |
| 86 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 87 | if (p.mKey.equals(key)) { |
| 88 | value = p.mValue; |
| 89 | return value; |
| 90 | } |
| 91 | } |
| 92 | return value; |
| 93 | } |
| 94 | |
| 95 | public void setDetailString(String key, String newValue) { |
| 96 | for (int i = 0; i < privateArray.size(); ++i) { |
| 97 | PreferenceEntry p = privateArray.get(i); |
| 98 | if (p.mKey.equals(key)) { |
| 99 | privateArray.get(i).mValue = newValue; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | } |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 104 | |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 105 | @Override |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 106 | public boolean equals(Object other) { |
| 107 | if (other instanceof AccountCredentials) |
| 108 | return ((AccountCredentials) other).getDetailsHashMap().get(CONFIG_ACCOUNT_USERNAME) |
| 109 | .contentEquals(getDetailString(CONFIG_ACCOUNT_USERNAME)) |
| 110 | && ((AccountCredentials) other).getDetailsHashMap().get(CONFIG_ACCOUNT_PASSWORD) |
| 111 | .contentEquals(getDetailString(CONFIG_ACCOUNT_PASSWORD)) |
| 112 | && ((AccountCredentials) other).getDetailsHashMap().get(CONFIG_ACCOUNT_REALM) |
| 113 | .contentEquals(getDetailString(CONFIG_ACCOUNT_REALM)); |
| 114 | |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 115 | return false; |
| 116 | } |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 117 | |
| 118 | } |