fix commands related bugs

This commit is contained in:
kosyak 2024-02-19 03:58:26 +01:00
parent d5a089fb24
commit 16a834e0eb
13 changed files with 67 additions and 22 deletions

View file

@ -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'
}

View file

@ -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<CommandUnknownBinding> {
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);
}

View file

@ -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" />
</layout>

View file

@ -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"

View file

@ -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" />

View file

@ -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" />

View file

@ -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"

View file

@ -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" />

View file

@ -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"

View file

@ -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"

View file

@ -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" />

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<View
android:layout_width="0dp"
android:layout_height="0dp"/>
</layout>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
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"
android:background="@drawable/list_choice" />