blob: e8182aec62f79943ba0afade2964cd2179941945 [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/**
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
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 Lision3b7148e2013-11-13 17:23:06 -050022package org.sflphone.account;
23
24import java.util.ArrayList;
25import java.util.HashMap;
26
Alexandre Lision3b7148e2013-11-13 17:23:06 -050027import android.util.Log;
28
29public class AccountCredentials implements AccountDetail {
30
Alexandre Lision06412a32014-02-05 17:33:04 -050031 @SuppressWarnings("unused")
Alexandre Lision3b7148e2013-11-13 17:23:06 -050032 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 Lision3b7148e2013-11-13 17:23:06 -050037
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 Lisionab0cc9f2013-12-12 11:27:25 -050043 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERNAME));
44 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_PASSWORD));
45 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REALM));
Alexandre Lision3b7148e2013-11-13 17:23:06 -050046
47 return preference;
48 }
49
Alexandre Lision3b7148e2013-11-13 17:23:06 -050050 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 Lisionab0cc9f2013-12-12 11:27:25 -050056
Alexandre Lision3b7148e2013-11-13 17:23:06 -050057 }
58
Alexandre Lision3b7148e2013-11-13 17:23:06 -050059 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 Lision3b7148e2013-11-13 17:23:06 -050067 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 Lisionab0cc9f2013-12-12 11:27:25 -0500104
Alexandre Lision3cefec22013-11-14 17:26:35 -0500105 @Override
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -0500106 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 Lision3cefec22013-11-14 17:26:35 -0500115 return false;
116 }
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500117
118}