|
23 | 23 | import android.view.LayoutInflater;
|
24 | 24 | import android.view.View;
|
25 | 25 | import android.widget.AdapterView;
|
| 26 | +import android.widget.Button; |
26 | 27 | import android.widget.EditText;
|
27 | 28 | import android.widget.ImageView;
|
28 | 29 | import android.widget.ListView;
|
@@ -205,82 +206,80 @@ private void completeWifiList() {
|
205 | 206 |
|
206 | 207 | private void askForNetwork(final String ssid, final int authMode) {
|
207 | 208 |
|
208 |
| - final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
209 | 209 | LayoutInflater inflater = this.getLayoutInflater();
|
210 | 210 | final View dialogView = inflater.inflate(R.layout.dialog_wifi_network, null);
|
211 |
| - builder.setView(dialogView); |
212 |
| - |
213 | 211 | final EditText etSsid = dialogView.findViewById(R.id.et_ssid);
|
214 | 212 | final EditText etPassword = dialogView.findViewById(R.id.et_password);
|
215 | 213 |
|
216 |
| - if (ssid.equals(getString(R.string.join_other_network))) { |
217 |
| - |
218 |
| - builder.setTitle(R.string.dialog_title_network_info); |
219 |
| - |
220 |
| - } else { |
221 |
| - |
222 |
| - builder.setTitle(ssid); |
| 214 | + String title = getString(R.string.join_other_network); |
| 215 | + if (!ssid.equals(title)) { |
| 216 | + title = ssid; |
223 | 217 | etSsid.setVisibility(View.GONE);
|
224 | 218 | }
|
225 | 219 |
|
226 |
| - builder.setPositiveButton(R.string.btn_provision, new DialogInterface.OnClickListener() { |
| 220 | + final AlertDialog alertDialog = new AlertDialog.Builder(this) |
| 221 | + .setView(dialogView) |
| 222 | + .setTitle(title) |
| 223 | + .setPositiveButton(R.string.btn_provision, null) |
| 224 | + .setNegativeButton(R.string.btn_cancel, null) |
| 225 | + .create(); |
227 | 226 |
|
| 227 | + alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { |
228 | 228 | @Override
|
229 |
| - public void onClick(DialogInterface dialog, int which) { |
230 |
| - |
231 |
| - String password = etPassword.getText().toString(); |
232 |
| - |
233 |
| - if (ssid.equals(getString(R.string.join_other_network))) { |
| 229 | + public void onShow(DialogInterface dialog) { |
234 | 230 |
|
235 |
| - String networkName = etSsid.getText().toString(); |
| 231 | + Button buttonPositive = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); |
| 232 | + buttonPositive.setOnClickListener(new View.OnClickListener() { |
| 233 | + @Override |
| 234 | + public void onClick(View view) { |
| 235 | + String password = etPassword.getText().toString(); |
236 | 236 |
|
237 |
| - if (TextUtils.isEmpty(networkName)) { |
| 237 | + if (ssid.equals(getString(R.string.join_other_network))) { |
238 | 238 |
|
239 |
| - etSsid.setError(getString(R.string.error_ssid_empty)); |
| 239 | + String networkName = etSsid.getText().toString(); |
240 | 240 |
|
241 |
| - } else { |
| 241 | + if (TextUtils.isEmpty(networkName)) { |
| 242 | + etSsid.setError(getString(R.string.error_ssid_empty)); |
242 | 243 |
|
243 |
| - dialog.dismiss(); |
244 |
| - goForProvisioning(networkName, password); |
245 |
| - } |
| 244 | + } else { |
| 245 | + dialog.dismiss(); |
| 246 | + goForProvisioning(networkName, password); |
| 247 | + } |
246 | 248 |
|
247 |
| - } else { |
| 249 | + } else { |
248 | 250 |
|
249 |
| - if (TextUtils.isEmpty(password)) { |
| 251 | + if (TextUtils.isEmpty(password)) { |
250 | 252 |
|
251 |
| - if (authMode != ESPConstants.WIFI_OPEN) { |
| 253 | + if (authMode != ESPConstants.WIFI_OPEN) { |
| 254 | + TextInputLayout passwordLayout = dialogView.findViewById(R.id.layout_password); |
| 255 | + passwordLayout.setError(getString(R.string.error_password_empty)); |
252 | 256 |
|
253 |
| - TextInputLayout passwordLayout = dialogView.findViewById(R.id.layout_password); |
254 |
| - passwordLayout.setError(getString(R.string.error_password_empty)); |
| 257 | + } else { |
| 258 | + dialog.dismiss(); |
| 259 | + goForProvisioning(ssid, password); |
| 260 | + } |
255 | 261 |
|
256 |
| - } else { |
| 262 | + } else { |
257 | 263 |
|
258 |
| - dialog.dismiss(); |
259 |
| - goForProvisioning(ssid, password); |
260 |
| - } |
261 |
| - |
262 |
| - } else { |
263 |
| - |
264 |
| - if (authMode == ESPConstants.WIFI_OPEN) { |
265 |
| - password = ""; |
| 264 | + if (authMode == ESPConstants.WIFI_OPEN) { |
| 265 | + password = ""; |
| 266 | + } |
| 267 | + dialog.dismiss(); |
| 268 | + goForProvisioning(ssid, password); |
| 269 | + } |
266 | 270 | }
|
| 271 | + } |
| 272 | + }); |
| 273 | + Button buttonNegative = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE); |
| 274 | + buttonNegative.setOnClickListener(new View.OnClickListener() { |
| 275 | + @Override |
| 276 | + public void onClick(View view) { |
267 | 277 | dialog.dismiss();
|
268 |
| - goForProvisioning(ssid, password); |
269 | 278 | }
|
270 |
| - } |
271 |
| - } |
272 |
| - }); |
273 |
| - |
274 |
| - builder.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() { |
275 |
| - |
276 |
| - @Override |
277 |
| - public void onClick(DialogInterface dialog, int which) { |
278 |
| - |
279 |
| - dialog.dismiss(); |
| 279 | + }); |
280 | 280 | }
|
281 | 281 | });
|
282 | 282 |
|
283 |
| - AlertDialog alertDialog = builder.create(); |
284 | 283 | alertDialog.show();
|
285 | 284 | }
|
286 | 285 |
|
|
0 commit comments