From fcfb695e7adbecc4b8d3217e267d0ea0371bb040 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 10 Jun 2018 19:12:46 +0200 Subject: [PATCH] permit empty values for subject and roster name --- .../generator/MessageGenerator.java | 4 +--- .../ui/ConferenceDetailsActivity.java | 5 +++-- .../conversations/ui/ContactDetailsActivity.java | 16 ++++++---------- .../eu/siacs/conversations/ui/XmppActivity.java | 13 +++++++++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index 394c25c10..b82f081e5 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -180,9 +180,7 @@ public class MessageGenerator extends AbstractGenerator { MessagePacket packet = new MessagePacket(); packet.setType(MessagePacket.TYPE_GROUPCHAT); packet.setTo(conversation.getJid().asBareJid()); - Element subjectChild = new Element("subject"); - subjectChild.setContent(subject); - packet.addChild(subjectChild); + packet.addChild("subject").setContent(subject); packet.setFrom(conversation.getAccount().getJid().asBareJid()); return packet; } diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 58a58667f..8c7fc18af 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -181,7 +181,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public String onValueEdited(String value) { - xmppConnectionService.pushSubjectToConference(mConversation, value); + xmppConnectionService.pushSubjectToConference(mConversation, value.trim().isEmpty() ? null : value.trim()); return null; } }; @@ -271,7 +271,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers if (mConversation != null) { quickEdit(mConversation.getMucOptions().getSubject(), R.string.edit_subject_hint, - this.onSubjectEdited); + this.onSubjectEdited, + true); } break; case R.id.action_share_http: diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index d73676af5..a88f769e4 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -240,16 +240,12 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp case R.id.action_edit_contact: Uri systemAccount = contact.getSystemAccount(); if (systemAccount == null) { - quickEdit(contact.getDisplayName(), 0, new OnValueEdited() { - - @Override - public String onValueEdited(String value) { - contact.setServerName(value); - ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact); - populateView(); - return null; - } - }); + quickEdit(contact.getDisplayName(), 0, value -> { + contact.setServerName(value); + ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact); + populateView(); + return null; + }, true); } else { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setDataAndType(systemAccount, Contacts.CONTENT_ITEM_TYPE); diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 3a69d55ca..08073dfc1 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -688,18 +688,23 @@ public abstract class XmppActivity extends ActionBarActivity { } protected void quickEdit(String previousValue, int hint, OnValueEdited callback) { - quickEdit(previousValue, callback, hint, false); + quickEdit(previousValue, callback, hint, false, false); + } + + protected void quickEdit(String previousValue, int hint, OnValueEdited callback, boolean permitEmpty) { + quickEdit(previousValue, callback, hint, false, permitEmpty); } protected void quickPasswordEdit(String previousValue, OnValueEdited callback) { - quickEdit(previousValue, callback, R.string.password, true); + quickEdit(previousValue, callback, R.string.password, true, false); } @SuppressLint("InflateParams") private void quickEdit(final String previousValue, final OnValueEdited callback, final int hint, - boolean password) { + boolean password, + boolean permitEmpty) { AlertDialog.Builder builder = new AlertDialog.Builder(this); View view = getLayoutInflater().inflate(R.layout.quickedit, null); final EditText editor = view.findViewById(R.id.editor); @@ -722,7 +727,7 @@ public abstract class XmppActivity extends ActionBarActivity { dialog.show(); View.OnClickListener clickListener = v -> { String value = editor.getText().toString(); - if (!value.equals(previousValue) && value.trim().length() > 0) { + if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) { String error = callback.onValueEdited(value); if (error != null) { editor.setError(error);