Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18b60764 authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Expose components of the ScheduleInfo string representation" into main

parents dcd7eb59 7a4b4c96
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -129,10 +129,7 @@ public final class SystemZenRules {
        }
        sb.append(daysSummary);
        sb.append(context.getString(R.string.zen_mode_trigger_summary_divider_text));
        sb.append(context.getString(
                R.string.zen_mode_trigger_summary_range_symbol_combination,
                timeString(context, schedule.startHour, schedule.startMinute),
                timeString(context, schedule.endHour, schedule.endMinute)));
        sb.append(getTimeSummary(context, schedule));

        return sb.toString();
    }
@@ -142,7 +139,7 @@ public final class SystemZenRules {
     * adjacent days grouped together ("Sun-Wed" instead of "Sun,Mon,Tue,Wed").
     */
    @Nullable
    private static String getShortDaysSummary(Context context, @NonNull ScheduleInfo schedule) {
    public static String getShortDaysSummary(Context context, @NonNull ScheduleInfo schedule) {
        // Compute a list of days with contiguous days grouped together, for example: "Sun-Thu" or
        // "Sun-Mon,Wed,Fri"
        final int[] days = schedule.days;
@@ -224,6 +221,14 @@ public final class SystemZenRules {
        return null;
    }

    /** Returns the time part of a {@link ScheduleInfo}, e.g. {@code 9:00-17:00}. */
    public static String getTimeSummary(Context context, @NonNull ScheduleInfo schedule) {
        return context.getString(
                R.string.zen_mode_trigger_summary_range_symbol_combination,
                timeString(context, schedule.startHour, schedule.startMinute),
                timeString(context, schedule.endHour, schedule.endMinute));
    }

    /**
     * Convenience method for representing the specified time in string format.
     */
+24 −0
Original line number Diff line number Diff line
@@ -207,4 +207,28 @@ public class SystemZenRulesTest extends UiServiceTestCase {
        assertThat(getTriggerDescriptionForScheduleTime(mContext, scheduleInfo))
                .isEqualTo("Mon,Wed,Fri-Sat,10:00 AM-4:00 PM");
    }

    @Test
    public void getShortDaysSummary_onlyDays() {
        ScheduleInfo scheduleInfo = new ScheduleInfo();
        scheduleInfo.startHour = 10;
        scheduleInfo.endHour = 16;
        scheduleInfo.days = new int[] {Calendar.MONDAY, Calendar.TUESDAY,
                Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY};

        assertThat(SystemZenRules.getShortDaysSummary(mContext, scheduleInfo))
                .isEqualTo("Mon-Fri");
    }

    @Test
    public void getTimeSummary_onlyTime() {
        ScheduleInfo scheduleInfo = new ScheduleInfo();
        scheduleInfo.startHour = 11;
        scheduleInfo.endHour = 15;
        scheduleInfo.days = new int[] {Calendar.MONDAY, Calendar.TUESDAY,
                Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY};

        assertThat(SystemZenRules.getTimeSummary(mContext, scheduleInfo))
                .isEqualTo("11:00 AM-3:00 PM");
    }
}