|
@@ -4,8 +4,9 @@ import android.accounts.Account;
|
4
|
4
|
import android.accounts.AccountAuthenticatorResponse;
|
5
|
5
|
import android.accounts.AccountManager;
|
6
|
6
|
import android.app.Activity;
|
7
|
|
-import android.support.v7.app.AppCompatActivity;
|
|
7
|
+import android.net.Uri;
|
8
|
8
|
import android.os.Bundle;
|
|
9
|
+import android.support.v7.app.AppCompatActivity;
|
9
|
10
|
import android.view.View;
|
10
|
11
|
import android.widget.CheckBox;
|
11
|
12
|
import android.widget.EditText;
|
|
@@ -13,10 +14,13 @@ import android.widget.Toast;
|
13
|
14
|
|
14
|
15
|
import com.luticate.auth.dbo.LuLoginDbo;
|
15
|
16
|
import com.luticate.utils.business.LuPromise;
|
|
17
|
+import com.luticate.utils.business.LuRequest;
|
16
|
18
|
import com.rthoni.camotion.R;
|
17
|
19
|
import com.rthoni.camotion.dbo.LocationDbo;
|
18
|
20
|
import com.rthoni.camotion.ui.dialogs.LoginDialog;
|
19
|
21
|
|
|
22
|
+import org.json.JSONObject;
|
|
23
|
+
|
20
|
24
|
public class AddAccountActivity extends AppCompatActivity {
|
21
|
25
|
|
22
|
26
|
private EditText _nameInput;
|
|
@@ -30,6 +34,7 @@ public class AddAccountActivity extends AppCompatActivity {
|
30
|
34
|
@Override
|
31
|
35
|
protected void onCreate(Bundle savedInstanceState) {
|
32
|
36
|
super.onCreate(savedInstanceState);
|
|
37
|
+ LuRequest.init(this);
|
33
|
38
|
setContentView(R.layout.activity_add_account);
|
34
|
39
|
_nameInput = (EditText) findViewById(R.id.name_input);
|
35
|
40
|
_usernameInput = (EditText) findViewById(R.id.username_input);
|
|
@@ -56,6 +61,26 @@ public class AddAccountActivity extends AppCompatActivity {
|
56
|
61
|
if (extras != null) {
|
57
|
62
|
_response = extras.getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
|
58
|
63
|
}
|
|
64
|
+
|
|
65
|
+ LocationDbo location = new LocationDbo();
|
|
66
|
+ location.setHttps(true);
|
|
67
|
+ try {
|
|
68
|
+ String data = getIntent().getDataString();
|
|
69
|
+ Uri uri= Uri.parse(data);;
|
|
70
|
+ String config = uri.getQueryParameter("config");
|
|
71
|
+
|
|
72
|
+ JSONObject json = new JSONObject(config);
|
|
73
|
+
|
|
74
|
+ location.fromJson(json);
|
|
75
|
+ }
|
|
76
|
+ catch (Exception e)
|
|
77
|
+ {
|
|
78
|
+ }
|
|
79
|
+ _nameInput.setText(location.getName());
|
|
80
|
+ _usernameInput.setText(location.getUsername());
|
|
81
|
+ _passwordInput.setText(location.getPassword());
|
|
82
|
+ _domainInput.setText(location.getDomain());
|
|
83
|
+ _checkBoxHttps.setChecked(location.isHttps());
|
59
|
84
|
}
|
60
|
85
|
|
61
|
86
|
private LocationDbo validate()
|
|
@@ -107,13 +132,15 @@ public class AddAccountActivity extends AppCompatActivity {
|
107
|
132
|
Account newUserAccount = new Account(username, getResources().getString(R.string.account_type));
|
108
|
133
|
boolean accountCreated = accountManager.addAccountExplicitly(newUserAccount, location.getPassword(), null);
|
109
|
134
|
|
110
|
|
- if (accountCreated && _response != null) {
|
|
135
|
+ if (accountCreated) {
|
111
|
136
|
accountManager.setUserData(newUserAccount, "Https", location.isHttps() ? "true" : "false");
|
112
|
137
|
accountManager.setUserData(newUserAccount, "Domain", location.getDomain());
|
113
|
138
|
Bundle result = new Bundle();
|
114
|
139
|
result.putString(AccountManager.KEY_ACCOUNT_NAME, username);
|
115
|
140
|
result.putString(AccountManager.KEY_ACCOUNT_TYPE, getString(R.string.account_type));
|
116
|
|
- _response.onResult(result);
|
|
141
|
+ if (_response != null) {
|
|
142
|
+ _response.onResult(result);
|
|
143
|
+ }
|
117
|
144
|
finish();
|
118
|
145
|
}
|
119
|
146
|
}
|