Refactoring

pull/147/head
M66B 6 years ago
parent 31bf9cfaa9
commit 9dc1f04604

@ -834,15 +834,24 @@ public class FragmentSetup extends FragmentEx {
@Override
public void onActivityResult(final int requestCode, int resultCode, final Intent data) {
if (requestCode == ActivitySetup.REQUEST_EXPORT || requestCode == ActivitySetup.REQUEST_IMPORT) {
if (resultCode == RESULT_OK && data != null) {
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_password, null);
if (resultCode == RESULT_OK && data != null)
fileSelected(requestCode == ActivitySetup.REQUEST_EXPORT, data);
} else if (requestCode == ActivitySetup.REQUEST_CHOOSE_ACCOUNT) {
if (resultCode == RESULT_OK && data != null)
accountSelected(data);
}
}
private void fileSelected(final boolean export, final Intent data) {
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_password, null);
final TextInputLayout etPassword1 = dview.findViewById(R.id.tilPassword1);
final TextInputLayout etPassword2 = dview.findViewById(R.id.tilPassword2);
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TextInputLayout etPassword1 = dview.findViewById(R.id.tilPassword1);
TextInputLayout etPassword2 = dview.findViewById(R.id.tilPassword2);
String password1 = etPassword1.getEditText().getText().toString();
String password2 = etPassword2.getEditText().getText().toString();
@ -851,7 +860,7 @@ public class FragmentSetup extends FragmentEx {
Snackbar.make(view, R.string.title_setup_password_missing, Snackbar.LENGTH_LONG).show();
else {
if (password1.equals(password2)) {
if (requestCode == ActivitySetup.REQUEST_EXPORT)
if (export)
handleExport(data, password1);
else
handleImport(data, password1);
@ -862,8 +871,8 @@ public class FragmentSetup extends FragmentEx {
})
.show();
}
} else if (requestCode == ActivitySetup.REQUEST_CHOOSE_ACCOUNT) {
if (resultCode == RESULT_OK && data != null) {
private void accountSelected(Intent data) {
String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
String type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
@ -921,8 +930,6 @@ public class FragmentSetup extends FragmentEx {
break;
}
}
}
}
private void onMenuPrivacy() {
Helper.view(getContext(), getViewLifecycleOwner(), Helper.getIntentPrivacy());

Loading…
Cancel
Save