blob: baeb12f1fb58c7edda1affe14b174b749f05f329 [file] [log] [blame]
Alexandre Lision3b7148e2013-11-13 17:23:06 -05001package org.sflphone.account;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5
6import org.sflphone.R;
7
8import android.util.Log;
9
10public class AccountCredentials implements AccountDetail {
11
12 private static final String TAG = AccountCredentials.class.getSimpleName();
13
14 public static final String CONFIG_ACCOUNT_USERNAME = "Account.username";
15 public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password";
16 public static final String CONFIG_ACCOUNT_REALM = "Account.realm";
17
18
19 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
20
21 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
22 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
23
24 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERNAME, R.string.account_username_label));
25 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_PASSWORD, R.string.account_password_label));
26 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REALM, R.string.account_realm_label));
27
28 return preference;
29 }
30
31 public AccountCredentials() {
32 privateArray = getPreferenceEntries();
33 }
34
35 public AccountCredentials(HashMap<String, String> pref) {
36 privateArray = getPreferenceEntries();
37
38 for (AccountDetail.PreferenceEntry p : privateArray) {
39 p.mValue = pref.get(p.mKey);
40 }
41 }
42
43 public AccountCredentials(ArrayList<String> pref) {
44 privateArray = getPreferenceEntries();
45
46 if (pref.size() != privateArray.size()) {
47 Log.i(TAG, "Error list are not of equal size");
48 } else {
49 int index = 0;
50 for (String s : pref) {
51 privateArray.get(index).mValue = s;
52 index++;
53 }
54 }
55 }
56
57 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
58 return privateArray;
59 }
60
61 public ArrayList<String> getValuesOnly() {
62 ArrayList<String> valueList = new ArrayList<String>();
63
64 for (AccountDetail.PreferenceEntry p : privateArray) {
65 Log.i(TAG, "" + p.mValue);
66 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 }
103
104}