1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.accountswitcher;
20
21 import org.exoplatform.model.ExoAccount;
22 import org.exoplatform.ui.login.LoginProxy;
23 import org.exoplatform.utils.SettingUtils;
24
25 import android.content.Context;
26 import android.os.Bundle;
27 import android.util.Log;
28
29
30
31
32
33 public class AccountSwitcherProxy implements LoginProxy.ProxyListener {
34
35 private Context mContext;
36
37 private AccountSwitcherListener mListener;
38
39 private boolean mIgnoreRememberMe = false;
40
41 public static final String TAG = "eXo____AccountSwitcherController____";
42
43 public AccountSwitcherProxy(Context c, AccountSwitcherListener l, boolean ignore) {
44 mContext = c;
45 mListener = l;
46 mIgnoreRememberMe = ignore;
47 }
48
49
50
51
52
53
54
55
56 public void switchToAccount(ExoAccount account) {
57 if (account == null || account.serverUrl == null || account.serverUrl.isEmpty()) {
58
59 if (mListener != null)
60 mListener.onAccountInvalid(account);
61 } else if (account.username == null || account.username.isEmpty()
62 || account.password == null || account.password.isEmpty()
63 || (!mIgnoreRememberMe && !account.isRememberEnabled)) {
64
65
66 if (mListener != null)
67 mListener.onMissingPassword(account);
68 } else {
69 Log.i(TAG, "Switching to account " + account.accountName);
70
71
72 Bundle params = new Bundle();
73 params.putString(LoginProxy.USERNAME, account.username);
74 params.putString(LoginProxy.PASSWORD, account.password);
75 params.putString(LoginProxy.DOMAIN, account.serverUrl);
76 params.putString(LoginProxy.ACCOUNT_NAME, account.accountName);
77
78
79
80
81 SettingUtils.disableAutoLogin(mContext);
82 LoginProxy login = new LoginProxy(mContext, LoginProxy.SWITCH_ACCOUNT, params);
83 login.setListener(this);
84 login.performLogin();
85 }
86 }
87
88
89
90
91 @Override
92 public void onLoginFinished(boolean result) {
93 if (mListener != null)
94 mListener.onSwitchAccountFinished(result);
95 }
96
97
98
99
100
101
102 public interface AccountSwitcherListener {
103
104
105
106
107
108 public void onSwitchAccountFinished(boolean result);
109
110
111
112
113
114
115
116 public void onMissingPassword(ExoAccount account);
117
118
119
120
121
122
123 public void onAccountInvalid(ExoAccount account);
124 }
125
126 }