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

Commit 7a4b4c96 authored by Matías Hernández's avatar Matías Hernández
Browse files

Expose components of the ScheduleInfo string representation

(To be used in Modes Settings).

Bug: 349376785
Test: atest SystemZenRulesTest
Flag: android.app.modes_ui
Change-Id: I2bfc83ab01b116d9f2326300bf4e5294dee18df6
parent d2043307
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");
    }
}