From b2806b2f873b5b212aa9204811bdb2a2c6b3a397 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 24 Jul 2024 21:28:12 +0200 Subject: [PATCH 1/7] Added Buddhist calendar --- .../dialogs/BuddhistDatePickerDialog.kt | 78 +++++++++++++++++++ .../android/logic/DatePickerDetails.java | 2 +- .../collect/android/utilities/Appearances.kt | 1 + .../utilities/DateTimeWidgetUtils.java | 11 +++ collect_app/src/main/res/values/arrays.xml | 15 +++- 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt b/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt new file mode 100644 index 00000000000..745bbec42dc --- /dev/null +++ b/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt @@ -0,0 +1,78 @@ +package org.odk.collect.android.fragments.dialogs + +import org.joda.time.LocalDateTime +import org.joda.time.chrono.BuddhistChronology +import org.odk.collect.android.R +import org.odk.collect.android.utilities.DateTimeUtils + +class BuddhistDatePickerDialog : CustomDatePickerDialog() { + companion object { + const val MIN_SUPPORTED_YEAR = 2443 // 1900 in Gregorian calendar + const val MAX_SUPPORTED_YEAR = 2643 // 2100 in Gregorian calendar + } + + private lateinit var monthsArray: Array + + override fun onResume() { + super.onResume() + monthsArray = resources.getStringArray(R.array.buddhist_months) + setUpValues() + } + + override fun updateDays() { + val localDateTime = getCurrentBuddhistDate() + setUpDayPicker(localDateTime.dayOfMonth, localDateTime.dayOfMonth().maximumValue) + } + + override fun getOriginalDate(): LocalDateTime { + return getCurrentBuddhistDate() + } + + private fun setUpDatePicker() { + val buddhistDate = DateTimeUtils + .skipDaylightSavingGapIfExists(date) + .toDateTime() + .withChronology(BuddhistChronology.getInstance()) + .toLocalDateTime() + + setUpDayPicker(buddhistDate.dayOfMonth, buddhistDate.dayOfMonth().maximumValue) + setUpMonthPicker(buddhistDate.monthOfYear, monthsArray) + setUpYearPicker(buddhistDate.year, MIN_SUPPORTED_YEAR, MAX_SUPPORTED_YEAR) + } + + private fun setUpValues() { + setUpDatePicker() + updateGregorianDateLabel() + } + + private fun getCurrentBuddhistDate(): LocalDateTime { + var buddhistDay = day + val buddhistMonth = monthsArray.indexOf(month) + val buddhistYear = year + + val buddhistDate = LocalDateTime( + buddhistYear, + buddhistMonth + 1, + 1, + 0, + 0, + 0, + 0, + BuddhistChronology.getInstance() + ) + if (buddhistDay > buddhistDate.dayOfMonth().maximumValue) { + buddhistDay = buddhistDate.dayOfMonth().maximumValue + } + + return LocalDateTime( + buddhistYear, + buddhistMonth + 1, + buddhistDay, + 0, + 0, + 0, + 0, + BuddhistChronology.getInstance() + ) + } +} diff --git a/collect_app/src/main/java/org/odk/collect/android/logic/DatePickerDetails.java b/collect_app/src/main/java/org/odk/collect/android/logic/DatePickerDetails.java index c40bdf3136a..c864d686939 100644 --- a/collect_app/src/main/java/org/odk/collect/android/logic/DatePickerDetails.java +++ b/collect_app/src/main/java/org/odk/collect/android/logic/DatePickerDetails.java @@ -20,7 +20,7 @@ public class DatePickerDetails implements Serializable { public enum DatePickerType { - GREGORIAN, ETHIOPIAN, COPTIC, ISLAMIC, BIKRAM_SAMBAT, MYANMAR, PERSIAN + GREGORIAN, ETHIOPIAN, COPTIC, ISLAMIC, BIKRAM_SAMBAT, MYANMAR, PERSIAN, BUDDHIST } public enum DatePickerMode { diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/Appearances.kt b/collect_app/src/main/java/org/odk/collect/android/utilities/Appearances.kt index 12f3331f62e..3e5915d2596 100644 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/Appearances.kt +++ b/collect_app/src/main/java/org/odk/collect/android/utilities/Appearances.kt @@ -29,6 +29,7 @@ object Appearances { const val BIKRAM_SAMBAT = "bikram-sambat" const val MYANMAR = "myanmar" const val PERSIAN = "persian" + const val BUDDHIST = "buddhist" const val NO_CALENDAR = "no-calendar" const val MONTH_YEAR = "month-year" const val YEAR = "year" diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java index b435217ae72..ee5dde566b4 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java @@ -8,12 +8,14 @@ import org.joda.time.DateTime; import org.joda.time.LocalDateTime; +import org.joda.time.chrono.BuddhistChronology; import org.joda.time.chrono.CopticChronology; import org.joda.time.chrono.EthiopicChronology; import org.joda.time.chrono.IslamicChronology; import org.joda.time.chrono.PersianChronologyKhayyamBorkowski; import org.odk.collect.android.R; import org.odk.collect.android.fragments.dialogs.BikramSambatDatePickerDialog; +import org.odk.collect.android.fragments.dialogs.BuddhistDatePickerDialog; import org.odk.collect.android.fragments.dialogs.CopticDatePickerDialog; import org.odk.collect.android.fragments.dialogs.CustomTimePickerDialog; import org.odk.collect.android.fragments.dialogs.EthiopianDatePickerDialog; @@ -70,6 +72,9 @@ public static DatePickerDetails getDatePickerDetails(String appearance) { } else if (appearance.contains(Appearances.PERSIAN)) { datePickerType = DatePickerDetails.DatePickerType.PERSIAN; datePickerMode = DatePickerDetails.DatePickerMode.SPINNERS; + } else if (appearance.contains(Appearances.BUDDHIST)) { + datePickerType = DatePickerDetails.DatePickerType.BUDDHIST; + datePickerMode = DatePickerDetails.DatePickerMode.SPINNERS; } else if (appearance.contains(Appearances.NO_CALENDAR)) { datePickerMode = DatePickerDetails.DatePickerMode.SPINNERS; } @@ -120,6 +125,10 @@ public static String getDateTimeLabel(Date date, DatePickerDetails datePickerDet customDate = new DateTime(date).withChronology(PersianChronologyKhayyamBorkowski.getInstance()); monthArray = context.getResources().getStringArray(R.array.persian_months); break; + case BUDDHIST: + customDate = new DateTime(date).withChronology(BuddhistChronology.getInstance()); + monthArray = context.getResources().getStringArray(R.array.buddhist_months); + break; default: Timber.w("Not supported date type."); return null; @@ -214,6 +223,8 @@ private static Class getClass(DatePickerDetails.DatePickerType datePickerType) { return MyanmarDatePickerDialog.class; case PERSIAN: return PersianDatePickerDialog.class; + case BUDDHIST: + return BuddhistDatePickerDialog.class; default: return FixedDatePickerDialog.class; } diff --git a/collect_app/src/main/res/values/arrays.xml b/collect_app/src/main/res/values/arrays.xml index b5a54b22416..52d98bbd6a2 100644 --- a/collect_app/src/main/res/values/arrays.xml +++ b/collect_app/src/main/res/values/arrays.xml @@ -147,7 +147,20 @@ the specific language governing permissions and limitations under the License. - @string/persian_month_11 @string/persian_month_12 - + + มกราคม + กุมภาพันธ์ + มีนาคม + เมษายน + พฤษภาคม + มิถุนายน + กรกฎาคม + สิงหาคม + กันยายน + ตุลาคม + พฤศจิกายน + ธันวาคม + @string/every_fifteen_minutes_value @string/every_one_hour_value From b08b7f398c52b630ea6dbe02582e96b7619840c2 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 24 Jul 2024 21:30:15 +0200 Subject: [PATCH 2/7] Added tests --- .../utilities/DateTimeUtilsTest.java | 5 ++++ .../utilities/DateTimeWidgetUtilsTest.java | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java index 6aa17297edb..4b7fbffddcd 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java @@ -46,6 +46,7 @@ public class DateTimeUtilsTest { private DatePickerDetails bikramSambatDatePickerDetails; private DatePickerDetails myanmarDatePickerDetails; private DatePickerDetails persianDatePickerDetails; + private DatePickerDetails buddhistDatePickerDetails; private Context context; private Locale defaultLocale; @@ -60,6 +61,7 @@ public void setUp() { bikramSambatDatePickerDetails = new DatePickerDetails(DatePickerDetails.DatePickerType.BIKRAM_SAMBAT, DatePickerDetails.DatePickerMode.SPINNERS); myanmarDatePickerDetails = new DatePickerDetails(DatePickerDetails.DatePickerType.MYANMAR, DatePickerDetails.DatePickerMode.SPINNERS); persianDatePickerDetails = new DatePickerDetails(DatePickerDetails.DatePickerType.PERSIAN, DatePickerDetails.DatePickerMode.SPINNERS); + buddhistDatePickerDetails = new DatePickerDetails(DatePickerDetails.DatePickerType.BUDDHIST, DatePickerDetails.DatePickerMode.SPINNERS); context = Collect.getInstance(); defaultLocale = Locale.getDefault(); @@ -96,6 +98,9 @@ public void getDateTimeLabelTest() { assertEquals("28 Mehr 1370 (Oct 20, 1991)", DateTimeWidgetUtils.getDateTimeLabel(date, persianDatePickerDetails, false, context)); assertEquals("28 Mehr 1370, 14:00 (Oct 20, 1991, 14:00)", DateTimeWidgetUtils.getDateTimeLabel(date, persianDatePickerDetails, true, context)); + + assertEquals("20 ตุลาคม 2534 (Oct 20, 1991)", DateTimeWidgetUtils.getDateTimeLabel(date, buddhistDatePickerDetails, false, context)); + assertEquals("20 ตุลาคม 2534, 14:00 (Oct 20, 1991, 14:00)", DateTimeWidgetUtils.getDateTimeLabel(date, buddhistDatePickerDetails, true, context)); } @After diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtilsTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtilsTest.java index 64172265ef0..c93848f26b2 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtilsTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtilsTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.fragments.dialogs.BikramSambatDatePickerDialog; +import org.odk.collect.android.fragments.dialogs.BuddhistDatePickerDialog; import org.odk.collect.android.fragments.dialogs.CopticDatePickerDialog; import org.odk.collect.android.fragments.dialogs.CustomTimePickerDialog; import org.odk.collect.android.fragments.dialogs.EthiopianDatePickerDialog; @@ -26,6 +27,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.BIKRAM_SAMBAT; +import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.BUDDHIST; import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.COPTIC; import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.ETHIOPIAN; import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.GREGORIAN; @@ -72,6 +74,10 @@ public class DateTimeWidgetUtilsTest { private DatePickerDetails persianMonthYear; private DatePickerDetails persianYear; + private DatePickerDetails buddhist; + private DatePickerDetails buddhistMonthYear; + private DatePickerDetails buddhistYear; + @Before public void setUp() { dateTimeWidgetUtils = new DateTimeWidgetUtils(); @@ -110,6 +116,10 @@ public void setUp() { persian = new DatePickerDetails(DatePickerDetails.DatePickerType.PERSIAN, DatePickerDetails.DatePickerMode.SPINNERS); persianMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.PERSIAN, DatePickerDetails.DatePickerMode.MONTH_YEAR); persianYear = new DatePickerDetails(DatePickerDetails.DatePickerType.PERSIAN, DatePickerDetails.DatePickerMode.YEAR); + + buddhist = new DatePickerDetails(DatePickerDetails.DatePickerType.BUDDHIST, DatePickerDetails.DatePickerMode.SPINNERS); + buddhistMonthYear = new DatePickerDetails(DatePickerDetails.DatePickerType.BUDDHIST, DatePickerDetails.DatePickerMode.MONTH_YEAR); + buddhistYear = new DatePickerDetails(DatePickerDetails.DatePickerType.BUDDHIST, DatePickerDetails.DatePickerMode.YEAR); } @Test @@ -195,6 +205,17 @@ public void getDatePickerDetailsTest() { assertEquals(persianYear, DateTimeWidgetUtils.getDatePickerDetails(appearance)); appearance = "year persian"; assertEquals(persianYear, DateTimeWidgetUtils.getDatePickerDetails(appearance)); + + appearance = "buddhist"; + assertEquals(buddhist, DateTimeWidgetUtils.getDatePickerDetails(appearance)); + appearance = "Buddhist month-year"; + assertEquals(buddhistMonthYear, DateTimeWidgetUtils.getDatePickerDetails(appearance)); + appearance = "month-year buddhist"; + assertEquals(buddhistMonthYear, DateTimeWidgetUtils.getDatePickerDetails(appearance)); + appearance = "Buddhist year"; + assertEquals(buddhistYear, DateTimeWidgetUtils.getDatePickerDetails(appearance)); + appearance = "year buddhist"; + assertEquals(buddhistYear, DateTimeWidgetUtils.getDatePickerDetails(appearance)); } @Test @@ -241,6 +262,11 @@ public void displayDatePickerDialog_showsPersianDatePickerDialog_whenDatePickerT assertDialogIsShowing(PERSIAN, PersianDatePickerDialog.class); } + @Test + public void displayDatePickerDialog_showsBuddhistDatePickerDialog_whenDatePickerTypeIsBuddhist() { + assertDialogIsShowing(BUDDHIST, BuddhistDatePickerDialog.class); + } + @Test public void displayDatePickerDialogWithYearMode_showsDatePickerWithDayAndMonthFixedToJanuaryFirst() { when(datePickerDetails.getDatePickerType()).thenReturn(GREGORIAN); From 35150b9fa7bfc69a5090271672daaf27b8f7e896 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Fri, 26 Jul 2024 19:21:04 +0200 Subject: [PATCH 3/7] Added BuddhistDatePickerDialogTest --- .../dialogs/CustomDatePickerDialog.java | 2 +- .../dialogs/BuddhistDatePickerDialogTest.kt | 304 ++++++++++++++++++ .../odk/collect/android/support/Actions.kt | 56 ++++ 3 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialogTest.kt create mode 100644 collect_app/src/test/java/org/odk/collect/android/support/Actions.kt diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomDatePickerDialog.java index c69b93d2c0f..5fa39ca606b 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomDatePickerDialog.java @@ -67,7 +67,7 @@ public void onAttach(Context context) { viewModel.setDatePickerDetails((DatePickerDetails) getArguments().getSerializable(DateTimeWidgetUtils.DATE_PICKER_DETAILS)); viewModel.getSelectedDate().observe(this, localDateTime -> { - if (localDateTime != null) { + if (localDateTime != null && dateChangeListener != null) { dateChangeListener.onDateChanged(localDateTime); } }); diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialogTest.kt b/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialogTest.kt new file mode 100644 index 00000000000..27e757e3bdd --- /dev/null +++ b/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialogTest.kt @@ -0,0 +1,304 @@ +package org.odk.collect.android.fragments.dialogs + +import android.os.Bundle +import androidx.fragment.app.testing.FragmentScenario +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.matcher.RootMatchers.isDialog +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.notNullValue +import org.hamcrest.Matchers.nullValue +import org.joda.time.LocalDateTime +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.odk.collect.android.R +import org.odk.collect.android.logic.DatePickerDetails +import org.odk.collect.android.logic.DatePickerDetails.DatePickerMode +import org.odk.collect.android.support.Actions +import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils +import org.odk.collect.fragmentstest.FragmentScenarioLauncherRule +import org.odk.collect.strings.R.string +import org.odk.collect.testshared.Assertions +import org.odk.collect.testshared.Interactions + +@RunWith(AndroidJUnit4::class) +class BuddhistDatePickerDialogTest { + @get:Rule + val launcherRule = FragmentScenarioLauncherRule() + + @Test + fun `The dialog is cancelable`() { + val scenario = launchFragment(2010, 5, 12) + scenario.onFragment { + assertThat(it.isCancelable, equalTo(true)) + } + } + + @Test + fun `The dialog shows correct date`() { + launchFragment(2010, 5, 12, DatePickerMode.SPINNERS) + Assertions.assertText(withText("12 พฤษภาคม 2553 (May 12, 2010)"), isDialog()) + + updateDate(6, 0, 2447) + Assertions.assertText(withText("6 มกราคม 2447 (Jan 06, 1904)"), isDialog()) + + updateDate(13, 1, 2459) + Assertions.assertText(withText("13 กุมภาพันธ์ 2459 (Feb 13, 1916)"), isDialog()) + + updateDate(21, 2, 2467) + Assertions.assertText(withText("21 มีนาคม 2467 (Mar 21, 1924)"), isDialog()) + + updateDate(10, 3, 2479) + Assertions.assertText(withText("10 เมษายน 2479 (Apr 10, 1936)"), isDialog()) + + updateDate(18, 4, 2487) + Assertions.assertText(withText("18 พฤษภาคม 2487 (May 18, 1944)"), isDialog()) + + updateDate(27, 5, 2499) + Assertions.assertText(withText("27 มิถุนายน 2499 (Jun 27, 1956)"), isDialog()) + + updateDate(8, 6, 2507) + Assertions.assertText(withText("8 กรกฎาคม 2507 (Jul 08, 1964)"), isDialog()) + + updateDate(15, 7, 2519) + Assertions.assertText(withText("15 สิงหาคม 2519 (Aug 15, 1976)"), isDialog()) + + updateDate(23, 8, 2527) + Assertions.assertText(withText("23 กันยายน 2527 (Sep 23, 1984)"), isDialog()) + + updateDate(30, 9, 2539) + Assertions.assertText(withText("30 ตุลาคม 2539 (Oct 30, 1996)"), isDialog()) + + updateDate(5, 10, 2547) + Assertions.assertText(withText("5 พฤศจิกายน 2547 (Nov 05, 2004)"), isDialog()) + + updateDate(12, 11, 2559) + Assertions.assertText(withText("12 ธันวาคม 2559 (Dec 12, 2016)"), isDialog()) + + updateDate(7, 0, 2567) + Assertions.assertText(withText("7 มกราคม 2567 (Jan 07, 2024)"), isDialog()) + + updateDate(14, 1, 2579) + Assertions.assertText(withText("14 กุมภาพันธ์ 2579 (Feb 14, 2036)"), isDialog()) + + updateDate(22, 2, 2587) + Assertions.assertText(withText("22 มีนาคม 2587 (Mar 22, 2044)"), isDialog()) + + updateDate(11, 3, 2599) + Assertions.assertText(withText("11 เมษายน 2599 (Apr 11, 2056)"), isDialog()) + + updateDate(19, 4, 2607) + Assertions.assertText(withText("19 พฤษภาคม 2607 (May 19, 2064)"), isDialog()) + + updateDate(26, 5, 2619) + Assertions.assertText(withText("26 มิถุนายน 2619 (Jun 26, 2076)"), isDialog()) + + updateDate(9, 6, 2627) + Assertions.assertText(withText("9 กรกฎาคม 2627 (Jul 09, 2084)"), isDialog()) + + updateDate(16, 7, 2639) + Assertions.assertText(withText("16 สิงหาคม 2639 (Aug 16, 2096)"), isDialog()) + } + + @Test + fun `The dialog shows correct date for 'year' mode`() { + launchFragment(2010, 5, 12, DatePickerMode.YEAR) + Assertions.assertText(withText("2553 (2010)"), isDialog()) + + updateDate(year = 2447) + Assertions.assertText(withText("2447 (1904)"), isDialog()) + + updateDate(year = 2453) + Assertions.assertText(withText("2453 (1910)"), isDialog()) + + updateDate(year = 2461) + Assertions.assertText(withText("2461 (1918)"), isDialog()) + + updateDate(year = 2468) + Assertions.assertText(withText("2468 (1925)"), isDialog()) + + updateDate(year = 2474) + Assertions.assertText(withText("2474 (1931)"), isDialog()) + + updateDate(year = 2483) + Assertions.assertText(withText("2483 (1940)"), isDialog()) + + updateDate(year = 2501) + Assertions.assertText(withText("2501 (1958)"), isDialog()) + + updateDate(year = 2509) + Assertions.assertText(withText("2509 (1966)"), isDialog()) + + updateDate(year = 2517) + Assertions.assertText(withText("2517 (1974)"), isDialog()) + + updateDate(year = 2525) + Assertions.assertText(withText("2525 (1982)"), isDialog()) + + updateDate(year = 2542) + Assertions.assertText(withText("2542 (1999)"), isDialog()) + + updateDate(year = 2551) + Assertions.assertText(withText("2551 (2008)"), isDialog()) + + updateDate(year = 2559) + Assertions.assertText(withText("2559 (2016)"), isDialog()) + + updateDate(year = 2567) + Assertions.assertText(withText("2567 (2024)"), isDialog()) + + updateDate(year = 2575) + Assertions.assertText(withText("2575 (2032)"), isDialog()) + + updateDate(year = 2583) + Assertions.assertText(withText("2583 (2040)"), isDialog()) + + updateDate(year = 2599) + Assertions.assertText(withText("2599 (2056)"), isDialog()) + + updateDate(year = 2608) + Assertions.assertText(withText("2608 (2065)"), isDialog()) + + updateDate(year = 2616) + Assertions.assertText(withText("2616 (2073)"), isDialog()) + + updateDate(year = 2624) + Assertions.assertText(withText("2624 (2081)"), isDialog()) + + updateDate(year = 2632) + Assertions.assertText(withText("2632 (2089)"), isDialog()) + + updateDate(year = 2638) + Assertions.assertText(withText("2638 (2095)"), isDialog()) + } + + @Test + fun `The dialog shows correct date for 'month-year' mode`() { + launchFragment(2010, 5, 12, DatePickerMode.MONTH_YEAR) + Assertions.assertText(withText("พฤษภาคม 2553 (May 2010)"), isDialog()) + + updateDate(month = 0, year = 2448) + Assertions.assertText(withText("มกราคม 2448 (Jan 1905)"), isDialog()) + + updateDate(month = 1, year = 2454) + Assertions.assertText(withText("กุมภาพันธ์ 2454 (Feb 1911)"), isDialog()) + + updateDate(month = 2, year = 2464) + Assertions.assertText(withText("มีนาคม 2464 (Mar 1921)"), isDialog()) + + updateDate(month = 3, year = 2473) + Assertions.assertText(withText("เมษายน 2473 (Apr 1930)"), isDialog()) + + updateDate(month = 4, year = 2486) + Assertions.assertText(withText("พฤษภาคม 2486 (May 1943)"), isDialog()) + + updateDate(month = 5, year = 2495) + Assertions.assertText(withText("มิถุนายน 2495 (Jun 1952)"), isDialog()) + + updateDate(month = 6, year = 2508) + Assertions.assertText(withText("กรกฎาคม 2508 (Jul 1965)"), isDialog()) + + updateDate(month = 7, year = 2519) + Assertions.assertText(withText("สิงหาคม 2519 (Aug 1976)"), isDialog()) + + updateDate(month = 8, year = 2527) + Assertions.assertText(withText("กันยายน 2527 (Sep 1984)"), isDialog()) + + updateDate(month = 9, year = 2538) + Assertions.assertText(withText("ตุลาคม 2538 (Oct 1995)"), isDialog()) + + updateDate(month = 10, year = 2549) + Assertions.assertText(withText("พฤศจิกายน 2549 (Nov 2006)"), isDialog()) + + updateDate(month = 11, year = 2560) + Assertions.assertText(withText("ธันวาคม 2560 (Dec 2017)"), isDialog()) + + updateDate(month = 0, year = 2571) + Assertions.assertText(withText("มกราคม 2571 (Jan 2028)"), isDialog()) + + updateDate(month = 1, year = 2582) + Assertions.assertText(withText("กุมภาพันธ์ 2582 (Feb 2039)"), isDialog()) + + updateDate(month = 2, year = 2592) + Assertions.assertText(withText("มีนาคม 2592 (Mar 2049)"), isDialog()) + + updateDate(month = 2, year = 2595) + Assertions.assertText(withText("มีนาคม 2595 (Mar 2052)"), isDialog()) + + updateDate(month = 3, year = 2604) + Assertions.assertText(withText("เมษายน 2604 (Apr 2061)"), isDialog()) + + updateDate(month = 4, year = 2615) + Assertions.assertText(withText("พฤษภาคม 2615 (May 2072)"), isDialog()) + + updateDate(month = 5, year = 2626) + Assertions.assertText(withText("มิถุนายน 2626 (Jun 2083)"), isDialog()) + + updateDate(month = 6, year = 2637) + Assertions.assertText(withText("กรกฎาคม 2637 (Jul 2094)"), isDialog()) + } + + @Test + fun `recreating maintains the date`() { + val scenario = launchFragment(2010, 5, 12) + Assertions.assertText(withText("12 พฤษภาคม 2553 (May 12, 2010)"), isDialog()) + scenario.recreate() + Assertions.assertText(withText("12 พฤษภาคม 2553 (May 12, 2010)"), isDialog()) + } + + @Test + fun `clicking OK dismisses the dialog`() { + val scenario = launchFragment(2010, 5, 12) + scenario.onFragment { + assertThat(it.dialog, notNullValue()) + Interactions.clickOn(withText(string.ok), isDialog()) + assertThat(it.dialog, nullValue()) + } + } + + @Test + fun `clicking CANCEL dismisses the dialog`() { + val scenario = launchFragment(2010, 5, 12) + scenario.onFragment { + assertThat(it.dialog, notNullValue()) + Interactions.clickOn(withText(string.cancel), isDialog()) + assertThat(it.dialog, nullValue()) + } + } + + private fun updateDate(day: Int? = null, month: Int? = null, year: Int? = null) { + day?.let { + onView(withId(R.id.day_picker)).inRoot(isDialog()).perform(Actions.scrollNumberPickerToValue(it)) + } + month?.let { + onView(withId(R.id.month_picker)).inRoot(isDialog()).perform(Actions.scrollNumberPickerToValue(it)) + } + year?.let { + onView(withId(R.id.year_picker)).inRoot(isDialog()).perform(Actions.scrollNumberPickerToValue(it)) + } + } + + private fun launchFragment( + year: Int, + month: Int, + day: Int, + datePickerMode: DatePickerMode = DatePickerMode.SPINNERS + ): FragmentScenario { + val args = Bundle().apply { + putSerializable( + DateTimeWidgetUtils.DATE, + LocalDateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(day) + ) + putSerializable( + DateTimeWidgetUtils.DATE_PICKER_DETAILS, + DatePickerDetails(DatePickerDetails.DatePickerType.BUDDHIST, datePickerMode) + ) + } + + return launcherRule.launch(BuddhistDatePickerDialog::class.java, args) + } +} diff --git a/collect_app/src/test/java/org/odk/collect/android/support/Actions.kt b/collect_app/src/test/java/org/odk/collect/android/support/Actions.kt new file mode 100644 index 00000000000..45794615ae9 --- /dev/null +++ b/collect_app/src/test/java/org/odk/collect/android/support/Actions.kt @@ -0,0 +1,56 @@ +package org.odk.collect.android.support + +import android.view.View +import android.widget.NumberPicker +import androidx.test.espresso.UiController +import androidx.test.espresso.ViewAction +import androidx.test.espresso.action.GeneralLocation +import androidx.test.espresso.action.GeneralSwipeAction +import androidx.test.espresso.action.Press +import androidx.test.espresso.action.Swipe +import androidx.test.espresso.matcher.ViewMatchers +import org.hamcrest.Matcher + +object Actions { + fun scrollNumberPickerToValue(targetValue: Int): ViewAction { + return object : ViewAction { + override fun getConstraints(): Matcher { + return ViewMatchers.isAssignableFrom(NumberPicker::class.java) + } + + override fun getDescription(): String { + return "Scroll the NumberPicker to a specific value" + } + + override fun perform(uiController: UiController, view: View) { + val numberPicker = view as NumberPicker + + while (targetValue != numberPicker.value) { + if (targetValue < numberPicker.value) { + swipeDown(uiController, view) + } else { + swipeUp(uiController, view) + } + } + } + + private fun swipeUp(uiController: UiController, view: View) { + GeneralSwipeAction( + Swipe.SLOW, + GeneralLocation.CENTER, + GeneralLocation.TOP_CENTER, + Press.FINGER + ).perform(uiController, view) + } + + private fun swipeDown(uiController: UiController, view: View) { + GeneralSwipeAction( + Swipe.SLOW, + GeneralLocation.CENTER, + GeneralLocation.BOTTOM_CENTER, + Press.FINGER + ).perform(uiController, view) + } + } + } +} From 6d974bf3b4d8b96fd89a7306d23e5e972fb09611 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 24 Jul 2024 23:09:08 +0200 Subject: [PATCH 4/7] Moved the list of months to the date picker class --- .../dialogs/BuddhistDatePickerDialog.kt | 24 ++++++++++--------- .../utilities/DateTimeWidgetUtils.java | 2 +- collect_app/src/main/res/values/arrays.xml | 14 ----------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt b/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt index 745bbec42dc..0ee7496f8cb 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt +++ b/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt @@ -2,20 +2,11 @@ package org.odk.collect.android.fragments.dialogs import org.joda.time.LocalDateTime import org.joda.time.chrono.BuddhistChronology -import org.odk.collect.android.R import org.odk.collect.android.utilities.DateTimeUtils class BuddhistDatePickerDialog : CustomDatePickerDialog() { - companion object { - const val MIN_SUPPORTED_YEAR = 2443 // 1900 in Gregorian calendar - const val MAX_SUPPORTED_YEAR = 2643 // 2100 in Gregorian calendar - } - - private lateinit var monthsArray: Array - override fun onResume() { super.onResume() - monthsArray = resources.getStringArray(R.array.buddhist_months) setUpValues() } @@ -36,7 +27,7 @@ class BuddhistDatePickerDialog : CustomDatePickerDialog() { .toLocalDateTime() setUpDayPicker(buddhistDate.dayOfMonth, buddhistDate.dayOfMonth().maximumValue) - setUpMonthPicker(buddhistDate.monthOfYear, monthsArray) + setUpMonthPicker(buddhistDate.monthOfYear, MONTHS) setUpYearPicker(buddhistDate.year, MIN_SUPPORTED_YEAR, MAX_SUPPORTED_YEAR) } @@ -47,7 +38,7 @@ class BuddhistDatePickerDialog : CustomDatePickerDialog() { private fun getCurrentBuddhistDate(): LocalDateTime { var buddhistDay = day - val buddhistMonth = monthsArray.indexOf(month) + val buddhistMonth = MONTHS.indexOf(month) val buddhistYear = year val buddhistDate = LocalDateTime( @@ -75,4 +66,15 @@ class BuddhistDatePickerDialog : CustomDatePickerDialog() { BuddhistChronology.getInstance() ) } + + companion object { + const val MIN_SUPPORTED_YEAR = 2443 // 1900 in Gregorian calendar + const val MAX_SUPPORTED_YEAR = 2643 // 2100 in Gregorian calendar + + @JvmField + val MONTHS = arrayOf( + "มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", + "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม" + ) + } } diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java index ee5dde566b4..c825b7fcb69 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java @@ -127,7 +127,7 @@ public static String getDateTimeLabel(Date date, DatePickerDetails datePickerDet break; case BUDDHIST: customDate = new DateTime(date).withChronology(BuddhistChronology.getInstance()); - monthArray = context.getResources().getStringArray(R.array.buddhist_months); + monthArray = BuddhistDatePickerDialog.MONTHS; break; default: Timber.w("Not supported date type."); diff --git a/collect_app/src/main/res/values/arrays.xml b/collect_app/src/main/res/values/arrays.xml index 52d98bbd6a2..1a0bfcea7af 100644 --- a/collect_app/src/main/res/values/arrays.xml +++ b/collect_app/src/main/res/values/arrays.xml @@ -147,20 +147,6 @@ the specific language governing permissions and limitations under the License. - @string/persian_month_11 @string/persian_month_12 - - มกราคม - กุมภาพันธ์ - มีนาคม - เมษายน - พฤษภาคม - มิถุนายน - กรกฎาคม - สิงหาคม - กันยายน - ตุลาคม - พฤศจิกายน - ธันวาคม - @string/every_fifteen_minutes_value @string/every_one_hour_value From 0e247ad67af7a441fb8122ee42c2d7c51a9ae856 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Mon, 29 Jul 2024 12:26:03 +0200 Subject: [PATCH 5/7] Moved date time pickers and widgets to the same package --- .../utilities/DateTimeUtilsTest.java | 2 +- .../activities/FormFillingActivity.java | 6 +-- .../android/widgets/WidgetFactory.java | 3 ++ .../datetime}/DatePickerDetails.java | 2 +- .../datetime}/DateTimeUtils.java | 2 +- .../{ => datetime}/DateTimeWidget.java | 5 +-- .../widgets/{ => datetime}/DateWidget.java | 5 +-- .../widgets/{ => datetime}/TimeWidget.java | 4 +- .../BikramSambatDatePickerDialog.java | 2 +- .../pickers}/BuddhistDatePickerDialog.kt | 4 +- .../pickers}/CopticDatePickerDialog.java | 4 +- .../pickers}/CustomDatePickerDialog.java | 6 +-- .../pickers}/CustomTimePickerDialog.java | 2 +- .../pickers}/EthiopianDatePickerDialog.java | 6 +-- .../pickers}/FixedDatePickerDialog.java | 4 +- .../pickers}/IslamicDatePickerDialog.java | 4 +- .../pickers}/MyanmarDatePickerDialog.java | 6 +-- .../pickers}/PersianDatePickerDialog.java | 6 +-- .../utilities/DateTimeWidgetUtils.java | 20 +++++----- .../widgets/viewmodels/DateTimeViewModel.java | 4 +- .../support/DialogFragmentHelpers.java | 4 +- .../datetime}/DateTimeUtilsTest.java | 2 +- .../{ => datetime}/DateTimeWidgetTest.java | 4 +- .../DateTimeWidgetUtilsTest.java | 38 +++++++++---------- .../{ => datetime}/DateWidgetTest.java | 4 +- .../datetime}/DaylightSavingTest.java | 4 +- .../{ => datetime}/TimeWidgetTest.java | 3 +- .../BikramSambatDatePickerDialogTest.java | 4 +- .../pickers}/BuddhistDatePickerDialogTest.kt | 11 ++++-- .../pickers}/CopticDatePickerDialogTest.java | 4 +- .../EthiopianDatePickerDialogTest.java | 4 +- .../pickers}/IslamicDatePickerDialogTest.java | 4 +- .../pickers}/MyanmarDatePickerDialogTest.java | 4 +- .../pickers}/PersianDatePickerDialogTest.java | 4 +- .../viewmodels/DateTimeViewModelTest.java | 2 +- 35 files changed, 95 insertions(+), 98 deletions(-) rename collect_app/src/main/java/org/odk/collect/android/{logic => widgets/datetime}/DatePickerDetails.java (97%) rename collect_app/src/main/java/org/odk/collect/android/{utilities => widgets/datetime}/DateTimeUtils.java (97%) rename collect_app/src/main/java/org/odk/collect/android/widgets/{ => datetime}/DateTimeWidget.java (97%) rename collect_app/src/main/java/org/odk/collect/android/widgets/{ => datetime}/DateWidget.java (96%) rename collect_app/src/main/java/org/odk/collect/android/widgets/{ => datetime}/TimeWidget.java (97%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/BikramSambatDatePickerDialog.java (98%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/BuddhistDatePickerDialog.kt (95%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/CopticDatePickerDialog.java (95%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/CustomDatePickerDialog.java (97%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/CustomTimePickerDialog.java (99%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/EthiopianDatePickerDialog.java (96%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/FixedDatePickerDialog.java (98%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/IslamicDatePickerDialog.java (96%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/MyanmarDatePickerDialog.java (96%) rename collect_app/src/main/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/PersianDatePickerDialog.java (96%) rename collect_app/src/test/java/org/odk/collect/android/{utilities => widgets/datetime}/DateTimeUtilsTest.java (98%) rename collect_app/src/test/java/org/odk/collect/android/widgets/{ => datetime}/DateTimeWidgetTest.java (98%) rename collect_app/src/test/java/org/odk/collect/android/widgets/{utilities => datetime}/DateTimeWidgetUtilsTest.java (89%) rename collect_app/src/test/java/org/odk/collect/android/widgets/{ => datetime}/DateWidgetTest.java (98%) rename collect_app/src/test/java/org/odk/collect/android/{utilities => widgets/datetime}/DaylightSavingTest.java (97%) rename collect_app/src/test/java/org/odk/collect/android/widgets/{ => datetime}/TimeWidgetTest.java (98%) rename collect_app/src/test/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/BikramSambatDatePickerDialogTest.java (96%) rename collect_app/src/test/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/BuddhistDatePickerDialogTest.kt (97%) rename collect_app/src/test/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/CopticDatePickerDialogTest.java (96%) rename collect_app/src/test/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/EthiopianDatePickerDialogTest.java (96%) rename collect_app/src/test/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/IslamicDatePickerDialogTest.java (96%) rename collect_app/src/test/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/MyanmarDatePickerDialogTest.java (96%) rename collect_app/src/test/java/org/odk/collect/android/{fragments/dialogs => widgets/datetime/pickers}/PersianDatePickerDialogTest.java (96%) diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java index 4b7fbffddcd..87902377167 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/instrumented/utilities/DateTimeUtilsTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.application.Collect; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.testshared.TimeZoneSetter; diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java index aa5fcc31a0d..8d4baf9b202 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java @@ -126,8 +126,8 @@ import org.odk.collect.android.formhierarchy.FormHierarchyActivity; import org.odk.collect.android.formhierarchy.ViewOnlyFormHierarchyActivity; import org.odk.collect.android.fragments.MediaLoadingFragment; -import org.odk.collect.android.fragments.dialogs.CustomDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.CustomTimePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.CustomDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.CustomTimePickerDialog; import org.odk.collect.android.fragments.dialogs.LocationProvidersDisabledDialog; import org.odk.collect.android.fragments.dialogs.NumberPickerDialog; import org.odk.collect.android.fragments.dialogs.RankingWidgetDialog; @@ -161,7 +161,7 @@ import org.odk.collect.android.utilities.SavepointsRepositoryProvider; import org.odk.collect.android.utilities.ScreenContext; import org.odk.collect.android.utilities.SoftKeyboardController; -import org.odk.collect.android.widgets.DateTimeWidget; +import org.odk.collect.android.widgets.datetime.DateTimeWidget; import org.odk.collect.android.widgets.QuestionWidget; import org.odk.collect.android.widgets.interfaces.WidgetDataReceiver; import org.odk.collect.android.widgets.items.SelectOneFromMapDialogFragment; 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 af2f5cbdc38..ad2cc83422d 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 @@ -35,6 +35,9 @@ import org.odk.collect.android.storage.StoragePathProvider; import org.odk.collect.android.utilities.Appearances; import org.odk.collect.android.utilities.QuestionMediaManager; +import org.odk.collect.android.widgets.datetime.DateTimeWidget; +import org.odk.collect.android.widgets.datetime.DateWidget; +import org.odk.collect.android.widgets.datetime.TimeWidget; import org.odk.collect.android.widgets.items.LabelWidget; import org.odk.collect.android.widgets.items.LikertWidget; import org.odk.collect.android.widgets.items.ListMultiWidget; diff --git a/collect_app/src/main/java/org/odk/collect/android/logic/DatePickerDetails.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DatePickerDetails.java similarity index 97% rename from collect_app/src/main/java/org/odk/collect/android/logic/DatePickerDetails.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DatePickerDetails.java index c864d686939..9fdc20a0622 100644 --- a/collect_app/src/main/java/org/odk/collect/android/logic/DatePickerDetails.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DatePickerDetails.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.odk.collect.android.logic; +package org.odk.collect.android.widgets.datetime; import java.io.Serializable; diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/DateTimeUtils.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateTimeUtils.java similarity index 97% rename from collect_app/src/main/java/org/odk/collect/android/utilities/DateTimeUtils.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateTimeUtils.java index 6a38d46692d..dbd3ec85724 100644 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/DateTimeUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateTimeUtils.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.utilities; +package org.odk.collect.android.widgets.datetime; import org.javarosa.core.model.data.TimeData; import org.joda.time.DateTime; diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/DateTimeWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateTimeWidget.java similarity index 97% rename from collect_app/src/main/java/org/odk/collect/android/widgets/DateTimeWidget.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateTimeWidget.java index 4aacfddc2cc..d0b8d1c43b0 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/DateTimeWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateTimeWidget.java @@ -12,7 +12,7 @@ * the License. */ -package org.odk.collect.android.widgets; +package org.odk.collect.android.widgets.datetime; import android.annotation.SuppressLint; import android.app.Activity; @@ -28,8 +28,7 @@ import org.joda.time.LocalDateTime; import org.odk.collect.android.databinding.DateTimeWidgetAnswerBinding; import org.odk.collect.android.formentry.questions.QuestionDetails; -import org.odk.collect.android.logic.DatePickerDetails; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.QuestionWidget; import org.odk.collect.android.widgets.interfaces.WidgetDataReceiver; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.android.widgets.utilities.WaitingForDataRegistry; diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateWidget.java similarity index 96% rename from collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateWidget.java index bb09ceebbbd..8c5e51bdaf9 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/DateWidget.java @@ -12,7 +12,7 @@ * the License. */ -package org.odk.collect.android.widgets; +package org.odk.collect.android.widgets.datetime; import android.annotation.SuppressLint; import android.app.Activity; @@ -26,8 +26,7 @@ import org.joda.time.LocalDateTime; import org.odk.collect.android.databinding.DateWidgetAnswerBinding; import org.odk.collect.android.formentry.questions.QuestionDetails; -import org.odk.collect.android.logic.DatePickerDetails; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.QuestionWidget; import org.odk.collect.android.widgets.interfaces.WidgetDataReceiver; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.android.widgets.utilities.WaitingForDataRegistry; diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/TimeWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/TimeWidget.java similarity index 97% rename from collect_app/src/main/java/org/odk/collect/android/widgets/TimeWidget.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/TimeWidget.java index 5af01958a0b..debd3044b42 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/TimeWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/TimeWidget.java @@ -12,7 +12,7 @@ * the License. */ -package org.odk.collect.android.widgets; +package org.odk.collect.android.widgets.datetime; import android.annotation.SuppressLint; import android.app.Activity; @@ -28,7 +28,7 @@ import org.joda.time.LocalDateTime; import org.odk.collect.android.databinding.TimeWidgetAnswerBinding; import org.odk.collect.android.formentry.questions.QuestionDetails; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.QuestionWidget; import org.odk.collect.android.widgets.interfaces.WidgetDataReceiver; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.android.widgets.utilities.WaitingForDataRegistry; diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BikramSambatDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BikramSambatDatePickerDialog.java similarity index 98% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BikramSambatDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BikramSambatDatePickerDialog.java index 4a4625d6bc8..f637e6cf6db 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BikramSambatDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BikramSambatDatePickerDialog.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import org.joda.time.LocalDateTime; diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.kt similarity index 95% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.kt index 0ee7496f8cb..c89d4600c42 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialog.kt +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.kt @@ -1,8 +1,8 @@ -package org.odk.collect.android.fragments.dialogs +package org.odk.collect.android.widgets.datetime.pickers import org.joda.time.LocalDateTime import org.joda.time.chrono.BuddhistChronology -import org.odk.collect.android.utilities.DateTimeUtils +import org.odk.collect.android.widgets.datetime.DateTimeUtils class BuddhistDatePickerDialog : CustomDatePickerDialog() { override fun onResume() { diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CopticDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CopticDatePickerDialog.java similarity index 95% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CopticDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CopticDatePickerDialog.java index d68b2dac88b..0e6ce3e2c05 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CopticDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CopticDatePickerDialog.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import org.joda.time.LocalDateTime; import org.joda.time.chrono.CopticChronology; import org.odk.collect.android.R; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; import java.util.Arrays; diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CustomDatePickerDialog.java similarity index 97% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CustomDatePickerDialog.java index 5fa39ca606b..8551a99971a 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CustomDatePickerDialog.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.app.Dialog; import android.content.Context; @@ -30,8 +30,8 @@ import org.joda.time.LocalDateTime; import org.odk.collect.android.R; -import org.odk.collect.android.logic.DatePickerDetails; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.android.widgets.viewmodels.DateTimeViewModel; diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomTimePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CustomTimePickerDialog.java similarity index 99% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomTimePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CustomTimePickerDialog.java index 09a7cd503dc..0fdc3f3e0eb 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/CustomTimePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/CustomTimePickerDialog.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.app.Dialog; import android.app.TimePickerDialog; diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/EthiopianDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/EthiopianDatePickerDialog.java similarity index 96% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/EthiopianDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/EthiopianDatePickerDialog.java index 2237b10f3e5..504dcb448d9 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/EthiopianDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/EthiopianDatePickerDialog.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import org.joda.time.LocalDateTime; import org.joda.time.chrono.EthiopicChronology; import org.odk.collect.android.R; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; import java.util.Arrays; @@ -82,4 +82,4 @@ private LocalDateTime getCurrentEthiopianDate() { return new LocalDateTime(ethiopianYear, ethiopianMonth + 1, ethiopianDay, 0, 0, 0, 0, EthiopicChronology.getInstance()); } -} \ No newline at end of file +} diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/FixedDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/FixedDatePickerDialog.java similarity index 98% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/FixedDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/FixedDatePickerDialog.java index ff327009123..452a46f8b93 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/FixedDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/FixedDatePickerDialog.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.app.DatePickerDialog; import android.app.Dialog; @@ -19,7 +19,7 @@ import androidx.lifecycle.ViewModelProvider; import org.joda.time.LocalDateTime; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.utilities.ThemeUtils; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.android.widgets.viewmodels.DateTimeViewModel; diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/IslamicDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/IslamicDatePickerDialog.java similarity index 96% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/IslamicDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/IslamicDatePickerDialog.java index 083e20688c1..c172b369a29 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/IslamicDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/IslamicDatePickerDialog.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import org.joda.time.LocalDateTime; import org.joda.time.chrono.IslamicChronology; import org.odk.collect.android.R; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; import java.util.Arrays; diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/MyanmarDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/MyanmarDatePickerDialog.java similarity index 96% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/MyanmarDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/MyanmarDatePickerDialog.java index cd0d6e4a4c8..2e811a9f438 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/MyanmarDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/MyanmarDatePickerDialog.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import org.joda.time.LocalDateTime; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; import org.odk.collect.android.utilities.MyanmarDateUtils; import java.util.List; @@ -70,4 +70,4 @@ private MyanmarDate getCurrentMyanmarDate() { return MyanmarDateUtils.createMyanmarDate(getYear(), monthIndex, dayOfMonth); } -} \ No newline at end of file +} diff --git a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/PersianDatePickerDialog.java b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/PersianDatePickerDialog.java similarity index 96% rename from collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/PersianDatePickerDialog.java rename to collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/PersianDatePickerDialog.java index d5cb0b1a9cd..3203ae0b5d6 100644 --- a/collect_app/src/main/java/org/odk/collect/android/fragments/dialogs/PersianDatePickerDialog.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/PersianDatePickerDialog.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import org.joda.time.LocalDateTime; import org.joda.time.chrono.PersianChronologyKhayyamBorkowski; import org.odk.collect.android.R; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; import java.util.Arrays; @@ -78,4 +78,4 @@ private LocalDateTime getCurrentPersianDate() { return new LocalDateTime(persianYear, persianMonth + 1, persianDay, 0, 0, 0, 0, PersianChronologyKhayyamBorkowski.getInstance()); } -} \ No newline at end of file +} diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java index c825b7fcb69..dae4520e573 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java @@ -14,16 +14,16 @@ import org.joda.time.chrono.IslamicChronology; import org.joda.time.chrono.PersianChronologyKhayyamBorkowski; import org.odk.collect.android.R; -import org.odk.collect.android.fragments.dialogs.BikramSambatDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.BuddhistDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.CopticDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.CustomTimePickerDialog; -import org.odk.collect.android.fragments.dialogs.EthiopianDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.FixedDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.IslamicDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.MyanmarDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.PersianDatePickerDialog; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.pickers.BikramSambatDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.BuddhistDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.CopticDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.CustomTimePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.EthiopianDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.FixedDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.IslamicDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.MyanmarDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.PersianDatePickerDialog; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.utilities.Appearances; import org.odk.collect.android.utilities.MyanmarDateUtils; import org.odk.collect.android.utilities.ThemeUtils; diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModel.java b/collect_app/src/main/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModel.java index 3b16aeee079..ed14aa0a35f 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModel.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModel.java @@ -9,8 +9,8 @@ import org.joda.time.DateTime; import org.joda.time.LocalDateTime; -import org.odk.collect.android.logic.DatePickerDetails; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; public class DateTimeViewModel extends ViewModel { private final MutableLiveData selectedDate = new MutableLiveData<>(); diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/support/DialogFragmentHelpers.java b/collect_app/src/test/java/org/odk/collect/android/fragments/support/DialogFragmentHelpers.java index 1764a9015e1..ff2631a9146 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/support/DialogFragmentHelpers.java +++ b/collect_app/src/test/java/org/odk/collect/android/fragments/support/DialogFragmentHelpers.java @@ -19,8 +19,8 @@ import org.joda.time.LocalDateTime; import org.odk.collect.android.R; -import org.odk.collect.android.fragments.dialogs.CustomDatePickerDialog; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.pickers.CustomDatePickerDialog; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.testshared.RobolectricHelpers; import org.robolectric.Robolectric; diff --git a/collect_app/src/test/java/org/odk/collect/android/utilities/DateTimeUtilsTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeUtilsTest.java similarity index 98% rename from collect_app/src/test/java/org/odk/collect/android/utilities/DateTimeUtilsTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeUtilsTest.java index 75109ed12c1..82612479b2e 100644 --- a/collect_app/src/test/java/org/odk/collect/android/utilities/DateTimeUtilsTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeUtilsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.odk.collect.android.utilities; +package org.odk.collect.android.widgets.datetime; import androidx.test.ext.junit.runners.AndroidJUnit4; diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/DateTimeWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeWidgetTest.java similarity index 98% rename from collect_app/src/test/java/org/odk/collect/android/widgets/DateTimeWidgetTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeWidgetTest.java index 0d6d39defbc..18d1dce2315 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/DateTimeWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeWidgetTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.widgets; +package org.odk.collect.android.widgets.datetime; import android.view.View; @@ -16,9 +16,7 @@ import org.junit.runner.RunWith; import org.odk.collect.android.formentry.questions.QuestionDetails; import org.odk.collect.android.listeners.WidgetValueChangedListener; -import org.odk.collect.android.logic.DatePickerDetails; import org.odk.collect.android.support.WidgetTestActivity; -import org.odk.collect.android.utilities.DateTimeUtils; import org.odk.collect.android.widgets.support.FakeWaitingForDataRegistry; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtilsTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeWidgetUtilsTest.java similarity index 89% rename from collect_app/src/test/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtilsTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeWidgetUtilsTest.java index c93848f26b2..ce84fe4680f 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtilsTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateTimeWidgetUtilsTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.widgets.utilities; +package org.odk.collect.android.widgets.datetime; import androidx.fragment.app.DialogFragment; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -7,16 +7,16 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.odk.collect.android.fragments.dialogs.BikramSambatDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.BuddhistDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.CopticDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.CustomTimePickerDialog; -import org.odk.collect.android.fragments.dialogs.EthiopianDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.FixedDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.IslamicDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.MyanmarDatePickerDialog; -import org.odk.collect.android.fragments.dialogs.PersianDatePickerDialog; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.pickers.BikramSambatDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.BuddhistDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.CopticDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.CustomTimePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.EthiopianDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.FixedDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.IslamicDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.MyanmarDatePickerDialog; +import org.odk.collect.android.widgets.datetime.pickers.PersianDatePickerDialog; +import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.testshared.RobolectricHelpers; import org.odk.collect.android.support.WidgetTestActivity; @@ -26,14 +26,14 @@ import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.BIKRAM_SAMBAT; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.BUDDHIST; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.COPTIC; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.ETHIOPIAN; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.GREGORIAN; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.ISLAMIC; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.MYANMAR; -import static org.odk.collect.android.logic.DatePickerDetails.DatePickerType.PERSIAN; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.BIKRAM_SAMBAT; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.BUDDHIST; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.COPTIC; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.ETHIOPIAN; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.GREGORIAN; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.ISLAMIC; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.MYANMAR; +import static org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerType.PERSIAN; import android.app.DatePickerDialog; diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/DateWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateWidgetTest.java similarity index 98% rename from collect_app/src/test/java/org/odk/collect/android/widgets/DateWidgetTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateWidgetTest.java index f5206eae27a..fc63a925412 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/DateWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DateWidgetTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.widgets; +package org.odk.collect.android.widgets.datetime; import android.view.View; @@ -13,9 +13,7 @@ import org.junit.runner.RunWith; import org.odk.collect.android.formentry.questions.QuestionDetails; import org.odk.collect.android.listeners.WidgetValueChangedListener; -import org.odk.collect.android.logic.DatePickerDetails; import org.odk.collect.android.support.WidgetTestActivity; -import org.odk.collect.android.utilities.DateTimeUtils; import org.odk.collect.android.widgets.support.FakeWaitingForDataRegistry; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; diff --git a/collect_app/src/test/java/org/odk/collect/android/utilities/DaylightSavingTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DaylightSavingTest.java similarity index 97% rename from collect_app/src/test/java/org/odk/collect/android/utilities/DaylightSavingTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DaylightSavingTest.java index c9d16ac594e..25d6a68c83a 100644 --- a/collect_app/src/test/java/org/odk/collect/android/utilities/DaylightSavingTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/DaylightSavingTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.odk.collect.android.utilities; +package org.odk.collect.android.widgets.datetime; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -38,8 +38,6 @@ import org.odk.collect.android.support.CollectHelpers; import org.odk.collect.android.support.MockFormEntryPromptBuilder; import org.odk.collect.android.support.WidgetTestActivity; -import org.odk.collect.android.widgets.DateTimeWidget; -import org.odk.collect.android.widgets.DateWidget; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; import org.odk.collect.testshared.TimeZoneSetter; diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/TimeWidgetTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/TimeWidgetTest.java similarity index 98% rename from collect_app/src/test/java/org/odk/collect/android/widgets/TimeWidgetTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/TimeWidgetTest.java index 327c1dedcbd..9620e9a3881 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/TimeWidgetTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/TimeWidgetTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.widgets; +package org.odk.collect.android.widgets.datetime; import android.view.View; @@ -14,7 +14,6 @@ import org.odk.collect.android.formentry.questions.QuestionDetails; import org.odk.collect.android.listeners.WidgetValueChangedListener; import org.odk.collect.android.support.WidgetTestActivity; -import org.odk.collect.android.utilities.DateTimeUtils; import org.odk.collect.android.widgets.support.FakeWaitingForDataRegistry; import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils; diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BikramSambatDatePickerDialogTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BikramSambatDatePickerDialogTest.java similarity index 96% rename from collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BikramSambatDatePickerDialogTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BikramSambatDatePickerDialogTest.java index de786134abd..76692b56d7c 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BikramSambatDatePickerDialogTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BikramSambatDatePickerDialogTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import static org.mockito.Mockito.when; @@ -11,7 +11,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.fragments.support.DialogFragmentHelpers; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.support.CollectHelpers; import org.odk.collect.testshared.RobolectricHelpers; diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialogTest.kt b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialogTest.kt similarity index 97% rename from collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialogTest.kt rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialogTest.kt index 27e757e3bdd..c5d3edf47cf 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/BuddhistDatePickerDialogTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialogTest.kt @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs +package org.odk.collect.android.widgets.datetime.pickers import android.os.Bundle import androidx.fragment.app.testing.FragmentScenario @@ -16,9 +16,9 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.odk.collect.android.R -import org.odk.collect.android.logic.DatePickerDetails -import org.odk.collect.android.logic.DatePickerDetails.DatePickerMode import org.odk.collect.android.support.Actions +import org.odk.collect.android.widgets.datetime.DatePickerDetails +import org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerMode import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils import org.odk.collect.fragmentstest.FragmentScenarioLauncherRule import org.odk.collect.strings.R.string @@ -295,7 +295,10 @@ class BuddhistDatePickerDialogTest { ) putSerializable( DateTimeWidgetUtils.DATE_PICKER_DETAILS, - DatePickerDetails(DatePickerDetails.DatePickerType.BUDDHIST, datePickerMode) + DatePickerDetails( + DatePickerDetails.DatePickerType.BUDDHIST, + datePickerMode + ) ) } diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/CopticDatePickerDialogTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/CopticDatePickerDialogTest.java similarity index 96% rename from collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/CopticDatePickerDialogTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/CopticDatePickerDialogTest.java index fa512d6e1cd..a208fe6b4be 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/CopticDatePickerDialogTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/CopticDatePickerDialogTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.content.DialogInterface; @@ -9,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.fragments.support.DialogFragmentHelpers; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.support.CollectHelpers; import org.odk.collect.testshared.RobolectricHelpers; diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/EthiopianDatePickerDialogTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/EthiopianDatePickerDialogTest.java similarity index 96% rename from collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/EthiopianDatePickerDialogTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/EthiopianDatePickerDialogTest.java index 19a4e718bf4..265c7fed3ab 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/EthiopianDatePickerDialogTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/EthiopianDatePickerDialogTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.content.DialogInterface; @@ -9,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.fragments.support.DialogFragmentHelpers; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.support.CollectHelpers; import org.odk.collect.testshared.RobolectricHelpers; diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/IslamicDatePickerDialogTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/IslamicDatePickerDialogTest.java similarity index 96% rename from collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/IslamicDatePickerDialogTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/IslamicDatePickerDialogTest.java index d203e4f4443..9a1e1040540 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/IslamicDatePickerDialogTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/IslamicDatePickerDialogTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.content.DialogInterface; @@ -9,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.fragments.support.DialogFragmentHelpers; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.support.CollectHelpers; import org.odk.collect.testshared.RobolectricHelpers; diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/MyanmarDatePickerDialogTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/MyanmarDatePickerDialogTest.java similarity index 96% rename from collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/MyanmarDatePickerDialogTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/MyanmarDatePickerDialogTest.java index 3ddd47fb7f2..8c9d1e5f2a0 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/MyanmarDatePickerDialogTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/MyanmarDatePickerDialogTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.content.DialogInterface; @@ -9,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.fragments.support.DialogFragmentHelpers; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.support.CollectHelpers; import org.odk.collect.testshared.RobolectricHelpers; diff --git a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/PersianDatePickerDialogTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/PersianDatePickerDialogTest.java similarity index 96% rename from collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/PersianDatePickerDialogTest.java rename to collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/PersianDatePickerDialogTest.java index 63d8fde898c..9e2e888ae19 100644 --- a/collect_app/src/test/java/org/odk/collect/android/fragments/dialogs/PersianDatePickerDialogTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/PersianDatePickerDialogTest.java @@ -1,4 +1,4 @@ -package org.odk.collect.android.fragments.dialogs; +package org.odk.collect.android.widgets.datetime.pickers; import android.content.DialogInterface; @@ -9,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.odk.collect.android.fragments.support.DialogFragmentHelpers; -import org.odk.collect.android.logic.DatePickerDetails; +import org.odk.collect.android.widgets.datetime.DatePickerDetails; import org.odk.collect.android.support.CollectHelpers; import org.odk.collect.testshared.RobolectricHelpers; diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModelTest.java b/collect_app/src/test/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModelTest.java index e7235f0c119..7c278f27002 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModelTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/viewmodels/DateTimeViewModelTest.java @@ -20,7 +20,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.odk.collect.android.utilities.DateTimeUtils; +import org.odk.collect.android.widgets.datetime.DateTimeUtils; @RunWith(AndroidJUnit4.class) public class DateTimeViewModelTest { From 9a95144968fc2cbc705a72eb0d87a6499066964a Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 14 Aug 2024 16:12:23 +0200 Subject: [PATCH 6/7] Make month names translatable --- .../pickers/BuddhistDatePickerDialog.kt | 26 +++++++++++++------ .../utilities/DateTimeWidgetUtils.java | 2 +- collect_app/src/main/res/values/arrays.xml | 14 ++++++++++ strings/src/main/res/values/strings.xml | 26 +++++++++++++++++++ 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.kt b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.kt index c89d4600c42..6d8b82cd0cd 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.kt +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.kt @@ -1,10 +1,26 @@ package org.odk.collect.android.widgets.datetime.pickers +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import org.joda.time.LocalDateTime import org.joda.time.chrono.BuddhistChronology +import org.odk.collect.android.R import org.odk.collect.android.widgets.datetime.DateTimeUtils class BuddhistDatePickerDialog : CustomDatePickerDialog() { + private lateinit var monthsArray: Array + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + monthsArray = resources.getStringArray(R.array.buddhist_months) + return super.onCreateView(inflater, container, savedInstanceState) + } + override fun onResume() { super.onResume() setUpValues() @@ -27,7 +43,7 @@ class BuddhistDatePickerDialog : CustomDatePickerDialog() { .toLocalDateTime() setUpDayPicker(buddhistDate.dayOfMonth, buddhistDate.dayOfMonth().maximumValue) - setUpMonthPicker(buddhistDate.monthOfYear, MONTHS) + setUpMonthPicker(buddhistDate.monthOfYear, monthsArray) setUpYearPicker(buddhistDate.year, MIN_SUPPORTED_YEAR, MAX_SUPPORTED_YEAR) } @@ -38,7 +54,7 @@ class BuddhistDatePickerDialog : CustomDatePickerDialog() { private fun getCurrentBuddhistDate(): LocalDateTime { var buddhistDay = day - val buddhistMonth = MONTHS.indexOf(month) + val buddhistMonth = monthsArray.indexOf(month) val buddhistYear = year val buddhistDate = LocalDateTime( @@ -70,11 +86,5 @@ class BuddhistDatePickerDialog : CustomDatePickerDialog() { companion object { const val MIN_SUPPORTED_YEAR = 2443 // 1900 in Gregorian calendar const val MAX_SUPPORTED_YEAR = 2643 // 2100 in Gregorian calendar - - @JvmField - val MONTHS = arrayOf( - "มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", - "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม" - ) } } diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java index dae4520e573..d8b1e065ba7 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/utilities/DateTimeWidgetUtils.java @@ -127,7 +127,7 @@ public static String getDateTimeLabel(Date date, DatePickerDetails datePickerDet break; case BUDDHIST: customDate = new DateTime(date).withChronology(BuddhistChronology.getInstance()); - monthArray = BuddhistDatePickerDialog.MONTHS; + monthArray = context.getResources().getStringArray(R.array.buddhist_months); break; default: Timber.w("Not supported date type."); diff --git a/collect_app/src/main/res/values/arrays.xml b/collect_app/src/main/res/values/arrays.xml index 1a0bfcea7af..e8ac31c790a 100644 --- a/collect_app/src/main/res/values/arrays.xml +++ b/collect_app/src/main/res/values/arrays.xml @@ -147,6 +147,20 @@ the specific language governing permissions and limitations under the License. - @string/persian_month_11 @string/persian_month_12 + + @string/buddhist_month_1 + @string/buddhist_month_2 + @string/buddhist_month_3 + @string/buddhist_month_4 + @string/buddhist_month_5 + @string/buddhist_month_6 + @string/buddhist_month_7 + @string/buddhist_month_8 + @string/buddhist_month_9 + @string/buddhist_month_10 + @string/buddhist_month_11 + @string/buddhist_month_12 + @string/every_fifteen_minutes_value @string/every_one_hour_value diff --git a/strings/src/main/res/values/strings.xml b/strings/src/main/res/values/strings.xml index 6b4b0d7ca8c..5fc50069ee5 100644 --- a/strings/src/main/res/values/strings.xml +++ b/strings/src/main/res/values/strings.xml @@ -413,6 +413,32 @@ Dey Bahman Esfand + + + มกราคม + + กุมภาพันธ์ + + มีนาคม + + เมษายน + + พฤษภาคม + + มิถุนายน + + กรกฎาคม + + สิงหาคม + + กันยายน + + ตุลาคม + + พฤศจิกายน + + ธันวาคม + %1$s (%2$s) From ce7d8cec7aded41ae05eb03a705058fa570bc32b Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Mon, 19 Aug 2024 22:22:40 +0200 Subject: [PATCH 7/7] Moved scrollNumberPickerToValue to ViewActions --- .../odk/collect/android/support/Actions.kt | 56 ------------------- .../pickers/BuddhistDatePickerDialogTest.kt | 8 +-- .../org/odk/collect/testshared/ViewActions.kt | 48 ++++++++++++++++ 3 files changed, 52 insertions(+), 60 deletions(-) delete mode 100644 collect_app/src/test/java/org/odk/collect/android/support/Actions.kt diff --git a/collect_app/src/test/java/org/odk/collect/android/support/Actions.kt b/collect_app/src/test/java/org/odk/collect/android/support/Actions.kt deleted file mode 100644 index 45794615ae9..00000000000 --- a/collect_app/src/test/java/org/odk/collect/android/support/Actions.kt +++ /dev/null @@ -1,56 +0,0 @@ -package org.odk.collect.android.support - -import android.view.View -import android.widget.NumberPicker -import androidx.test.espresso.UiController -import androidx.test.espresso.ViewAction -import androidx.test.espresso.action.GeneralLocation -import androidx.test.espresso.action.GeneralSwipeAction -import androidx.test.espresso.action.Press -import androidx.test.espresso.action.Swipe -import androidx.test.espresso.matcher.ViewMatchers -import org.hamcrest.Matcher - -object Actions { - fun scrollNumberPickerToValue(targetValue: Int): ViewAction { - return object : ViewAction { - override fun getConstraints(): Matcher { - return ViewMatchers.isAssignableFrom(NumberPicker::class.java) - } - - override fun getDescription(): String { - return "Scroll the NumberPicker to a specific value" - } - - override fun perform(uiController: UiController, view: View) { - val numberPicker = view as NumberPicker - - while (targetValue != numberPicker.value) { - if (targetValue < numberPicker.value) { - swipeDown(uiController, view) - } else { - swipeUp(uiController, view) - } - } - } - - private fun swipeUp(uiController: UiController, view: View) { - GeneralSwipeAction( - Swipe.SLOW, - GeneralLocation.CENTER, - GeneralLocation.TOP_CENTER, - Press.FINGER - ).perform(uiController, view) - } - - private fun swipeDown(uiController: UiController, view: View) { - GeneralSwipeAction( - Swipe.SLOW, - GeneralLocation.CENTER, - GeneralLocation.BOTTOM_CENTER, - Press.FINGER - ).perform(uiController, view) - } - } - } -} diff --git a/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialogTest.kt b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialogTest.kt index c5d3edf47cf..76fef393862 100644 --- a/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialogTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialogTest.kt @@ -16,7 +16,6 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.odk.collect.android.R -import org.odk.collect.android.support.Actions import org.odk.collect.android.widgets.datetime.DatePickerDetails import org.odk.collect.android.widgets.datetime.DatePickerDetails.DatePickerMode import org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils @@ -24,6 +23,7 @@ import org.odk.collect.fragmentstest.FragmentScenarioLauncherRule import org.odk.collect.strings.R.string import org.odk.collect.testshared.Assertions import org.odk.collect.testshared.Interactions +import org.odk.collect.testshared.ViewActions @RunWith(AndroidJUnit4::class) class BuddhistDatePickerDialogTest { @@ -272,13 +272,13 @@ class BuddhistDatePickerDialogTest { private fun updateDate(day: Int? = null, month: Int? = null, year: Int? = null) { day?.let { - onView(withId(R.id.day_picker)).inRoot(isDialog()).perform(Actions.scrollNumberPickerToValue(it)) + onView(withId(R.id.day_picker)).inRoot(isDialog()).perform(ViewActions.scrollNumberPickerToValue(it)) } month?.let { - onView(withId(R.id.month_picker)).inRoot(isDialog()).perform(Actions.scrollNumberPickerToValue(it)) + onView(withId(R.id.month_picker)).inRoot(isDialog()).perform(ViewActions.scrollNumberPickerToValue(it)) } year?.let { - onView(withId(R.id.year_picker)).inRoot(isDialog()).perform(Actions.scrollNumberPickerToValue(it)) + onView(withId(R.id.year_picker)).inRoot(isDialog()).perform(ViewActions.scrollNumberPickerToValue(it)) } } diff --git a/test-shared/src/main/java/org/odk/collect/testshared/ViewActions.kt b/test-shared/src/main/java/org/odk/collect/testshared/ViewActions.kt index 7f500982038..83f830e2c90 100644 --- a/test-shared/src/main/java/org/odk/collect/testshared/ViewActions.kt +++ b/test-shared/src/main/java/org/odk/collect/testshared/ViewActions.kt @@ -3,13 +3,19 @@ package org.odk.collect.testshared import android.content.Context import android.view.View import android.view.ViewGroup +import android.widget.NumberPicker import androidx.annotation.StringRes import androidx.core.view.allViews import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.test.espresso.UiController import androidx.test.espresso.ViewAction +import androidx.test.espresso.action.GeneralLocation +import androidx.test.espresso.action.GeneralSwipeAction +import androidx.test.espresso.action.Press +import androidx.test.espresso.action.Swipe import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import org.hamcrest.Matcher @@ -35,4 +41,46 @@ object ViewActions { fun clickOnItemWith(matcher: Matcher): ViewAction { return actionOnItem(hasDescendant(matcher), click()) } + + fun scrollNumberPickerToValue(targetValue: Int): ViewAction { + return object : ViewAction { + override fun getConstraints(): Matcher { + return ViewMatchers.isAssignableFrom(NumberPicker::class.java) + } + + override fun getDescription(): String { + return "Scroll the NumberPicker to a specific value" + } + + override fun perform(uiController: UiController, view: View) { + val numberPicker = view as NumberPicker + + while (targetValue != numberPicker.value) { + if (targetValue < numberPicker.value) { + swipeDown(uiController, view) + } else { + swipeUp(uiController, view) + } + } + } + + private fun swipeUp(uiController: UiController, view: View) { + GeneralSwipeAction( + Swipe.SLOW, + GeneralLocation.CENTER, + GeneralLocation.TOP_CENTER, + Press.FINGER + ).perform(uiController, view) + } + + private fun swipeDown(uiController: UiController, view: View) { + GeneralSwipeAction( + Swipe.SLOW, + GeneralLocation.CENTER, + GeneralLocation.BOTTOM_CENTER, + Press.FINGER + ).perform(uiController, view) + } + } + } }