Allow button grid prev

This commit is contained in:
Stephen Paul Weber 2024-02-19 04:11:32 +01:00 committed by Arne
parent 48aad97820
commit f8bb4d46e6

View file

@ -2949,7 +2949,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
final String datatype = validate == null ? null : validate.getAttribute("datatype");
final Element range = validate == null ? null : validate.findChild("range", "http://jabber.org/protocol/xdata-validate");
if (fieldType.equals("boolean")) {
if (fillableFieldCount == 1 && actionsAdapter.countExceptCancel() < 1) {
if (fillableFieldCount == 1 && actionsAdapter.countProceed() < 1) {
viewType = TYPE_BUTTON_GRID_FIELD;
} else {
viewType = TYPE_CHECKBOX_FIELD;
@ -2963,7 +2963,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
) {
// has a range and is numeric, use a slider
viewType = TYPE_SLIDER_FIELD;
if (fillableFieldCount == 1 && actionsAdapter.countExceptCancel() < 1) {
if (fillableFieldCount == 1 && actionsAdapter.countProceed() < 1 && Option.forField(el).size() < 50) {
viewType = TYPE_BUTTON_GRID_FIELD;
} else if (Option.forField(el).size() > 9) {
viewType = TYPE_SEARCH_LIST_FIELD;
@ -3037,6 +3037,14 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return -1;
}
public int countProceed() {
int count = 0;
for(int i = 0; i < getCount(); i++) {
if (!"cancel".equals(getItem(i).first) && !"prev".equals(getItem(i).first)) count++;
}
return count;
}
public int countExceptCancel() {
int count = 0;
for(int i = 0; i < getCount(); i++) {
@ -3045,13 +3053,16 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return count;
}
public void clearExceptCancel() {
public void clearProceed() {
Pair<String,String> cancelItem = null;
Pair<String,String> prevItem = null;
for(int i = 0; i < getCount(); i++) {
if (getItem(i).first.equals("cancel")) cancelItem = getItem(i);
if (getItem(i).first.equals("prev")) prevItem = getItem(i);
}
clear();
if (cancelItem != null) add(cancelItem);
if (prevItem != null) add(prevItem);
}
}
@ -3186,19 +3197,17 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
}
String fillableFieldType = null;
String fillableFieldValue = null;
eu.siacs.conversations.xmpp.forms.Field fillableField = null;
for (eu.siacs.conversations.xmpp.forms.Field field : form.getFields()) {
if ((field.getType() == null || (!field.getType().equals("hidden") && !field.getType().equals("fixed"))) && field.getFieldName() != null && !field.getFieldName().equals("http://jabber.org/protocol/commands#actions")) {
fillableFieldType = field.getType();
fillableFieldValue = field.getValue();
fillableField = field;
fillableFieldCount++;
}
}
if (fillableFieldCount == 1 && actionsAdapter.countExceptCancel() < 2 && fillableFieldType != null && (fillableFieldType.equals("list-single") || (fillableFieldType.equals("boolean") && fillableFieldValue == null))) {
if (fillableFieldCount == 1 && actionsAdapter.countProceed() < 2 && (("list-single".equals(fillableField.getType()) && Option.forField(fillableField).size() < 50) || ("boolean".equals(fillableField.getType()) && fillableField.getValue() == null))) {
actionsCleared = true;
actionsAdapter.clearExceptCancel();
actionsAdapter.clearProceed();
}
break;
}