1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.singleton;
20
21 import java.util.ArrayList;
22
23 import org.exoplatform.model.ExoAccount;
24
25 import android.os.Parcel;
26 import android.os.Parcelable;
27
28
29
30
31
32
33
34 public class AccountSetting implements Parcelable {
35
36 private static AccountSetting accountSetting = new AccountSetting();
37
38
39
40
41 private String domainIndex;
42
43
44
45
46 public String socialKey;
47
48
49
50
51 public String socialKeyIndex;
52
53
54
55
56 public String documentKey;
57
58 public ArrayList<String> cookiesList;
59
60
61 private ExoAccount mCurrentAccount;
62
63 private AccountSetting() {
64 }
65
66 public static AccountSetting getInstance() {
67 return accountSetting;
68 }
69
70 public void setInstance(AccountSetting instance) {
71 accountSetting = instance;
72 }
73
74 public ExoAccount getCurrentAccount() {
75 return mCurrentAccount;
76 }
77
78 public void setCurrentAccount(ExoAccount acc) {
79 mCurrentAccount = acc;
80 }
81
82 public String getUsername() {
83 return (mCurrentAccount != null) ? mCurrentAccount.username : "";
84 }
85
86 public String getPassword() {
87 return (mCurrentAccount != null) ? mCurrentAccount.password : "";
88 }
89
90 public String getDomainName() {
91 return (mCurrentAccount != null) ? mCurrentAccount.serverUrl : "";
92 }
93
94 public String getServerName() {
95 return (mCurrentAccount != null) ? mCurrentAccount.accountName : "";
96 }
97
98 public String getUserFullName() {
99 return (mCurrentAccount != null) ? mCurrentAccount.userFullName : "";
100 }
101
102 public String getUserAvatarUrl() {
103 return (mCurrentAccount != null) ? mCurrentAccount.avatarUrl : "";
104 }
105
106 public boolean shouldSaveProfileInfo(String newUserFullName, String newUserAvatarUrl) {
107 boolean shouldSave = false;
108 if (!getUserFullName().equalsIgnoreCase(newUserFullName)) {
109 mCurrentAccount.userFullName = newUserFullName;
110 shouldSave = true;
111 }
112 if (!getUserAvatarUrl().equalsIgnoreCase(newUserAvatarUrl)) {
113 mCurrentAccount.avatarUrl = newUserAvatarUrl;
114 shouldSave = true;
115 }
116 return shouldSave;
117 }
118
119
120
121
122
123
124
125 public boolean isAutoLoginEnabled() {
126 return (mCurrentAccount != null) ? mCurrentAccount.isAutoLoginEnabled : false;
127 }
128
129
130
131
132
133
134
135 public boolean isRememberMeEnabled() {
136 return (mCurrentAccount != null) ? mCurrentAccount.isRememberEnabled : false;
137 }
138
139 public String getDomainIndex() {
140 return (domainIndex == null) ? "-1" : domainIndex;
141 }
142
143 public void setDomainIndex(String index) {
144 domainIndex = index;
145 }
146
147
148
149
150 public void clear() {
151 socialKey = null;
152 socialKeyIndex = null;
153 documentKey = null;
154 cookiesList = null;
155 }
156
157 private AccountSetting(Parcel in) {
158 readFromParcel(in);
159 }
160
161 public void readFromParcel(Parcel in) {
162 domainIndex = in.readString();
163 mCurrentAccount = in.readParcelable(ExoAccount.class.getClassLoader());
164 cookiesList = new ArrayList<String>();
165 in.readStringList(cookiesList);
166
167 }
168
169 public static final Parcelable.Creator<AccountSetting> CREATOR = new Parcelable.Creator<AccountSetting>() {
170 public AccountSetting createFromParcel(Parcel in) {
171 return new AccountSetting(in);
172 }
173
174 public AccountSetting[] newArray(int size) {
175 return new AccountSetting[size];
176 }
177 };
178
179
180
181
182
183 @Override
184 public int describeContents() {
185 return 0;
186 }
187
188
189
190
191
192 @Override
193 public void writeToParcel(Parcel par, int flags) {
194 par.writeString(domainIndex);
195 par.writeParcelable(mCurrentAccount, flags);
196 par.writeStringList(cookiesList);
197 }
198
199 }