2929import static org .hamcrest .core .IsEqual .equalTo ;
3030
3131import android .app .Activity ;
32+ import androidx .annotation .VisibleForTesting ;
3233import androidx .fragment .app .DialogFragment ;
3334import androidx .fragment .app .Fragment ;
3435import androidx .fragment .app .FragmentManager ;
4748
4849public final class MaterialDatePickerTestUtils {
4950
51+ @ VisibleForTesting public static final Month OPENING = Month .create (2018 , Calendar .APRIL );
52+
5053 private MaterialDatePickerTestUtils () {}
5154
5255 private static final ViewInteraction onMonthsGroup =
@@ -68,9 +71,8 @@ public static MaterialDatePicker<Long> showDatePicker(
6871
6972 Month start = Month .create (1900 , Calendar .JANUARY );
7073 Month end = Month .create (2100 , Calendar .DECEMBER );
71- Month current = Month .create (2018 , Calendar .APRIL );
7274 CalendarConstraints calendarConstraints =
73- new CalendarConstraints .Builder ().setStart (start ).setEnd (end ).setOpening (current ).build ();
75+ new CalendarConstraints .Builder ().setStart (start ).setEnd (end ).setOpening (OPENING ).build ();
7476
7577 return showDatePicker (activityTestRule , themeResId , calendarConstraints );
7678 }
@@ -107,9 +109,8 @@ public static MaterialDatePicker<Pair<Long, Long>> showRangePicker(
107109 ActivityTestRule <? extends AppCompatActivity > activityTestRule , int themeResId ) {
108110 Month start = Month .create (1900 , Calendar .JANUARY );
109111 Month end = Month .create (2100 , Calendar .DECEMBER );
110- Month current = Month .create (2018 , Calendar .APRIL );
111112 CalendarConstraints calendarConstraints =
112- new CalendarConstraints .Builder ().setStart (start ).setEnd (end ).setOpening (current ).build ();
113+ new CalendarConstraints .Builder ().setStart (start ).setEnd (end ).setOpening (OPENING ).build ();
113114 return showRangePicker (activityTestRule , themeResId , calendarConstraints );
114115 }
115116
@@ -187,7 +188,8 @@ static void clickSelectorToggle() {
187188 InstrumentationRegistry .getInstrumentation ().waitForIdleSync ();
188189 }
189190
190- static void swipeEarlier (DialogFragment dialogFragment ) {
191+ @ VisibleForTesting
192+ public static void swipeEarlier (DialogFragment dialogFragment ) {
191193 int orientation = getOrientation (dialogFragment );
192194 if (orientation == LinearLayoutManager .HORIZONTAL ) {
193195 onMonthsGroup .perform (swipeRight ());
@@ -235,6 +237,15 @@ static void hideAllEditTextCursors(View view) {
235237 }
236238 }
237239
240+ @ VisibleForTesting
241+ public static Month findFirstVisibleItem (DialogFragment dialogFragment ) {
242+ RecyclerView recyclerView =
243+ dialogFragment .getView ().findViewWithTag (MaterialCalendar .MONTHS_VIEW_GROUP_TAG );
244+ MonthsPagerAdapter monthsPagerAdapter = (MonthsPagerAdapter ) recyclerView .getAdapter ();
245+ return monthsPagerAdapter .getPageMonth (
246+ ((LinearLayoutManager ) recyclerView .getLayoutManager ()).findFirstVisibleItemPosition ());
247+ }
248+
238249 private static int getOrientation (DialogFragment dialogFragment ) {
239250 return ((LinearLayoutManager ) getMonthsViewGroup (dialogFragment ).getLayoutManager ())
240251 .getOrientation ();
0 commit comments