From 43521891f0114d050c1ae8bf3d76d5ad4f1cf0a4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Jan 2016 11:39:02 +0100 Subject: show fetch errors in trust keys activity --- .../siacs/conversations/crypto/axolotl/AxolotlService.java | 13 +++++++++++++ .../java/eu/siacs/conversations/ui/TrustKeysActivity.java | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index c8253dd49..43a900109 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -79,6 +79,19 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } } + public boolean fetchMapHasErrors(Contact contact) { + Jid jid = contact.getJid().toBareJid(); + if (deviceIds.get(jid) != null) { + for (Integer foreignId : this.deviceIds.get(jid)) { + AxolotlAddress address = new AxolotlAddress(jid.toString(), foreignId); + if (fetchStatusMap.getAll(address).containsValue(FetchStatus.ERROR)) { + return true; + } + } + } + return false; + } + private static class AxolotlAddressMap { protected Map> map; protected final Object MAP_LOCK = new Object(); diff --git a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index 29da0ce6c..eec30798e 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -162,7 +162,8 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate } else { if (!hasForeignKeys && hasNoOtherTrustedKeys()) { keyErrorMessageCard.setVisibility(View.VISIBLE); - if (lastFetchReport == AxolotlService.FetchStatus.ERROR) { + if (lastFetchReport == AxolotlService.FetchStatus.ERROR + || contact.getAccount().getAxolotlService().fetchMapHasErrors(contact)) { keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error); } else { keyErrorMessage.setText(R.string.error_no_keys_to_trust); -- cgit v1.2.3 From 61408611437785ebe685aadfbca924cbc86340c1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Jan 2016 11:40:32 +0100 Subject: reset stanza queue when resetting xmppconnection --- src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 273a7381c..a3dd06446 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -879,6 +879,7 @@ public class XmppConnection implements Runnable { public void resetEverything() { resetStreamId(); clearIqCallbacks(); + mStanzaQueue.clear(); synchronized (this.disco) { disco.clear(); } -- cgit v1.2.3 From 39fdf4a333378affcca360886701851d84dd9e0b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Jan 2016 12:44:08 +0100 Subject: added support for field types jid-single and text-private --- .../conversations/ui/forms/FormFieldFactory.java | 5 ++++ .../conversations/ui/forms/FormFieldWrapper.java | 8 +++++- .../ui/forms/FormJidSingleFieldWrapper.java | 31 ++++++++++++++++++++++ .../ui/forms/FormTextFieldWrapper.java | 19 ++++++++++--- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java index 9e54678a3..2e7c17dc2 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java @@ -15,10 +15,15 @@ public class FormFieldFactory { static { typeTable.put("text-single", FormTextFieldWrapper.class); typeTable.put("text-multi", FormTextFieldWrapper.class); + typeTable.put("text-private", FormTextFieldWrapper.class); + typeTable.put("jid-single", FormJidSingleFieldWrapper.class); } public static FormFieldWrapper createFromField(Context context, Field field) { Class clazz = typeTable.get(field.getType()); + if (clazz == null) { + clazz = FormTextFieldWrapper.class; + } return FormFieldWrapper.createFromField(clazz, context, field); } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java index 3af375363..a0ed371a3 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java @@ -19,7 +19,11 @@ public abstract class FormFieldWrapper { this.field = field; LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.view = inflater.inflate(getLayoutResource(), null); - setLabel(field.getLabel(), field.isRequired()); + String label = field.getLabel(); + if (label == null) { + label = field.getFieldName(); + } + setLabel(label, field.isRequired()); } public void submit() { @@ -34,6 +38,8 @@ public abstract class FormFieldWrapper { abstract List getValues(); + abstract boolean validates(); + abstract protected int getLayoutResource(); protected static FormFieldWrapper createFromField(Class c, Context context, Field field) { diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java new file mode 100644 index 000000000..b54940f64 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java @@ -0,0 +1,31 @@ +package eu.siacs.conversations.ui.forms; + +import android.content.Context; +import android.text.InputType; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.xmpp.forms.Field; +import eu.siacs.conversations.xmpp.jid.InvalidJidException; +import eu.siacs.conversations.xmpp.jid.Jid; + +public class FormJidSingleFieldWrapper extends FormTextFieldWrapper { + + protected FormJidSingleFieldWrapper(Context context, Field field) { + super(context, field); + editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + editText.setHint(R.string.account_settings_example_jabber_id); + } + + @Override + public boolean validates() { + String value = getValue(); + if (!value.isEmpty()) { + try { + Jid.fromString(value); + } catch (InvalidJidException e) { + return false; + } + } + return super.validates(); + } +} diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java index 8f70dd37e..71ed6e4ab 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; +import android.text.InputType; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; @@ -20,7 +21,10 @@ public class FormTextFieldWrapper extends FormFieldWrapper { protected FormTextFieldWrapper(Context context, Field field) { super(context, field); editText = (EditText) view.findViewById(R.id.field); - editText.setSingleLine("text-single".equals(field.getType())); + editText.setSingleLine(!"text-multi".equals(field.getType())); + if ("text-private".equals(field.getType())) { + editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + } } @Override @@ -36,15 +40,24 @@ public class FormTextFieldWrapper extends FormFieldWrapper { textView.setText(spannableString); } + protected String getValue() { + return editText.getText().toString(); + } + @Override - List getValues() { + public List getValues() { List values = new ArrayList<>(); - for (String line : editText.getText().toString().split("\\n")) { + for (String line : getValue().split("\\n")) { values.add(line); } return values; } + @Override + public boolean validates() { + return getValue().trim().length() > 0 || !field.isRequired(); + } + @Override protected int getLayoutResource() { return R.layout.form_text; -- cgit v1.2.3 From 0569a1e7698141262e3f8443be26b5cb053954b8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Jan 2016 16:23:23 +0100 Subject: introduced boolean form field wrapper --- .../ui/forms/FormBooleanFieldWrapper.java | 43 ++++++++++++++++++++++ .../conversations/ui/forms/FormFieldFactory.java | 1 + .../conversations/ui/forms/FormFieldWrapper.java | 19 +++++++++- .../ui/forms/FormTextFieldWrapper.java | 12 +----- src/main/res/layout/form_boolean.xml | 13 +++++++ src/main/res/layout/form_text.xml | 2 +- 6 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java create mode 100644 src/main/res/layout/form_boolean.xml (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java new file mode 100644 index 000000000..e9adf15a3 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java @@ -0,0 +1,43 @@ +package eu.siacs.conversations.ui.forms; + +import android.content.Context; +import android.widget.CheckBox; + +import java.util.ArrayList; +import java.util.List; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.xmpp.forms.Field; + +public class FormBooleanFieldWrapper extends FormFieldWrapper { + + protected CheckBox checkBox; + + protected FormBooleanFieldWrapper(Context context, Field field) { + super(context, field); + checkBox = (CheckBox) view.findViewById(R.id.field); + } + + @Override + protected void setLabel(String label, boolean required) { + CheckBox checkBox = (CheckBox) view.findViewById(R.id.field); + checkBox.setText(createSpannableLabelString(label, required)); + } + + @Override + public List getValues() { + List values = new ArrayList<>(); + values.add(Boolean.toString(checkBox.isChecked())); + return values; + } + + @Override + public boolean validates() { + return checkBox.isChecked() || !field.isRequired(); + } + + @Override + protected int getLayoutResource() { + return R.layout.form_boolean; + } +} diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java index 2e7c17dc2..966c0e5aa 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java @@ -17,6 +17,7 @@ public class FormFieldFactory { typeTable.put("text-multi", FormTextFieldWrapper.class); typeTable.put("text-private", FormTextFieldWrapper.class); typeTable.put("jid-single", FormJidSingleFieldWrapper.class); + typeTable.put("boolean", FormBooleanFieldWrapper.class); } public static FormFieldWrapper createFromField(Context context, Field field) { diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java index a0ed371a3..f2560ef51 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java @@ -1,11 +1,15 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import java.util.List; +import eu.siacs.conversations.R; import eu.siacs.conversations.xmpp.forms.Field; public abstract class FormFieldWrapper { @@ -26,11 +30,11 @@ public abstract class FormFieldWrapper { setLabel(label, field.isRequired()); } - public void submit() { + public final void submit() { this.field.setValues(getValues()); } - public View getView() { + public final View getView() { return view; } @@ -42,6 +46,17 @@ public abstract class FormFieldWrapper { abstract protected int getLayoutResource(); + protected SpannableString createSpannableLabelString(String label, boolean required) { + SpannableString spannableString = new SpannableString(label + (required ? " *" : "")); + if (required) { + int start = label.length(); + int end = label.length() + 2; + spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0); + spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.accent)), start, end, 0); + } + return spannableString; + } + protected static FormFieldWrapper createFromField(Class c, Context context, Field field) { try { return c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field); diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java index 71ed6e4ab..274936e86 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java @@ -2,9 +2,6 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; import android.text.InputType; -import android.text.SpannableString; -import android.text.style.ForegroundColorSpan; -import android.text.style.StyleSpan; import android.widget.EditText; import android.widget.TextView; @@ -30,14 +27,7 @@ public class FormTextFieldWrapper extends FormFieldWrapper { @Override protected void setLabel(String label, boolean required) { TextView textView = (TextView) view.findViewById(R.id.label); - SpannableString spannableString = new SpannableString(label + (required ? " *" : "")); - if (required) { - int start = label.length(); - int end = label.length() + 2; - spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0); - spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.accent)), start, end, 0); - } - textView.setText(spannableString); + textView.setText(createSpannableLabelString(label, required)); } protected String getValue() { diff --git a/src/main/res/layout/form_boolean.xml b/src/main/res/layout/form_boolean.xml new file mode 100644 index 000000000..fd553acb2 --- /dev/null +++ b/src/main/res/layout/form_boolean.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/src/main/res/layout/form_text.xml b/src/main/res/layout/form_text.xml index e36ac74e9..31b521e89 100644 --- a/src/main/res/layout/form_text.xml +++ b/src/main/res/layout/form_text.xml @@ -2,12 +2,12 @@ -- cgit v1.2.3 From 8850a1fbe3d8affd734b94eb0eb650dc1dfa5bd6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Jan 2016 20:32:00 +0100 Subject: added FormWrapper and form field validation --- .../ui/forms/FormBooleanFieldWrapper.java | 25 +++++++- .../conversations/ui/forms/FormFieldFactory.java | 2 +- .../conversations/ui/forms/FormFieldWrapper.java | 24 ++++++++ .../ui/forms/FormJidSingleFieldWrapper.java | 2 + .../ui/forms/FormTextFieldWrapper.java | 29 +++++++++- .../siacs/conversations/ui/forms/FormWrapper.java | 66 ++++++++++++++++++++++ .../eu/siacs/conversations/xmpp/forms/Field.java | 15 +++++ src/main/res/values/strings.xml | 1 + 8 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java index e9adf15a3..eba0f12d9 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; import android.widget.CheckBox; +import android.widget.CompoundButton; import java.util.ArrayList; import java.util.List; @@ -16,6 +17,13 @@ public class FormBooleanFieldWrapper extends FormFieldWrapper { protected FormBooleanFieldWrapper(Context context, Field field) { super(context, field); checkBox = (CheckBox) view.findViewById(R.id.field); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + checkBox.setError(null); + invokeOnFormFieldValuesEdited(); + } + }); } @Override @@ -33,7 +41,22 @@ public class FormBooleanFieldWrapper extends FormFieldWrapper { @Override public boolean validates() { - return checkBox.isChecked() || !field.isRequired(); + if (checkBox.isChecked() || !field.isRequired()) { + return true; + } else { + checkBox.setError(context.getString(R.string.this_field_is_required)); + checkBox.requestFocus(); + return false; + } + } + + @Override + public boolean edited() { + if (field.getValues().size() == 0) { + return checkBox.isChecked(); + } else { + return super.edited(); + } } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java index 966c0e5aa..ee3064726 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldFactory.java @@ -20,7 +20,7 @@ public class FormFieldFactory { typeTable.put("boolean", FormBooleanFieldWrapper.class); } - public static FormFieldWrapper createFromField(Context context, Field field) { + protected static FormFieldWrapper createFromField(Context context, Field field) { Class clazz = typeTable.get(field.getType()); if (clazz == null) { clazz = FormTextFieldWrapper.class; diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java index f2560ef51..8ba62bdd8 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java @@ -4,11 +4,13 @@ import android.content.Context; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import java.util.List; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.xmpp.forms.Field; @@ -17,6 +19,7 @@ public abstract class FormFieldWrapper { protected final Context context; protected final Field field; protected final View view; + protected OnFormFieldValuesEdited onFormFieldValuesEditedListener; protected FormFieldWrapper(Context context, Field field) { this.context = context; @@ -57,6 +60,23 @@ public abstract class FormFieldWrapper { return spannableString; } + protected void invokeOnFormFieldValuesEdited() { + Log.d(Config.LOGTAG, "invoke on form field values edited"); + if (this.onFormFieldValuesEditedListener != null) { + this.onFormFieldValuesEditedListener.onFormFieldValuesEdited(); + } else { + Log.d(Config.LOGTAG,"listener is null"); + } + } + + public boolean edited() { + return !field.getValues().equals(getValues()); + } + + public void setOnFormFieldValuesEditedListener(OnFormFieldValuesEdited listener) { + this.onFormFieldValuesEditedListener = listener; + } + protected static FormFieldWrapper createFromField(Class c, Context context, Field field) { try { return c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field); @@ -65,4 +85,8 @@ public abstract class FormFieldWrapper { return null; } } + + public interface OnFormFieldValuesEdited { + void onFormFieldValuesEdited(); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java index b54940f64..3890a1a7a 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java @@ -23,6 +23,8 @@ public class FormJidSingleFieldWrapper extends FormTextFieldWrapper { try { Jid.fromString(value); } catch (InvalidJidException e) { + editText.setError(context.getString(R.string.invalid_jid)); + editText.requestFocus(); return false; } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java index 274936e86..47b8d86cb 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java @@ -1,7 +1,9 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; +import android.text.Editable; import android.text.InputType; +import android.text.TextWatcher; import android.widget.EditText; import android.widget.TextView; @@ -22,6 +24,21 @@ public class FormTextFieldWrapper extends FormFieldWrapper { if ("text-private".equals(field.getType())) { editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } + editText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + editText.setError(null); + invokeOnFormFieldValuesEdited(); + } + + @Override + public void afterTextChanged(Editable s) { + } + }); } @Override @@ -38,14 +55,22 @@ public class FormTextFieldWrapper extends FormFieldWrapper { public List getValues() { List values = new ArrayList<>(); for (String line : getValue().split("\\n")) { - values.add(line); + if (line.length() > 0) { + values.add(line); + } } return values; } @Override public boolean validates() { - return getValue().trim().length() > 0 || !field.isRequired(); + if (getValue().trim().length() > 0 || !field.isRequired()) { + return true; + } else { + editText.setError(context.getString(R.string.this_field_is_required)); + editText.requestFocus(); + return false; + } } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java new file mode 100644 index 000000000..51d15f0c2 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java @@ -0,0 +1,66 @@ +package eu.siacs.conversations.ui.forms; + +import android.content.Context; +import android.widget.LinearLayout; + +import java.util.ArrayList; +import java.util.List; + +import eu.siacs.conversations.xmpp.forms.Data; +import eu.siacs.conversations.xmpp.forms.Field; + +public class FormWrapper { + + private final LinearLayout layout; + + private final Data form; + + private final List fieldWrappers = new ArrayList<>(); + + private FormWrapper(Context context, LinearLayout linearLayout, Data form) { + this.form = form; + this.layout = linearLayout; + this.layout.removeAllViews(); + for(Field field : form.getFields()) { + FormFieldWrapper fieldWrapper = FormFieldFactory.createFromField(context,field); + if (fieldWrapper != null) { + layout.addView(fieldWrapper.getView()); + fieldWrappers.add(fieldWrapper); + } + } + } + + public Data submit() { + for(FormFieldWrapper fieldWrapper : fieldWrappers) { + fieldWrapper.submit(); + } + this.form.submit(); + return this.form; + } + + public boolean validates() { + boolean validates = true; + for(FormFieldWrapper fieldWrapper : fieldWrappers) { + validates &= fieldWrapper.validates(); + } + return validates; + } + + public void setOnFormFieldValuesEditedListener(FormFieldWrapper.OnFormFieldValuesEdited listener) { + for(FormFieldWrapper fieldWrapper : fieldWrappers) { + fieldWrapper.setOnFormFieldValuesEditedListener(listener); + } + } + + public boolean edited() { + boolean edited = false; + for(FormFieldWrapper fieldWrapper : fieldWrappers) { + edited |= fieldWrapper.edited(); + } + return edited; + } + + public static FormWrapper createInLayout(Context context, LinearLayout layout, Data form) { + return new FormWrapper(context, layout, form); + } +} diff --git a/src/main/java/eu/siacs/conversations/xmpp/forms/Field.java b/src/main/java/eu/siacs/conversations/xmpp/forms/Field.java index c1fc808dc..020b34b90 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/forms/Field.java +++ b/src/main/java/eu/siacs/conversations/xmpp/forms/Field.java @@ -1,7 +1,9 @@ package eu.siacs.conversations.xmpp.forms; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import eu.siacs.conversations.xml.Element; @@ -52,6 +54,19 @@ public class Field extends Element { return findChildContent("value"); } + public List getValues() { + List values = new ArrayList<>(); + for(Element child : getChildren()) { + if ("value".equals(child.getName())) { + String content = child.getContent(); + if (content != null) { + values.add(content); + } + } + } + return values; + } + public String getLabel() { return getAttribute("label"); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index a354435d7..38368383b 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -581,4 +581,5 @@ Disable The selected area is too large (No activated accounts) + This field is required -- cgit v1.2.3 From 31fd425c9a41f1cc70ec92ab5876781464b236d9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 24 Jan 2016 12:17:00 +0100 Subject: changed FileBackend API to allow files instead of messages to be copied and resized --- .../conversations/persistance/FileBackend.java | 67 +++++++++++----------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 05932acce..4bdf080cf 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -86,7 +86,7 @@ public class FileBackend { public static String getConversationsImageDirectory() { return Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_PICTURES).getAbsolutePath() + Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/Conversations/"; } @@ -155,12 +155,7 @@ public class FileBackend { return FileUtils.getPath(mXmppConnectionService,uri); } - public DownloadableFile copyFileToPrivateStorage(Message message, Uri uri) throws FileCopyException { - Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage"); - String mime = mXmppConnectionService.getContentResolver().getType(uri); - String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime); - message.setRelativeFilePath(message.getUuid() + "." + extension); - DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message); + public void copyFileToPrivateStorage(File file, Uri uri) throws FileCopyException { file.getParentFile().mkdirs(); OutputStream os = null; InputStream is = null; @@ -183,28 +178,18 @@ public class FileBackend { close(os); close(is); } - Log.d(Config.LOGTAG, "output file name " + mXmppConnectionService.getFileBackend().getFile(message)); - return file; + Log.d(Config.LOGTAG, "output file name " + file.getAbsolutePath()); } - public DownloadableFile copyImageToPrivateStorage(Message message, Uri image) - throws FileCopyException { - return this.copyImageToPrivateStorage(message, image, 0); + public void copyFileToPrivateStorage(Message message, Uri uri) throws FileCopyException { + Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage"); + String mime = mXmppConnectionService.getContentResolver().getType(uri); + String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime); + message.setRelativeFilePath(message.getUuid() + "." + extension); + copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri); } - private DownloadableFile copyImageToPrivateStorage(Message message,Uri image, int sampleSize) throws FileCopyException { - switch(Config.IMAGE_FORMAT) { - case JPEG: - message.setRelativeFilePath(message.getUuid()+".jpg"); - break; - case PNG: - message.setRelativeFilePath(message.getUuid()+".png"); - break; - case WEBP: - message.setRelativeFilePath(message.getUuid()+".webp"); - break; - } - DownloadableFile file = getFile(message); + private void copyImageToPrivateStorage(File file, Uri image, int sampleSize) throws FileCopyException { file.getParentFile().mkdirs(); InputStream is = null; OutputStream os = null; @@ -225,7 +210,6 @@ public class FileBackend { int rotation = getRotation(image); scaledBitmap = rotate(scaledBitmap, rotation); boolean targetSizeReached = false; - long size = 0; int quality = Config.IMAGE_QUALITY; while(!targetSizeReached) { os = new FileOutputStream(file); @@ -234,14 +218,11 @@ public class FileBackend { throw new FileCopyException(R.string.error_compressing_image); } os.flush(); - size = file.getSize(); - targetSizeReached = size <= Config.IMAGE_MAX_SIZE || quality <= 50; + targetSizeReached = file.length() <= Config.IMAGE_MAX_SIZE || quality <= 50; quality -= 5; } - int width = scaledBitmap.getWidth(); - int height = scaledBitmap.getHeight(); - message.setBody(Long.toString(size) + '|' + width + '|' + height); - return file; + scaledBitmap.recycle(); + return; } catch (FileNotFoundException e) { throw new FileCopyException(R.string.error_file_not_found); } catch (IOException e) { @@ -252,7 +233,7 @@ public class FileBackend { } catch (OutOfMemoryError e) { ++sampleSize; if (sampleSize <= 3) { - return copyImageToPrivateStorage(message, image, sampleSize); + copyImageToPrivateStorage(file, image, sampleSize); } else { throw new FileCopyException(R.string.error_out_of_memory); } @@ -264,6 +245,26 @@ public class FileBackend { } } + public void copyImageToPrivateStorage(File file, Uri image) throws FileCopyException { + copyImageToPrivateStorage(file, image, 0); + } + + public void copyImageToPrivateStorage(Message message, Uri image) throws FileCopyException { + switch(Config.IMAGE_FORMAT) { + case JPEG: + message.setRelativeFilePath(message.getUuid()+".jpg"); + break; + case PNG: + message.setRelativeFilePath(message.getUuid()+".png"); + break; + case WEBP: + message.setRelativeFilePath(message.getUuid()+".webp"); + break; + } + copyImageToPrivateStorage(getFile(message), image); + updateFileParams(message); + } + private int getRotation(File file) { return getRotation(Uri.parse("file://"+file.getAbsolutePath())); } -- cgit v1.2.3 From 7c0eae80591ec6b1562168be3d2a56315afc872a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 25 Jan 2016 21:17:53 +0100 Subject: expert setting to trigger extended connection options --- .../services/XmppConnectionService.java | 8 ++++-- .../conversations/ui/EditAccountActivity.java | 30 +++++++++++++++++----- .../siacs/conversations/xmpp/XmppConnection.java | 13 ++++++++-- src/main/res/values/strings.xml | 3 +++ src/main/res/xml/preferences.xml | 5 ++++ 5 files changed, 48 insertions(+), 11 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index a295b2cee..d4fda1b86 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1969,7 +1969,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } } - Element form = query.findChild("x","jabber:x:data"); + Element form = query.findChild("x", "jabber:x:data"); if (form != null) { conversation.getMucOptions().updateFormData(Data.parse(form)); } @@ -2378,7 +2378,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa updateConversationUi(); updateRosterUi(); } else { - Conversation conversation = find(account,avatar.owner.toBareJid()); + Conversation conversation = find(account, avatar.owner.toBareJid()); if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { MucOptions.User user = conversation.getMucOptions().findUser(avatar.owner.getResourcepart()); if (user != null) { @@ -2586,6 +2586,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return Config.FORCE_ORBOT || getPreferences().getBoolean("use_tor", false); } + public boolean showExtendedConnectionOptions() { + return getPreferences().getBoolean("show_connection_options", false); + } + public int unreadCount() { int count = 0; for (Conversation conversation : getConversations()) { diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 244906995..5c783f54f 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -5,6 +5,7 @@ import android.app.AlertDialog.Builder; import android.app.PendingIntent; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; @@ -91,7 +92,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate private Jid jidToEdit; private boolean mInitMode = false; - private boolean mUseTor = false; + private boolean mShowOptions = false; private Account mAccount; private String messageFingerprint; @@ -133,7 +134,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } String hostname = null; int numericPort = 5222; - if (mUseTor) { + if (mShowOptions) { hostname = mHostname.getText().toString(); final String port = mPort.getText().toString(); if (hostname.contains(" ")) { @@ -511,8 +512,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } } } - this.mUseTor = Config.FORCE_ORBOT || getPreferences().getBoolean("use_tor", false); - this.mNamePort.setVisibility(mUseTor ? View.VISIBLE : View.GONE); + SharedPreferences preferences = getPreferences(); + boolean useTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false); + this.mShowOptions = useTor || preferences.getBoolean("show_connection_options", false); + mHostname.setHint(useTor ? R.string.hostname_or_onion : R.string.hostname_example); + this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); } @Override @@ -598,7 +602,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mHostname.getEditableText().append(this.mAccount.getHostname()); this.mPort.setText(""); this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort())); - this.mNamePort.setVisibility(mUseTor ? View.VISIBLE : View.GONE); + this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); } if (!mInitMode) { @@ -740,12 +744,24 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } } else { if (this.mAccount.errorStatus()) { - this.mAccountJid.setError(getString(this.mAccount.getStatus().getReadableId())); + final EditText errorTextField; + if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) { + errorTextField = this.mPassword; + } else if (mShowOptions + && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND + && this.mHostname.getText().length() > 0) { + errorTextField = this.mHostname; + } else { + errorTextField = this.mAccountJid; + } + errorTextField.setError(getString(this.mAccount.getStatus().getReadableId())); if (init || !accountInfoEdited()) { - this.mAccountJid.requestFocus(); + errorTextField.requestFocus(); } } else { this.mAccountJid.setError(null); + this.mPassword.setError(null); + this.mHostname.setError(null); } this.mStats.setVisibility(View.GONE); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index a3dd06446..a39ccc37b 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -243,6 +243,7 @@ public class XmppConnection implements Runnable { tagWriter = new TagWriter(); this.changeStatus(Account.State.CONNECTING); final boolean useTor = mXmppConnectionService.useTorToConnect() || account.isOnion(); + final boolean extended = mXmppConnectionService.showExtendedConnectionOptions(); if (useTor) { String destination; if (account.getHostname() == null || account.getHostname().isEmpty()) { @@ -250,8 +251,16 @@ public class XmppConnection implements Runnable { } else { destination = account.getHostname(); } - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": connect to "+destination+" via TOR"); - socket = SocksSocketFactory.createSocketOverTor(destination,account.getPort()); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": connect to " + destination + " via TOR"); + socket = SocksSocketFactory.createSocketOverTor(destination, account.getPort()); + startXmpp(); + } else if (extended && account.getHostname() != null && !account.getHostname().isEmpty()) { + socket = new Socket(); + try { + socket.connect(new InetSocketAddress(account.getHostname(), account.getPort()), Config.SOCKET_TIMEOUT * 1000); + } catch (IOException e) { + throw new UnknownHostException(); + } startXmpp(); } else if (DNSHelper.isIp(account.getServer().toString())) { socket = new Socket(); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 38368383b..2034082de 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -529,6 +529,9 @@ Marks your resource as away when the screen is turned off Not available in silent mode Marks your resource as not available when device is in silent mode + Extended connection options + Show hostname and port options when setting up an account + xmpp.example.com Add account with certificate Unable to parse certificate Leave empty to authenticate w/ certificate diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index b3afe0c3e..6a5974c0e 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -155,6 +155,11 @@ android:key="use_tor" android:summary="@string/pref_use_tor_summary" android:title="@string/pref_use_tor"/> + Date: Tue, 26 Jan 2016 14:47:34 +0100 Subject: hide jid row in list item list when jid is null --- src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index 4be4931f7..47414f900 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -78,9 +78,10 @@ public class ListItemAdapter extends ArrayAdapter { } final Jid jid = item.getJid(); if (jid != null) { + tvJid.setVisibility(View.VISIBLE); tvJid.setText(jid.toString()); } else { - tvJid.setText(""); + tvJid.setVisibility(View.GONE); } tvName.setText(item.getDisplayName()); loadAvatar(item,picture); -- cgit v1.2.3 From d2c5a939ed2cf42374e0ddb528ee363b7fefee8c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 26 Jan 2016 17:23:24 +0100 Subject: show values in formfieldwrappers and allow form to be set to read only --- .../conversations/ui/forms/FormBooleanFieldWrapper.java | 14 ++++++++++++++ .../siacs/conversations/ui/forms/FormFieldWrapper.java | 11 +++++++---- .../ui/forms/FormJidSingleFieldWrapper.java | 11 +++++++++++ .../conversations/ui/forms/FormTextFieldWrapper.java | 17 +++++++++++++++++ .../eu/siacs/conversations/ui/forms/FormWrapper.java | 6 ++++++ .../java/eu/siacs/conversations/xmpp/forms/Data.java | 6 +++--- 6 files changed, 58 insertions(+), 7 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java index eba0f12d9..6cb357a90 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormBooleanFieldWrapper.java @@ -39,6 +39,15 @@ public class FormBooleanFieldWrapper extends FormFieldWrapper { return values; } + @Override + protected void setValues(List values) { + if (values.size() == 0) { + checkBox.setChecked(false); + } else { + checkBox.setChecked(Boolean.parseBoolean(values.get(0))); + } + } + @Override public boolean validates() { if (checkBox.isChecked() || !field.isRequired()) { @@ -63,4 +72,9 @@ public class FormBooleanFieldWrapper extends FormFieldWrapper { protected int getLayoutResource() { return R.layout.form_boolean; } + + @Override + void setReadOnly(boolean readOnly) { + checkBox.setEnabled(!readOnly); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java index 8ba62bdd8..3a21ade3b 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java @@ -45,10 +45,14 @@ public abstract class FormFieldWrapper { abstract List getValues(); + protected abstract void setValues(List values); + abstract boolean validates(); abstract protected int getLayoutResource(); + abstract void setReadOnly(boolean readOnly); + protected SpannableString createSpannableLabelString(String label, boolean required) { SpannableString spannableString = new SpannableString(label + (required ? " *" : "")); if (required) { @@ -61,11 +65,8 @@ public abstract class FormFieldWrapper { } protected void invokeOnFormFieldValuesEdited() { - Log.d(Config.LOGTAG, "invoke on form field values edited"); if (this.onFormFieldValuesEditedListener != null) { this.onFormFieldValuesEditedListener.onFormFieldValuesEdited(); - } else { - Log.d(Config.LOGTAG,"listener is null"); } } @@ -79,7 +80,9 @@ public abstract class FormFieldWrapper { protected static FormFieldWrapper createFromField(Class c, Context context, Field field) { try { - return c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field); + F fieldWrapper = c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field); + fieldWrapper.setValues(field.getValues()); + return fieldWrapper; } catch (Exception e) { e.printStackTrace(); return null; diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java index 3890a1a7a..553e8f21f 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormJidSingleFieldWrapper.java @@ -3,6 +3,8 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; import android.text.InputType; +import java.util.List; + import eu.siacs.conversations.R; import eu.siacs.conversations.xmpp.forms.Field; import eu.siacs.conversations.xmpp.jid.InvalidJidException; @@ -30,4 +32,13 @@ public class FormJidSingleFieldWrapper extends FormTextFieldWrapper { } return super.validates(); } + + @Override + protected void setValues(List values) { + StringBuilder builder = new StringBuilder(""); + for(String value : values) { + builder.append(value); + } + editText.setText(builder.toString()); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java index 47b8d86cb..b7dac9510 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormTextFieldWrapper.java @@ -62,6 +62,18 @@ public class FormTextFieldWrapper extends FormFieldWrapper { return values; } + @Override + protected void setValues(List values) { + StringBuilder builder = new StringBuilder(""); + for(int i = 0; i < values.size(); ++i) { + builder.append(values.get(i)); + if (i < values.size() - 1 && "text-multi".equals(field.getType())) { + builder.append("\n"); + } + } + editText.setText(builder.toString()); + } + @Override public boolean validates() { if (getValue().trim().length() > 0 || !field.isRequired()) { @@ -77,4 +89,9 @@ public class FormTextFieldWrapper extends FormFieldWrapper { protected int getLayoutResource() { return R.layout.form_text; } + + @Override + void setReadOnly(boolean readOnly) { + editText.setEnabled(!readOnly); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java index 51d15f0c2..eafe95cc8 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormWrapper.java @@ -52,6 +52,12 @@ public class FormWrapper { } } + public void setReadOnly(boolean b) { + for(FormFieldWrapper fieldWrapper : fieldWrappers) { + fieldWrapper.setReadOnly(b); + } + } + public boolean edited() { boolean edited = false; for(FormFieldWrapper fieldWrapper : fieldWrappers) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java index d05c9abb3..0053a399c 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java +++ b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java @@ -53,16 +53,16 @@ public class Data extends Element { public void submit() { this.setAttribute("type","submit"); - removeNonFieldChildren(); + removeUnnecessaryChildren(); for(Field field : getFields()) { field.removeNonValueChildren(); } } - private void removeNonFieldChildren() { + private void removeUnnecessaryChildren() { for(Iterator iterator = this.children.iterator(); iterator.hasNext();) { Element element = iterator.next(); - if (!element.getName().equals("field")) { + if (!element.getName().equals("field") && !element.getName().equals("title")) { iterator.remove(); } } -- cgit v1.2.3 From 28ebf927fb6cadc64a4f138cb84bac91c9903fdf Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 29 Jan 2016 12:09:31 +0100 Subject: try to make in-valid-session detection work for pgp --- src/main/java/eu/siacs/conversations/entities/Message.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index c5831e7ec..f3d891e86 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -743,13 +743,20 @@ public class Message extends AbstractEntity { } public boolean isValidInSession() { - int pastEncryption = this.getPreviousEncryption(); - int futureEncryption = this.getNextEncryption(); + int pastEncryption = getCleanedEncryption(this.getPreviousEncryption()); + int futureEncryption = getCleanedEncryption(this.getNextEncryption()); boolean inUnencryptedSession = pastEncryption == ENCRYPTION_NONE || futureEncryption == ENCRYPTION_NONE || pastEncryption != futureEncryption; - return inUnencryptedSession || this.getEncryption() == pastEncryption; + return inUnencryptedSession || getCleanedEncryption(this.getEncryption()) == pastEncryption; + } + + private static int getCleanedEncryption(int encryption) { + if (encryption == ENCRYPTION_DECRYPTED || encryption == ENCRYPTION_DECRYPTION_FAILED) { + return ENCRYPTION_PGP; + } + return encryption; } } -- cgit v1.2.3 From c416948f8bf188e1ff6369d5a5dbd7c1679976ee Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 29 Jan 2016 12:09:55 +0100 Subject: be more careful with resetting the stream id --- src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index a39ccc37b..37b2da685 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -549,7 +549,7 @@ public class XmppConnection implements Runnable { } else if (nextTag.isStart("failed")) { tagReader.readElement(nextTag); Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": resumption failed"); - streamId = null; + resetStreamId(); if (account.getStatus() != Account.State.ONLINE) { sendBindRequest(); } @@ -1290,7 +1290,6 @@ public class XmppConnection implements Runnable { } return; } else { - resetStreamId(); if (tagWriter.isActive()) { tagWriter.finish(); try { -- cgit v1.2.3