Skip to content

Commit

Permalink
Select appearances improvements (#3079)
Browse files Browse the repository at this point in the history
Select appearances improvements
  • Loading branch information
lognaturel authored May 22, 2019
2 parents 56e7700 + 0d1e45f commit 7fe83b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class WidgetAppearanceUtils {
public static final String MINIMAL = "minimal";
public static final String COLUMNS = "columns";
public static final String COLUMNS_N = "columns-";
public static final String COLUMNS_FLEX = "columns-flex";
public static final String COLUMNS_PACK = "columns-pack";
@Deprecated public static final String QUICKCOMPACT = "quickcompact";
@Deprecated public static final String SEARCH = "search";
public static final String AUTOCOMPLETE = "autocomplete";
Expand Down Expand Up @@ -122,6 +122,10 @@ public static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context co
numColumns = Integer.parseInt(substringFromNumColumns.substring(0, substringFromNumColumns.contains(" ")
? substringFromNumColumns.indexOf(' ')
: substringFromNumColumns.length()));

if (numColumns < 1) {
numColumns = 1;
}
}
} catch (Exception e) {
Timber.e(EXCEPTION_PARSING_COLUMNS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static QuestionWidget createWidgetFromPrompt(FormEntryPrompt fep, Context
// This means normal appearances should be put before search().
if (!appearance.startsWith(WidgetAppearanceUtils.COMPACT_N) && (appearance.startsWith(WidgetAppearanceUtils.COMPACT)
|| appearance.startsWith(WidgetAppearanceUtils.QUICKCOMPACT)
|| appearance.startsWith(WidgetAppearanceUtils.COLUMNS_FLEX))) {
|| appearance.startsWith(WidgetAppearanceUtils.COLUMNS_PACK))) {
questionWidget = new GridWidget(context, fep, appearance.contains(WidgetAppearanceUtils.QUICK));
} else if (appearance.contains(WidgetAppearanceUtils.MINIMAL)) {
questionWidget = new SpinnerWidget(context, fep, appearance.contains(WidgetAppearanceUtils.QUICK));
Expand All @@ -176,7 +176,7 @@ public static QuestionWidget createWidgetFromPrompt(FormEntryPrompt fep, Context
// This means normal appearances should be put before search().
if (!appearance.startsWith(WidgetAppearanceUtils.COMPACT_N)
&& (appearance.startsWith(WidgetAppearanceUtils.COMPACT)
|| appearance.startsWith(WidgetAppearanceUtils.COLUMNS_FLEX))) {
|| appearance.startsWith(WidgetAppearanceUtils.COLUMNS_PACK))) {
questionWidget = new GridMultiWidget(context, fep);
} else if (appearance.startsWith(WidgetAppearanceUtils.MINIMAL)) {
questionWidget = new SpinnerMultiWidget(context, fep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,17 @@ public void getNumberOfColumnsTest() {

when(formEntryPrompt.getAppearanceHint()).thenReturn("compact-5");
assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("compact-9");
assertEquals(9, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-9");
assertEquals(9, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("columns--1");
assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("columns--10");
assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));
}
}

0 comments on commit 7fe83b3

Please sign in to comment.