diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 6f342691c..66bb4136e 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2348,9 +2348,12 @@ public class XmppConnectionService extends Service { return false; } - public void renameInMuc(final Conversation conversation, final String nick, final UiCallback callback) { + public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback callback) { final MucOptions options = conversation.getMucOptions(); final Jid joinJid = options.createJoinJid(nick); + if (joinJid == null) { + return false; + } if (options.online()) { Account account = conversation.getAccount(); options.setOnRenameListener(new OnRenameListener() { @@ -2395,6 +2398,7 @@ public class XmppConnectionService extends Service { joinMuc(conversation); } } + return true; } public void leaveMuc(Conversation conversation) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 294db3ee5..d019834f3 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -204,8 +204,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers private OnValueEdited onSubjectEdited = new OnValueEdited() { @Override - public void onValueEdited(String value) { + public String onValueEdited(String value) { xmppConnectionService.pushSubjectToConference(mConversation,value); + return null; } }; @@ -254,8 +255,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers new OnValueEdited() { @Override - public void onValueEdited(String value) { - xmppConnectionService.renameInMuc(mConversation,value,renameCallback); + public String onValueEdited(String value) { + if (xmppConnectionService.renameInMuc(mConversation,value,renameCallback)) { + return null; + } else { + return getString(R.string.invalid_username); + } } }); } diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 3de3c4df2..48107a4ab 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -284,11 +284,11 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp quickEdit(contact.getDisplayName(), 0, new OnValueEdited() { @Override - public void onValueEdited(String value) { + public String onValueEdited(String value) { contact.setServerName(value); - ContactDetailsActivity.this.xmppConnectionService - .pushContactToServer(contact); + ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact); populateView(); + return null; } }); } else { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 897bd7cbc..9bd90902f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -133,9 +133,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa activity.quickPasswordEdit(password, new OnValueEdited() { @Override - public void onValueEdited(String value) { - activity.xmppConnectionService.providePasswordForMuc( - conversation, value); + public String onValueEdited(String value) { + activity.xmppConnectionService.providePasswordForMuc(conversation, value); + return null; } }); } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 8bf84af0c..a531fe8cf 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -7,6 +7,7 @@ import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; +import android.app.Dialog; import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.ClipData; @@ -167,11 +168,11 @@ public abstract class XmppActivity extends Activity { abstract protected void refreshUiReal(); protected interface OnValueEdited { - public void onValueEdited(String value); + String onValueEdited(String value); } public interface OnPresenceSelected { - public void onPresenceSelected(); + void onPresenceSelected(); } protected ServiceConnection mConnection = new ServiceConnection() { @@ -733,23 +734,13 @@ public abstract class XmppActivity extends Activity { boolean password) { AlertDialog.Builder builder = new AlertDialog.Builder(this); View view = getLayoutInflater().inflate(R.layout.quickedit, null); - final EditText editor = (EditText) view.findViewById(R.id.editor); - OnClickListener mClickListener = new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - String value = editor.getText().toString(); - if (!value.equals(previousValue) && value.trim().length() > 0) { - callback.onValueEdited(value); - } - } - }; + final EditText editor = view.findViewById(R.id.editor); if (password) { editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - builder.setPositiveButton(R.string.accept, mClickListener); + builder.setPositiveButton(R.string.accept,null); } else { - builder.setPositiveButton(R.string.edit, mClickListener); + builder.setPositiveButton(R.string.edit, null); } if (hint != 0) { editor.setHint(hint); @@ -761,7 +752,24 @@ public abstract class XmppActivity extends Activity { } builder.setView(view); builder.setNegativeButton(R.string.cancel, null); - builder.create().show(); + final AlertDialog dialog = builder.create(); + dialog.show(); + View.OnClickListener clickListener = new View.OnClickListener() { + + @Override + public void onClick(View v) { + String value = editor.getText().toString(); + if (!value.equals(previousValue) && value.trim().length() > 0) { + String error = callback.onValueEdited(value); + if (error != null) { + editor.setError(error); + return; + } + } + dialog.dismiss(); + } + }; + dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener); } public boolean hasStoragePermission(int requestCode) {