aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-12-23 22:26:19 +0100
committerChristian Schneppe <christian@pix-art.de>2017-12-23 22:26:19 +0100
commit4c82722686250d9dc9551a1f5cddeb76aae065df (patch)
tree170e5a0b18f0de6e630238c40a4c61fc9224a4f2
parentb2fade624678549c61dd69dd4ddd64bace0f91da (diff)
refactor StartConversationsActivity
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java85
1 files changed, 28 insertions, 57 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index b5c2e9b5e..e77ef8664 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -102,15 +102,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
- mSearchEditText.post(new Runnable() {
-
- @Override
- public void run() {
- mSearchEditText.requestFocus();
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(mSearchEditText,
- InputMethodManager.SHOW_IMPLICIT);
- }
+ mSearchEditText.post(() -> {
+ mSearchEditText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT);
});
return true;
@@ -206,23 +201,15 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
@Override
public void success(final Conversation conversation) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- hideToast();
- switchToConversation(conversation);
- }
+ runOnUiThread(() -> {
+ hideToast();
+ switchToConversation(conversation);
});
}
@Override
public void error(final int errorCode, Conversation object) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- replaceToast(getString(errorCode));
- }
- });
+ runOnUiThread(() -> replaceToast(getString(errorCode)));
}
@Override
@@ -240,7 +227,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else {
ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
R.layout.simple_list_item,
- Arrays.asList(new String[]{context.getString(R.string.no_accounts)}));
+ Arrays.asList(context.getString(R.string.no_accounts)));
adapter.setDropDownViewResource(R.layout.simple_list_item);
spinner.setAdapter(adapter);
spinner.setEnabled(false);
@@ -441,29 +428,26 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
prefilledJid, null, invite == null || !invite.hasFingerprints()
);
- dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
- @Override
- public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
- if (!xmppConnectionServiceBound) {
- return false;
- }
+ dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
+ if (!xmppConnectionServiceBound) {
+ return false;
+ }
final Account account = xmppConnectionService.findAccountByJid(accountJid);
if (account == null) {
return true;
}
- final Contact contact = account.getRoster().getContact(contactJid);
- if (contact.showInRoster()) {
- throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
- } else {
- xmppConnectionService.createContact(contact);
- if (invite != null && invite.hasFingerprints()) {
- xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
- }
- switchToConversation(contact, invite == null ? null : invite.getBody());
- return true;
+ final Contact contact = account.getRoster().getContact(contactJid);
+ if (contact.showInRoster()) {
+ throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
+ } else {
+ xmppConnectionService.createContact(contact);
+ if (invite != null && invite.hasFingerprints()) {
+ xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
}
+ switchToConversation(contact, invite == null ? null : invite.getBody());
+ return true;
}
});
@@ -880,29 +864,16 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
warning.setText(spannable);
builder.setView(view);
- builder.setPositiveButton(R.string.confirm, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (isTrustedSource.isChecked() && invite.hasFingerprints()) {
- xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
- }
- switchToConversation(contact, invite.getBody());
- }
- });
- builder.setNegativeButton(R.string.cancel, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- StartConversationActivity.this.finish();
+ builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
+ if (isTrustedSource.isChecked() && invite.hasFingerprints()) {
+ xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
}
+ switchToConversation(contact, invite.getBody());
});
+ builder.setNegativeButton(R.string.cancel, (dialog, which) -> StartConversationActivity.this.finish());
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
- dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- StartConversationActivity.this.finish();
- }
- });
+ dialog.setOnCancelListener(dialog1 -> StartConversationActivity.this.finish());
dialog.show();
}