Replace anonymous fun by lambda

This commit is contained in:
J-Jamet
2018-03-29 23:12:16 +02:00
parent 02b6191e66
commit 675efe3ab8
2 changed files with 85 additions and 128 deletions

View File

@@ -86,18 +86,13 @@ public class AssignMasterKeyDialogFragment extends DialogFragment {
builder.setView(rootView) builder.setView(rootView)
.setTitle(R.string.assign_master_key) .setTitle(R.string.assign_master_key)
// Add action buttons // Add action buttons
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, id) -> {
@Override
public void onClick(DialogInterface dialog, int id) {
}
}) })
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.cancel, (dialog, id) -> {
public void onClick(DialogInterface dialog, int id) {
}
}); });
passwordCheckBox = (CompoundButton) rootView.findViewById(R.id.password_checkbox); passwordCheckBox = rootView.findViewById(R.id.password_checkbox);
passView = (TextView) rootView.findViewById(R.id.pass_password); passView = rootView.findViewById(R.id.pass_password);
passView.addTextChangedListener(new TextWatcher() { passView.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@@ -110,10 +105,10 @@ public class AssignMasterKeyDialogFragment extends DialogFragment {
passwordCheckBox.setChecked(true); passwordCheckBox.setChecked(true);
} }
}); });
passConfView = (TextView) rootView.findViewById(R.id.pass_conf_password); passConfView = rootView.findViewById(R.id.pass_conf_password);
keyfileCheckBox = (CompoundButton) rootView.findViewById(R.id.keyfile_checkox); keyfileCheckBox = rootView.findViewById(R.id.keyfile_checkox);
keyfileView = (TextView) rootView.findViewById(R.id.pass_keyfile); keyfileView = rootView.findViewById(R.id.pass_keyfile);
keyfileView.addTextChangedListener(new TextWatcher() { keyfileView.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@@ -129,22 +124,13 @@ public class AssignMasterKeyDialogFragment extends DialogFragment {
keyFileHelper = new KeyFileHelper(this); keyFileHelper = new KeyFileHelper(this);
rootView.findViewById(R.id.browse_button) rootView.findViewById(R.id.browse_button)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(view -> keyFileHelper.getOpenFileOnClickViewListener().onClick(view));
@Override
public void onClick(View view) {
keyFileHelper.getOpenFileOnClickViewListener().onClick(view);
}
});
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() { dialog.setOnShowListener(dialog1 -> {
@Override Button positiveButton = ((AlertDialog) dialog1).getButton(DialogInterface.BUTTON_POSITIVE);
public void onShow(final DialogInterface dialog) { positiveButton.setOnClickListener(v -> {
Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
masterPassword = ""; masterPassword = "";
mKeyfile = null; mKeyfile = null;
@@ -162,19 +148,14 @@ public class AssignMasterKeyDialogFragment extends DialogFragment {
keyfileCheckBox.isChecked(), mKeyfile); keyfileCheckBox.isChecked(), mKeyfile);
dismiss(); dismiss();
} }
}
}); });
Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE); Button negativeButton = ((AlertDialog) dialog1).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setOnClickListener(new View.OnClickListener() { negativeButton.setOnClickListener(v -> {
@Override
public void onClick(final View v) {
mListener.onAssignKeyDialogNegativeClick( mListener.onAssignKeyDialogNegativeClick(
passwordCheckBox.isChecked(), masterPassword, passwordCheckBox.isChecked(), masterPassword,
keyfileCheckBox.isChecked(), mKeyfile); keyfileCheckBox.isChecked(), mKeyfile);
dismiss(); dismiss();
}
}); });
}
}); });
@@ -220,36 +201,28 @@ public class AssignMasterKeyDialogFragment extends DialogFragment {
private void showEmptyPasswordConfirmationDialog() { private void showEmptyPasswordConfirmationDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.warning_empty_password) builder.setMessage(R.string.warning_empty_password)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, id) -> {
public void onClick(DialogInterface dialog, int id) {
if (!verifyFile()) { if (!verifyFile()) {
mListener.onAssignKeyDialogPositiveClick( mListener.onAssignKeyDialogPositiveClick(
passwordCheckBox.isChecked(), masterPassword, passwordCheckBox.isChecked(), masterPassword,
keyfileCheckBox.isChecked(), mKeyfile); keyfileCheckBox.isChecked(), mKeyfile);
AssignMasterKeyDialogFragment.this.dismiss(); AssignMasterKeyDialogFragment.this.dismiss();
} }
}
}) })
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.cancel, (dialog, id) -> {});
public void onClick(DialogInterface dialog, int id) {}
});
builder.create().show(); builder.create().show();
} }
private void showNoKeyConfirmationDialog() { private void showNoKeyConfirmationDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.warning_no_encryption_key) builder.setMessage(R.string.warning_no_encryption_key)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, id) -> {
public void onClick(DialogInterface dialog, int id) {
mListener.onAssignKeyDialogPositiveClick( mListener.onAssignKeyDialogPositiveClick(
passwordCheckBox.isChecked(), masterPassword, passwordCheckBox.isChecked(), masterPassword,
keyfileCheckBox.isChecked(), mKeyfile); keyfileCheckBox.isChecked(), mKeyfile);
AssignMasterKeyDialogFragment.this.dismiss(); AssignMasterKeyDialogFragment.this.dismiss();
}
}) })
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.cancel, (dialog, id) -> {});
public void onClick(DialogInterface dialog, int id) {}
});
builder.create().show(); builder.create().show();
} }
@@ -258,9 +231,7 @@ public class AssignMasterKeyDialogFragment extends DialogFragment {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
keyFileHelper.onActivityResultCallback(requestCode, resultCode, data, keyFileHelper.onActivityResultCallback(requestCode, resultCode, data,
new KeyFileHelper.KeyFileCallback() { uri -> {
@Override
public void onKeyFileResultCallback(Uri uri) {
if(uri != null) { if(uri != null) {
Uri pathString = UriUtil.parseDefaultFile(uri.toString()); Uri pathString = UriUtil.parseDefaultFile(uri.toString());
if (pathString != null) { if (pathString != null) {
@@ -268,7 +239,6 @@ public class AssignMasterKeyDialogFragment extends DialogFragment {
keyfileView.setText(pathString.toString()); keyfileView.setText(pathString.toString());
} }
} }
}
}); });
} }
} }

View File

@@ -30,6 +30,7 @@ import android.os.Environment;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
@@ -76,6 +77,7 @@ public class CreateFileDialogFragment extends DialogFragment implements AdapterV
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
assert getActivity() != null;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
@@ -83,24 +85,17 @@ public class CreateFileDialogFragment extends DialogFragment implements AdapterV
builder.setView(rootView) builder.setView(rootView)
.setTitle(R.string.create_keepass_file) .setTitle(R.string.create_keepass_file)
// Add action buttons // Add action buttons
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, id) -> {})
@Override .setNegativeButton(R.string.cancel, (dialog, id) -> {});
public void onClick(DialogInterface dialog, int id) {}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {}
});
// Folder selection // Folder selection
View browseView = rootView.findViewById(R.id.browse_button); View browseView = rootView.findViewById(R.id.browse_button);
folderPathView = (EditText) rootView.findViewById(R.id.folder_path); folderPathView = rootView.findViewById(R.id.folder_path);
fileNameView = (EditText) rootView.findViewById(R.id.filename); fileNameView = rootView.findViewById(R.id.filename);
String defaultPath = Environment.getExternalStorageDirectory().getPath() String defaultPath = Environment.getExternalStorageDirectory().getPath()
+ getString(R.string.database_file_path_default); + getString(R.string.database_file_path_default);
folderPathView.setText(defaultPath); folderPathView.setText(defaultPath);
browseView.setOnClickListener(new View.OnClickListener() { browseView.setOnClickListener(v -> {
@Override
public void onClick(View v) {
Intent i = new Intent(getContext(), FilePickerStylishActivity.class); Intent i = new Intent(getContext(), FilePickerStylishActivity.class);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true); i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
@@ -108,7 +103,6 @@ public class CreateFileDialogFragment extends DialogFragment implements AdapterV
i.putExtra(FilePickerActivity.EXTRA_START_PATH, i.putExtra(FilePickerActivity.EXTRA_START_PATH,
Environment.getExternalStorageDirectory().getPath()); Environment.getExternalStorageDirectory().getPath());
startActivityForResult(i, FILE_CODE); startActivityForResult(i, FILE_CODE);
}
}); });
// Init path // Init path
@@ -116,37 +110,30 @@ public class CreateFileDialogFragment extends DialogFragment implements AdapterV
// Extension // Extension
extension = getString(R.string.database_file_extension_default); extension = getString(R.string.database_file_extension_default);
Spinner spinner = (Spinner) rootView.findViewById(R.id.file_types); Spinner spinner = rootView.findViewById(R.id.file_types);
spinner.setOnItemSelectedListener(this); spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements // Spinner Drop down elements
String[] fileTypes = getResources().getStringArray(R.array.file_types); String[] fileTypes = getResources().getStringArray(R.array.file_types);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, fileTypes); ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, fileTypes);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter); spinner.setAdapter(dataAdapter);
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() { dialog.setOnShowListener(dialog1 -> {
@Override Button positiveButton = ((AlertDialog) dialog1).getButton(DialogInterface.BUTTON_POSITIVE);
public void onShow(final DialogInterface dialog) { positiveButton.setOnClickListener(v -> {
Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if(mListener.onDefinePathDialogPositiveClick(buildPath())) if(mListener.onDefinePathDialogPositiveClick(buildPath()))
CreateFileDialogFragment.this.dismiss(); dismiss();
});
Button negativeButton = ((AlertDialog) dialog1).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setOnClickListener(v -> {
if(mListener.onDefinePathDialogNegativeClick(buildPath())) {
// issue #69 https://github.com/Kunzisoft/KeePassDX/issues/69
dismiss();
} }
}); });
Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if(mListener.onDefinePathDialogNegativeClick(buildPath()))
CreateFileDialogFragment.this.dismiss();
}
});
}
}); });
return dialog; return dialog;