From 16a834e0eb2d3443290d2e4df3bb4f1a16e845de Mon Sep 17 00:00:00 2001 From: kosyak Date: Mon, 19 Feb 2024 03:58:26 +0100 Subject: [PATCH] fix commands related bugs --- build.gradle | 2 +- .../conversations/entities/Conversation.java | 42 +++++++++---------- src/main/res/layout/command_button.xml | 1 + .../res/layout/command_button_grid_field.xml | 1 + .../res/layout/command_checkbox_field.xml | 1 + src/main/res/layout/command_note.xml | 1 + .../res/layout/command_radio_edit_field.xml | 1 + src/main/res/layout/command_result_field.xml | 1 + src/main/res/layout/command_row.xml | 1 + .../res/layout/command_search_list_field.xml | 1 + src/main/res/layout/command_spinner_field.xml | 1 + src/main/res/layout/command_unknown.xml | 9 ++++ .../simple_list_item_selectable_text.xml | 27 ++++++++++++ 13 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 src/main/res/layout/command_unknown.xml create mode 100644 src/main/res/layout/simple_list_item_selectable_text.xml diff --git a/build.gradle b/build.gradle index 0974217e1..9269d10ed 100644 --- a/build.gradle +++ b/build.gradle @@ -101,7 +101,7 @@ dependencies { implementation 'com.github.kizitonwose.colorpreference:support:1.1.0' implementation 'com.caverock:androidsvg-aar:1.4' implementation 'com.github.singpolyma:Better-Link-Movement-Method:4df081e1e4' - + debugImplementation 'com.squareup.leakcanary:leakcanary-android:3.0-alpha-1' } diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index e61cf1dd1..6f31d4f6a 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -22,6 +22,7 @@ import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; import android.text.TextWatcher; +import android.text.util.Linkify; import android.util.DisplayMetrics; import android.util.LruCache; import android.util.Pair; @@ -106,6 +107,7 @@ import eu.siacs.conversations.databinding.CommandResultFieldBinding; import eu.siacs.conversations.databinding.CommandSearchListFieldBinding; import eu.siacs.conversations.databinding.CommandSpinnerFieldBinding; import eu.siacs.conversations.databinding.CommandTextFieldBinding; +import eu.siacs.conversations.databinding.CommandUnknownBinding; import eu.siacs.conversations.databinding.CommandWebviewBinding; import eu.siacs.conversations.databinding.DialogQuickeditBinding; import eu.siacs.conversations.http.HttpConnectionManager; @@ -2047,6 +2049,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return true; }); binding.text.setMovementMethod(method); + Linkify.addLinks(binding.text, Linkify.ALL); } } } @@ -2170,7 +2173,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } else { filteredOptions = options.stream().filter(o -> o.toString().replaceAll("\\W", "").toLowerCase().contains(q)).collect(Collectors.toList()); } - adapter = new ArrayAdapter(binding.getRoot().getContext(), R.layout.simple_list_item, filteredOptions); + adapter = new ArrayAdapter(binding.getRoot().getContext(), R.layout.simple_list_item_selectable_text, filteredOptions); binding.list.setAdapter(adapter); int checkedPos = filteredOptions.indexOf(new Option(mValue.getContent(), "")); @@ -2394,7 +2397,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl break; } } - if (defaultOption == null && !mValue.getContent().equals("")) { + if (defaultOption == null && mValue.getContent() != null && !mValue.getContent().equals("")) { // Synthesize default option for custom value defaultOption = new Option(mValue.getContent(), mValue.getContent()); } @@ -2542,6 +2545,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } + class UnknownViewHolder extends ViewHolder { + public UnknownViewHolder(CommandUnknownBinding binding) { super(binding); } + + @Override + public void bind(Item item) {} + } + class Item { protected Element el; protected int viewType; @@ -2634,7 +2644,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } protected Field mkField(Element el) { - int viewType = -1; + int viewType = TYPE_UNKNOWN; String formType = responseElement.getAttribute("type"); if (formType != null) { @@ -2666,10 +2676,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } - if (viewType == -1) { - throw new RuntimeException("Invalid field " + responseElement.getName() + " " + formType + " " + fieldType + " " + el.getName() + " " + el); - } - return new Field(eu.siacs.conversations.xmpp.forms.Field.parse(el), viewType); } @@ -2677,7 +2683,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } protected Item mkItem(Element el, int pos) { - int viewType = -1; + int viewType = TYPE_UNKNOWN; if (response != null && response.getType() == IqPacket.TYPE.RESULT) { if (el.getName().equals("note")) { @@ -2693,22 +2699,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return field; } } - - if (viewType == -1) { - throw new RuntimeException("Invalid element " + el.getName() + " " + el.getNamespace() + " " + el); - } } else if (response != null) { viewType = TYPE_ERROR; } - if (viewType == -1) { - if (responseElement == null) { - throw new RuntimeException("Invalid element - nullable response"); - } else { - throw new RuntimeException("Invalid element, type " + response.getType()); - } - } - Item item = new Item(el, viewType); items.put(pos, item); return item; @@ -2718,7 +2712,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl protected Context ctx; public ActionsAdapter(Context ctx) { - super(ctx, R.layout.simple_list_item); + super(ctx, R.layout.simple_list_item_selectable_text); this.ctx = ctx; } @@ -2774,6 +2768,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl final int TYPE_ITEM_CARD = 12; final int TYPE_BUTTON_GRID_FIELD = 13; + final int TYPE_UNKNOWN = 100; + protected boolean executing = false; protected boolean loading = false; protected boolean loadingHasBeenLong = false; @@ -3142,6 +3138,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl CommandProgressBarBinding binding = DataBindingUtil.inflate(LayoutInflater.from(container.getContext()), R.layout.command_progress_bar, container, false); return new ProgressBarViewHolder(binding); } + case TYPE_UNKNOWN: { + CommandUnknownBinding binding = DataBindingUtil.inflate(LayoutInflater.from(container.getContext()), R.layout.command_unknown, container, false); + return new UnknownViewHolder(binding); + } default: throw new IllegalArgumentException("Unknown viewType: " + viewType + " based on: " + response); } diff --git a/src/main/res/layout/command_button.xml b/src/main/res/layout/command_button.xml index 9f0df64c2..ff68034f3 100644 --- a/src/main/res/layout/command_button.xml +++ b/src/main/res/layout/command_button.xml @@ -4,5 +4,6 @@ android:id="@+id/command" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:textIsSelectable="true" style="?android:attr/buttonStyleSmall" /> diff --git a/src/main/res/layout/command_button_grid_field.xml b/src/main/res/layout/command_button_grid_field.xml index 8035bea79..ead3e4ac1 100644 --- a/src/main/res/layout/command_button_grid_field.xml +++ b/src/main/res/layout/command_button_grid_field.xml @@ -22,6 +22,7 @@ android:id="@+id/desc" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textIsSelectable="true" android:paddingLeft="16dp" android:paddingRight="8dp" android:gravity="center" diff --git a/src/main/res/layout/command_checkbox_field.xml b/src/main/res/layout/command_checkbox_field.xml index d27b6af38..2ef5be4c9 100644 --- a/src/main/res/layout/command_checkbox_field.xml +++ b/src/main/res/layout/command_checkbox_field.xml @@ -30,6 +30,7 @@ android:id="@+id/desc" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:textIsSelectable="true" android:paddingLeft="16dp" android:textAppearance="@style/TextAppearance.Conversations.Status" android:textColor="?android:textColorSecondary" /> diff --git a/src/main/res/layout/command_note.xml b/src/main/res/layout/command_note.xml index cbb41fd45..0d7d27a61 100644 --- a/src/main/res/layout/command_note.xml +++ b/src/main/res/layout/command_note.xml @@ -24,6 +24,7 @@ android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingLeft="8dp" android:paddingRight="8dp" + android:textIsSelectable="true" android:textAppearance="@style/TextAppearance.Conversations.Body1" android:textColor="?attr/edit_text_color" /> diff --git a/src/main/res/layout/command_radio_edit_field.xml b/src/main/res/layout/command_radio_edit_field.xml index a55a3c6e1..7024fb581 100644 --- a/src/main/res/layout/command_radio_edit_field.xml +++ b/src/main/res/layout/command_radio_edit_field.xml @@ -44,6 +44,7 @@ android:id="@+id/desc" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textIsSelectable="true" android:paddingLeft="16dp" android:paddingRight="8dp" android:textAppearance="@style/TextAppearance.Conversations.Status" diff --git a/src/main/res/layout/command_result_field.xml b/src/main/res/layout/command_result_field.xml index 580e03781..a2298d338 100644 --- a/src/main/res/layout/command_result_field.xml +++ b/src/main/res/layout/command_result_field.xml @@ -46,6 +46,7 @@ android:layout_height="wrap_content" android:paddingLeft="8dp" android:paddingRight="8dp" + android:textIsSelectable="true" android:textAppearance="@style/TextAppearance.Conversations.Status" android:textColor="?android:textColorSecondary" /> diff --git a/src/main/res/layout/command_row.xml b/src/main/res/layout/command_row.xml index 81c90fe67..278635bcb 100644 --- a/src/main/res/layout/command_row.xml +++ b/src/main/res/layout/command_row.xml @@ -6,6 +6,7 @@ android:id="@+id/command" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textIsSelectable="true" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingLeft="@dimen/avatar_item_distance" diff --git a/src/main/res/layout/command_search_list_field.xml b/src/main/res/layout/command_search_list_field.xml index 903b87d7c..8d2f5b024 100644 --- a/src/main/res/layout/command_search_list_field.xml +++ b/src/main/res/layout/command_search_list_field.xml @@ -38,6 +38,7 @@ android:id="@+id/desc" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textIsSelectable="true" android:paddingLeft="16dp" android:paddingRight="8dp" android:textAppearance="@style/TextAppearance.Conversations.Status" diff --git a/src/main/res/layout/command_spinner_field.xml b/src/main/res/layout/command_spinner_field.xml index 1909173af..104441483 100644 --- a/src/main/res/layout/command_spinner_field.xml +++ b/src/main/res/layout/command_spinner_field.xml @@ -31,6 +31,7 @@ android:layout_height="wrap_content" android:paddingLeft="16dp" android:paddingRight="8dp" + android:textIsSelectable="true" android:textAppearance="@style/TextAppearance.Conversations.Status" android:textColor="?android:textColorSecondary" /> diff --git a/src/main/res/layout/command_unknown.xml b/src/main/res/layout/command_unknown.xml new file mode 100644 index 000000000..54ebb5851 --- /dev/null +++ b/src/main/res/layout/command_unknown.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/src/main/res/layout/simple_list_item_selectable_text.xml b/src/main/res/layout/simple_list_item_selectable_text.xml new file mode 100644 index 000000000..bd2800e32 --- /dev/null +++ b/src/main/res/layout/simple_list_item_selectable_text.xml @@ -0,0 +1,27 @@ + + +