Skip to content

Commit

Permalink
Merge branch 'bugfix/popup-empty-passwd-check' into 'master'
Browse files Browse the repository at this point in the history
Fixed askForNetwork() dialog box issue

See merge request idf/esp-idf-provisioning-android!55
  • Loading branch information
shahpiyushv committed Apr 26, 2022
2 parents bc40ea5 + 4a483f9 commit 0e54de2
Showing 1 changed file with 48 additions and 49 deletions.
97 changes: 48 additions & 49 deletions app/src/main/java/com/espressif/ui/activities/WiFiScanActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
Expand Down Expand Up @@ -205,82 +206,80 @@ private void completeWifiList() {

private void askForNetwork(final String ssid, final int authMode) {

final AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.dialog_wifi_network, null);
builder.setView(dialogView);

final EditText etSsid = dialogView.findViewById(R.id.et_ssid);
final EditText etPassword = dialogView.findViewById(R.id.et_password);

if (ssid.equals(getString(R.string.join_other_network))) {

builder.setTitle(R.string.dialog_title_network_info);

} else {

builder.setTitle(ssid);
String title = getString(R.string.join_other_network);
if (!ssid.equals(title)) {
title = ssid;
etSsid.setVisibility(View.GONE);
}

builder.setPositiveButton(R.string.btn_provision, new DialogInterface.OnClickListener() {
final AlertDialog alertDialog = new AlertDialog.Builder(this)
.setView(dialogView)
.setTitle(title)
.setPositiveButton(R.string.btn_provision, null)
.setNegativeButton(R.string.btn_cancel, null)
.create();

alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

String password = etPassword.getText().toString();

if (ssid.equals(getString(R.string.join_other_network))) {
public void onShow(DialogInterface dialog) {

String networkName = etSsid.getText().toString();
Button buttonPositive = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
buttonPositive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String password = etPassword.getText().toString();

if (TextUtils.isEmpty(networkName)) {
if (ssid.equals(getString(R.string.join_other_network))) {

etSsid.setError(getString(R.string.error_ssid_empty));
String networkName = etSsid.getText().toString();

} else {
if (TextUtils.isEmpty(networkName)) {
etSsid.setError(getString(R.string.error_ssid_empty));

dialog.dismiss();
goForProvisioning(networkName, password);
}
} else {
dialog.dismiss();
goForProvisioning(networkName, password);
}

} else {
} else {

if (TextUtils.isEmpty(password)) {
if (TextUtils.isEmpty(password)) {

if (authMode != ESPConstants.WIFI_OPEN) {
if (authMode != ESPConstants.WIFI_OPEN) {
TextInputLayout passwordLayout = dialogView.findViewById(R.id.layout_password);
passwordLayout.setError(getString(R.string.error_password_empty));

TextInputLayout passwordLayout = dialogView.findViewById(R.id.layout_password);
passwordLayout.setError(getString(R.string.error_password_empty));
} else {
dialog.dismiss();
goForProvisioning(ssid, password);
}

} else {
} else {

dialog.dismiss();
goForProvisioning(ssid, password);
}

} else {

if (authMode == ESPConstants.WIFI_OPEN) {
password = "";
if (authMode == ESPConstants.WIFI_OPEN) {
password = "";
}
dialog.dismiss();
goForProvisioning(ssid, password);
}
}
}
});
Button buttonNegative = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
buttonNegative.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
goForProvisioning(ssid, password);
}
}
}
});

builder.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();
});
}
});

AlertDialog alertDialog = builder.create();
alertDialog.show();
}

Expand Down

0 comments on commit 0e54de2

Please sign in to comment.