blob: 8d9a62a54b2b796fb27da8e509648eb8cb262634 [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
31 private static final String TAG = AccountCredentials.class.getSimpleName();
32
33 public static final String CONFIG_ACCOUNT_USERNAME = "Account.username";
34 public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password";
35 public static final String CONFIG_ACCOUNT_REALM = "Account.realm";
Alexandre Lision3b7148e2013-11-13 17:23:06 -050036
37 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
38
39 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
40 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
41
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -050042 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERNAME));
43 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_PASSWORD));
44 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REALM));
Alexandre Lision3b7148e2013-11-13 17:23:06 -050045
46 return preference;
47 }
48
Alexandre Lision3b7148e2013-11-13 17:23:06 -050049 public AccountCredentials(HashMap<String, String> pref) {
50 privateArray = getPreferenceEntries();
51
52 for (AccountDetail.PreferenceEntry p : privateArray) {
53 p.mValue = pref.get(p.mKey);
54 }
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -050055
Alexandre Lision3b7148e2013-11-13 17:23:06 -050056 }
57
Alexandre Lision3b7148e2013-11-13 17:23:06 -050058 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
59 return privateArray;
60 }
61
62 public ArrayList<String> getValuesOnly() {
63 ArrayList<String> valueList = new ArrayList<String>();
64
65 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Lision3b7148e2013-11-13 17:23:06 -050066 valueList.add(p.mValue);
67 }
68
69 return valueList;
70 }
71
72 public HashMap<String, String> getDetailsHashMap() {
73 HashMap<String, String> map = new HashMap<String, String>();
74
75 for (AccountDetail.PreferenceEntry p : privateArray) {
76 map.put(p.mKey, p.mValue);
77 }
78
79 return map;
80 }
81
82 public String getDetailString(String key) {
83 String value = "";
84
85 for (AccountDetail.PreferenceEntry p : privateArray) {
86 if (p.mKey.equals(key)) {
87 value = p.mValue;
88 return value;
89 }
90 }
91 return value;
92 }
93
94 public void setDetailString(String key, String newValue) {
95 for (int i = 0; i < privateArray.size(); ++i) {
96 PreferenceEntry p = privateArray.get(i);
97 if (p.mKey.equals(key)) {
98 privateArray.get(i).mValue = newValue;
99 }
100 }
101
102 }
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -0500103
Alexandre Lision3cefec22013-11-14 17:26:35 -0500104 @Override
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -0500105 public boolean equals(Object other) {
106 if (other instanceof AccountCredentials)
107 return ((AccountCredentials) other).getDetailsHashMap().get(CONFIG_ACCOUNT_USERNAME)
108 .contentEquals(getDetailString(CONFIG_ACCOUNT_USERNAME))
109 && ((AccountCredentials) other).getDetailsHashMap().get(CONFIG_ACCOUNT_PASSWORD)
110 .contentEquals(getDetailString(CONFIG_ACCOUNT_PASSWORD))
111 && ((AccountCredentials) other).getDetailsHashMap().get(CONFIG_ACCOUNT_REALM)
112 .contentEquals(getDetailString(CONFIG_ACCOUNT_REALM));
113
Alexandre Lision3cefec22013-11-14 17:26:35 -0500114 return false;
115 }
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500116
117}