Show an agenda in the clock widget's dynamic zone, with multiple slots
The dynamic zone showed exactly one part: the highest ranked of the enabled ones. It now shows up to `clockWidgetDynamicZoneSlots` of them (default 1), adjustable with a slider in the clock widget settings whose maximum is the number of enabled parts. `ClockWidgetVM.getActiveParts()` returns that sorted list, and both clock layouts render it (stacked under the clock, or next to it in the horizontal layout). On top of that the zone has an "Events" part (`clockWidgetCalendarPart`, off by default) that shows today's agenda: events that are still running or upcoming today, plus today's all-day events. At most four rows; when there are more, the last row is a "+N more events" hint that opens the calendar app. Tapping a row opens the event through `CalendarEvent.launch()`. A row is three fixed-width columns that are pure layout, not drawn: a dot in the calendar's colour, the time, and the title (ellipsized when it does not fit). Times are always times, never dates - an all-day event renders "all-day" - and the block is centred under the clock. The columns line up across rows, and the time is left-aligned within its column. The part ranks 70 when an event is running or starts within half an hour, 30 while events are left today and 0 on an empty day, so the date keeps the slot when there is nothing to show. It reloads itself through a ContentObserver on CalendarContract.Events and a 15 minute ticker, because unlike the calendar widget it is on screen all the time. Tasks (`CalendarEvent.isTask`) are filtered out for now; a tasks part can reuse this once tasks are configured. Verified on the Titan 2: with the part enabled and three slots, the home screen shows the agenda (two all-day events and a timed one) above the date part.
This commit is contained in:
@@ -598,6 +598,7 @@
|
||||
<string name="preference_clock_widget_alignment_center">Center</string>
|
||||
<string name="preference_clock_widget_alignment_bottom">Bottom</string>
|
||||
<string name="preference_clockwidget_dynamic_zone">Dynamic zone</string>
|
||||
<string name="preference_clockwidget_dynamic_zone_slots">Visible parts</string>
|
||||
<string name="preference_clockwidget_smartspacer">Managed by Smartspacer</string>
|
||||
<string name="preference_clockwidget_date_part">Date</string>
|
||||
<string name="preference_clockwidget_date_part_summary">Show the current date</string>
|
||||
@@ -612,6 +613,13 @@
|
||||
<string name="preference_clockwidget_battery_part_hide">Off</string>
|
||||
<string name="preference_clockwidget_alarm_part">Alarms</string>
|
||||
<string name="preference_clockwidget_alarm_part_summary">Show alarms that will ring within the next 8 hours</string>
|
||||
<string name="preference_clockwidget_calendar_part">Events</string>
|
||||
<string name="preference_clockwidget_calendar_part_summary">Show today\'s agenda</string>
|
||||
<string name="clockwidget_calendar_part_all_day">all-day</string>
|
||||
<plurals name="clockwidget_calendar_part_more_events">
|
||||
<item quantity="one">+%d more event</item>
|
||||
<item quantity="other">+%d more events</item>
|
||||
</plurals>
|
||||
<string name="preference_screen_backup">Backup and restore</string>
|
||||
<string name="preference_screen_backup_summary">Export and import launcher data</string>
|
||||
<string name="preference_backup">Backup</string>
|
||||
|
||||
@@ -58,6 +58,8 @@ data class LauncherSettingsData internal constructor(
|
||||
val clockWidgetBatteryPart: BatteryStatusVisibility = BatteryStatusVisibility.Show,
|
||||
val clockWidgetMusicPart: Boolean = true,
|
||||
val clockWidgetDatePart: Boolean = true,
|
||||
val clockWidgetCalendarPart: Boolean = false,
|
||||
val clockWidgetDynamicZoneSlots: Int = 1,
|
||||
val clockWidgetFillHeight: Boolean = false,
|
||||
val clockWidgetAlignment: ClockWidgetAlignment = ClockWidgetAlignment.Bottom,
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ data class ClockWidgetParts(
|
||||
val music: Boolean = false,
|
||||
val battery: BatteryStatusVisibility = BatteryStatusVisibility.Hide,
|
||||
val alarm: Boolean = false,
|
||||
val calendar: Boolean = false,
|
||||
)
|
||||
|
||||
class ClockWidgetSettings internal constructor(
|
||||
@@ -37,9 +38,29 @@ class ClockWidgetSettings internal constructor(
|
||||
music = it.clockWidgetMusicPart,
|
||||
battery = it.clockWidgetBatteryPart,
|
||||
alarm = it.clockWidgetAlarmPart,
|
||||
calendar = it.clockWidgetCalendarPart,
|
||||
)
|
||||
}.distinctUntilChanged()
|
||||
|
||||
/**
|
||||
* Maximum number of parts the dynamic zone shows at once.
|
||||
*/
|
||||
val slots
|
||||
get() = launcherDataStore.data.map { it.clockWidgetDynamicZoneSlots.coerceAtLeast(1) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
fun setSlots(slots: Int) {
|
||||
launcherDataStore.update {
|
||||
it.copy(clockWidgetDynamicZoneSlots = slots.coerceAtLeast(1))
|
||||
}
|
||||
}
|
||||
|
||||
fun setCalendarPart(calendarPart: Boolean) {
|
||||
launcherDataStore.update {
|
||||
it.copy(clockWidgetCalendarPart = calendarPart)
|
||||
}
|
||||
}
|
||||
|
||||
fun setDatePart(datePart: Boolean) {
|
||||
launcherDataStore.update {
|
||||
it.copy(clockWidgetDatePart = datePart)
|
||||
|
||||
Reference in New Issue
Block a user