From 1e419ca1eecc693516d08d7d3b037eb0faa401df Mon Sep 17 00:00:00 2001 From: grzegorz Date: Tue, 21 May 2019 13:48:54 +0200 Subject: [PATCH 1/2] Renamed columns-flex to columns-pack --- .../odk/collect/android/utilities/WidgetAppearanceUtils.java | 2 +- .../java/org/odk/collect/android/widgets/WidgetFactory.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java b/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java index a4f2bf20a00..75b4b110612 100644 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java @@ -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"; diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/WidgetFactory.java b/collect_app/src/main/java/org/odk/collect/android/widgets/WidgetFactory.java index 0e718e95a70..ca6693e918f 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/WidgetFactory.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/WidgetFactory.java @@ -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)); @@ -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); From 0d1e45fe3331492d661ee9eecf7e436d8da5dedc Mon Sep 17 00:00:00 2001 From: grzegorz Date: Tue, 21 May 2019 13:53:08 +0200 Subject: [PATCH 2/2] Validate number of columns, it should not be < 1 --- .../android/utilities/WidgetAppearanceUtils.java | 4 ++++ .../android/utilities/WidgetAppearanceUtilsTest.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java b/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java index 75b4b110612..0e63c829a10 100644 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/utilities/WidgetAppearanceUtils.java @@ -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); diff --git a/collect_app/src/test/java/org/odk/collect/android/utilities/WidgetAppearanceUtilsTest.java b/collect_app/src/test/java/org/odk/collect/android/utilities/WidgetAppearanceUtilsTest.java index 4fecb015d0b..071adc5629a 100644 --- a/collect_app/src/test/java/org/odk/collect/android/utilities/WidgetAppearanceUtilsTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/utilities/WidgetAppearanceUtilsTest.java @@ -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)); } }