blob: bec769e4d0b5dccd55c1bb57ea524e2906458429 [file] [log] [blame]
Adrien BĂ©raud04d822c2015-04-02 17:44:36 -04001/**
2 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Savard <alexandre.savard@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 */
22package cx.ring.model.account;
23
24import java.util.ArrayList;
25import java.util.HashMap;
26
27import android.util.Log;
28
29public class AccountDetailBasic implements AccountDetail {
30
31 private static final String TAG = AccountDetailBasic.class.getSimpleName();
32
33 public static final String CONFIG_ACCOUNT_ALIAS = "Account.alias";
34 public static final String CONFIG_ACCOUNT_HOSTNAME = "Account.hostname";
35 public static final String CONFIG_ACCOUNT_USERNAME = "Account.username";
36 public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password";
37
38 public static final String CONFIG_ACCOUNT_USERAGENT = "Account.useragent";
39 public static final String CONFIG_ACCOUNT_ROUTESET = "Account.routeset";
40 public static final String CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer";
41
42 public static final String CONFIG_ACCOUNT_REALM = "Account.realm";
43 public static final String CONFIG_ACCOUNT_TYPE = "Account.type";
44 public static final String CONFIG_ACCOUNT_ENABLE = "Account.enable";
45 public static final String CONFIG_PRESENCE_ENABLE = "Account.presenceEnabled";
46
47 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
48
49 public AccountDetailBasic(HashMap<String, String> pref) {
50 privateArray = new ArrayList<AccountDetail.PreferenceEntry>();
51
52 for (String key : pref.keySet()) {
53 PreferenceEntry p = new PreferenceEntry(key);
54 p.mValue = pref.get(key);
55
56 if(key.contentEquals(CONFIG_ACCOUNT_ENABLE) || key.contentEquals(CONFIG_ACCOUNT_AUTOANSWER))
57 p.isTwoState = true;
58
59 privateArray.add(p);
60 }
61 }
62
63 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
64 return privateArray;
65 }
66
67 public ArrayList<String> getValuesOnly() {
68 ArrayList<String> valueList = new ArrayList<String>();
69
70 for (AccountDetail.PreferenceEntry p : privateArray) {
71 Log.i(TAG, "" + p.mValue);
72 valueList.add(p.mValue);
73 }
74
75 return valueList;
76 }
77
78 public HashMap<String, String> getDetailsHashMap() {
79 HashMap<String, String> map = new HashMap<String, String>();
80
81 for (AccountDetail.PreferenceEntry p : privateArray) {
82 map.put(p.mKey, p.mValue);
83 }
84
85 return map;
86 }
87
88 public String getDetailString(String key) {
89 String value = "";
90
91 for (AccountDetail.PreferenceEntry p : privateArray) {
92 if (p.mKey.equals(key)) {
93 value = p.mValue;
94 return value;
95 }
96 }
97
98 return value;
99 }
100
101 public void setDetailString(String key, String newValue) {
102 for (int i = 0; i < privateArray.size(); ++i) {
103 PreferenceEntry p = privateArray.get(i);
104 if (p.mKey.equals(key)) {
105 privateArray.get(i).mValue = newValue;
106 }
107 }
108
109 }
110
111}