mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-06-18 09:34:52 +02:00
Move listeners to members
This commit is contained in:
parent
9ed9c36fa3
commit
9540d70313
|
@ -23,7 +23,7 @@ import org.mercury_im.messenger.R;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class AddAccountDialogFragment extends AppCompatDialogFragment implements TextView.OnEditorActionListener {
|
||||
public class AddAccountDialogFragment extends AppCompatDialogFragment {
|
||||
|
||||
@BindView(R.id.username)
|
||||
TextInputEditText addressView;
|
||||
|
@ -45,23 +45,15 @@ public class AddAccountDialogFragment extends AppCompatDialogFragment implements
|
|||
builder.setTitle(R.string.action_add_account)
|
||||
.setView(dialogView)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.action_sign_in, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// We later overwrite in onResume, so that the dialog does not automatically
|
||||
// dismiss when button is clicked.
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AddAccountDialogFragment.this.onCancel(dialog);
|
||||
}
|
||||
});
|
||||
.setPositiveButton(R.string.action_sign_in, null)
|
||||
.setNegativeButton(R.string.button_cancel, cancelButtonClickListener);
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private final DialogInterface.OnClickListener cancelButtonClickListener =
|
||||
(dialog, which) -> AddAccountDialogFragment.this.onCancel(dialog);
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
@ -90,34 +82,38 @@ public class AddAccountDialogFragment extends AppCompatDialogFragment implements
|
|||
}
|
||||
});
|
||||
|
||||
addressView.setOnEditorActionListener(this);
|
||||
passwordView.setOnEditorActionListener(this);
|
||||
|
||||
addressView.addTextChangedListener(viewModel.getUsernameTextChangedListener());
|
||||
passwordView.addTextChangedListener(viewModel.getPasswordTextChangedListener());
|
||||
|
||||
addressView.setOnEditorActionListener(focusPasswordFieldOnEnterPressed);
|
||||
passwordView.setOnEditorActionListener(loginOnEnterPressed);
|
||||
}
|
||||
|
||||
private final TextView.OnEditorActionListener focusPasswordFieldOnEnterPressed = new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_NEXT) {
|
||||
passwordView.requestFocus();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private final TextView.OnEditorActionListener loginOnEnterPressed = new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
|
||||
viewModel.getCommonViewModel().login();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
switch (v.getId()) {
|
||||
case R.id.username:
|
||||
if (actionId == EditorInfo.IME_ACTION_NEXT) {
|
||||
passwordView.requestFocus();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.password:
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
|
||||
viewModel.getCommonViewModel().login();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue