Skip to content

Commit

Permalink
Merge pull request getodk#325 from devanshi7799/master
Browse files Browse the repository at this point in the history
worked on issue  getodk#233
  • Loading branch information
lakshyagupta21 authored Dec 14, 2019
2 parents e127ba9 + 0fb710c commit b74f527
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.odk.share.views.ui.settings;

import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -10,7 +11,9 @@
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -21,6 +24,7 @@
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;

import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;

import org.odk.share.R;
Expand All @@ -40,6 +44,8 @@ public class SettingsActivity extends PreferenceActivity {
EditTextPreference odkDestinationDirPreference;
ListPreference defaultMethodPreference;
private SharedPreferences prefs;
String npass;
TextInputEditText edtpass;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -177,25 +183,68 @@ private ViewGroup getRootView() {
}

private void showPasswordDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater factory = LayoutInflater.from(this);

View dialogView = factory.inflate(R.layout.dialog_password_til, null);

TextInputLayout tlPassword = dialogView.findViewById(R.id.et_password_layout);
tlPassword.getEditText().setText(prefs.getString(PreferenceKeys.KEY_HOTSPOT_PASSWORD, getString(R.string.default_hotspot_password)));

edtpass = (TextInputEditText) dialogView.findViewById(R.id.edtpass);

AlertDialog.Builder builder = new AlertDialog.Builder(this);
npass = prefs.getString(PreferenceKeys.KEY_HOTSPOT_PASSWORD, getString(R.string.default_hotspot_password));

builder.setTitle(getString(R.string.title_hotspot_password));
builder.setView(dialogView);
builder.setPositiveButton(getString(R.string.ok), (dialog, which) -> {


((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);

String password = tlPassword.getEditText().getText().toString();
prefs.edit().putString(PreferenceKeys.KEY_HOTSPOT_PASSWORD, password).apply();
});
builder.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());

builder.setCancelable(false);
AlertDialog alertDialog = builder.create();

alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

@Override
public void onShow(DialogInterface dialog) {

edtpass.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

if (edtpass.getText().toString().length() >= 8) {
((AlertDialog) dialog) .getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
} else {
((AlertDialog) dialog) .getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
}

@Override
public void afterTextChanged(Editable s) {

}
});
}
});


alertDialog.show();

alertDialog.setCancelable(true);
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}

}

4 changes: 3 additions & 1 deletion skunkworks_crow/src/main/res/layout/dialog_password_til.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@

<com.google.android.material.textfield.TextInputEditText
style="@style/MatchParentWidth"
android:inputType="textPassword" />
android:inputType="textPassword"
android:id="@+id/edtpass"
/>
</com.google.android.material.textfield.TextInputLayout>

0 comments on commit b74f527

Please sign in to comment.