refactor StartConversationsActivity

This commit is contained in:
Daniel Gultsch 2017-12-15 19:13:58 +01:00
parent cc6a001ac2
commit 0be41e0aab
1 changed files with 32 additions and 61 deletions

View File

@ -100,15 +100,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override @Override
public boolean onMenuItemActionExpand(MenuItem item) { public boolean onMenuItemActionExpand(MenuItem item) {
mSearchEditText.post(new Runnable() { mSearchEditText.post(() -> {
mSearchEditText.requestFocus();
@Override InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
public void run() { imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT);
mSearchEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mSearchEditText,
InputMethodManager.SHOW_IMPLICIT);
}
}); });
return true; return true;
@ -204,23 +199,15 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() { private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
@Override @Override
public void success(final Conversation conversation) { public void success(final Conversation conversation) {
runOnUiThread(new Runnable() { runOnUiThread(() -> {
@Override hideToast();
public void run() { switchToConversation(conversation);
hideToast();
switchToConversation(conversation);
}
}); });
} }
@Override @Override
public void error(final int errorCode, Conversation object) { public void error(final int errorCode, Conversation object) {
runOnUiThread(new Runnable() { runOnUiThread(() -> replaceToast(getString(errorCode)));
@Override
public void run() {
replaceToast(getString(errorCode));
}
});
} }
@Override @Override
@ -422,29 +409,26 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
prefilledJid, null, invite == null || !invite.hasFingerprints() prefilledJid, null, invite == null || !invite.hasFingerprints()
); );
dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() { dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
@Override if (!xmppConnectionServiceBound) {
public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError { return false;
if (!xmppConnectionServiceBound) { }
return false;
}
final Account account = xmppConnectionService.findAccountByJid(accountJid); final Account account = xmppConnectionService.findAccountByJid(accountJid);
if (account == null) { if (account == null) {
return true; return true;
} }
final Contact contact = account.getRoster().getContact(contactJid); final Contact contact = account.getRoster().getContact(contactJid);
if (contact.showInRoster()) { if (contact.showInRoster()) {
throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists)); throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
} else { } else {
xmppConnectionService.createContact(contact); xmppConnectionService.createContact(contact);
if (invite != null && invite.hasFingerprints()) { if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints()); xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints());
}
switchToConversation(contact, invite == null ? null : invite.getBody());
return true;
} }
switchToConversation(contact, invite == null ? null : invite.getBody());
return true;
} }
}); });
@ -589,7 +573,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else { } else {
ArrayAdapter<String> adapter = new ArrayAdapter<>(context, ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
R.layout.simple_list_item, 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); adapter.setDropDownViewResource(R.layout.simple_list_item);
spinner.setAdapter(adapter); spinner.setAdapter(adapter);
spinner.setEnabled(false); spinner.setEnabled(false);
@ -877,29 +861,16 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
warning.setText(spannable); warning.setText(spannable);
builder.setView(view); builder.setView(view);
builder.setPositiveButton(R.string.confirm, new OnClickListener() { builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
@Override if (isTrustedSource.isChecked() && invite.hasFingerprints()) {
public void onClick(DialogInterface dialog, int which) { xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
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();
} }
switchToConversation(contact, invite.getBody());
}); });
builder.setNegativeButton(R.string.cancel, (dialog, which) -> StartConversationActivity.this.finish());
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false); dialog.setCanceledOnTouchOutside(false);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { dialog.setOnCancelListener(dialog1 -> StartConversationActivity.this.finish());
@Override
public void onCancel(DialogInterface dialog) {
StartConversationActivity.this.finish();
}
});
dialog.show(); dialog.show();
} }