From 00f7bb2c351399dfa4e5d39b686e770aa6b1a9de Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 1 Mar 2021 01:01:59 -0300 Subject: [PATCH 1/2] Improved Notifications: enhanced user interface --- Utilities/space.sh | 2 +- rwatch/ui/layer/single_notification_layer.c | 262 +++++++++++--------- rwatch/ui/notification_window.c | 201 +++++++++------ 3 files changed, 267 insertions(+), 198 deletions(-) diff --git a/Utilities/space.sh b/Utilities/space.sh index c276ab5d..a5f9a62f 100755 --- a/Utilities/space.sh +++ b/Utilities/space.sh @@ -14,4 +14,4 @@ if [[ $(getsym _ccm_top) ]]; then fi echo "$RAM_REMAIN bytes of RAM available for heap." -echo "$FLASH_REMAIN bytes of flash unused." +echo "$FLASH_REMAIN bytes of flash unused." \ No newline at end of file diff --git a/rwatch/ui/layer/single_notification_layer.c b/rwatch/ui/layer/single_notification_layer.c index 5efd4b9b..5010d680 100644 --- a/rwatch/ui/layer/single_notification_layer.c +++ b/rwatch/ui/layer/single_notification_layer.c @@ -17,28 +17,32 @@ #include "single_notification_layer.h" #include "minilib.h" +#include "status_bar_layer.h" + static void single_notification_layer_update_proc(Layer *layer, GContext *ctx); #define X_PADDING 4 #define APPNAME_HEIGHT 28 -#define APPNAME_PADDING 6 -#define ELEMENT_PADDING 5 -#define APPNAME_FONT FONT_KEY_GOTHIC_28_BOLD -#define TITLE_FONT FONT_KEY_GOTHIC_18_BOLD -#define SUBTITLE_FONT FONT_KEY_GOTHIC_18 -#define BODY_FONT FONT_KEY_GOTHIC_24_BOLD +#define APPNAME_PADDING 8 +#define ELEMENT_PADDING 8 +#define APPNAME_FONT FONT_KEY_GOTHIC_24_BOLD +#define TITLE_FONT FONT_KEY_GOTHIC_18_BOLD +#define SUBTITLE_FONT FONT_KEY_GOTHIC_18 +#define BODY_FONT FONT_KEY_GOTHIC_24_BOLD #define TIMESTAMP_FONT FONT_KEY_GOTHIC_14 -void single_notification_layer_ctor(SingleNotificationLayer *l, GRect frame) { +void single_notification_layer_ctor(SingleNotificationLayer *l, GRect frame) +{ layer_ctor(&l->layer, frame); layer_set_update_proc(&l->layer, single_notification_layer_update_proc); - + l->title = l->subtitle = l->body = l->timestamp = NULL; l->icon = NULL; } -void single_notification_layer_dtor(SingleNotificationLayer *l) { +void single_notification_layer_dtor(SingleNotificationLayer *l) +{ free(l->title); free(l->subtitle); free(l->body); @@ -47,23 +51,32 @@ void single_notification_layer_dtor(SingleNotificationLayer *l) { layer_dtor(&l->layer); } -extern void single_notification_layer_set_notification(SingleNotificationLayer *l, rebble_notification *notif) { +extern void single_notification_layer_set_notification(SingleNotificationLayer *l, rebble_notification *notif) +{ free(l->title); free(l->subtitle); free(l->body); free(l->timestamp); if (l->icon) gbitmap_destroy(l->icon); - + const char *sender = NULL, *subject = NULL, *message = NULL; uint32_t sourcetype = 0; - + rebble_attribute *a; - list_foreach(a, ¬if->attributes, rebble_attribute, node) { - switch (a->timeline_attribute.attribute_id) { - case TimelineAttributeType_Sender: sender = (const char *) a->data; break; - case TimelineAttributeType_Subject: subject = (const char *) a->data; break; - case TimelineAttributeType_Message: message = (const char *) a->data; break; + list_foreach(a, ¬if->attributes, rebble_attribute, node) + { + switch (a->timeline_attribute.attribute_id) + { + case TimelineAttributeType_Sender: + sender = (const char *)a->data; + break; + case TimelineAttributeType_Subject: + subject = (const char *)a->data; + break; + case TimelineAttributeType_Message: + message = (const char *)a->data; + break; case TimelineAttributeType_SourceType: sourcetype = *(uint32_t *)a->data; break; @@ -72,25 +85,39 @@ extern void single_notification_layer_set_notification(SingleNotificationLayer * ; } } - - if (sender && strlen(sender)) { + + if (sender && strlen(sender)) + { l->title = strdup(sender); if (subject && strlen(subject)) l->subtitle = strdup(subject); l->body = message ? strdup(message) : NULL; - } else { + } + else + { if (subject && strlen(subject)) l->title = strdup(subject); l->body = message ? strdup(message) : NULL; } - - switch (sourcetype) { + + switch (sourcetype) + { + // since the 'source' will be useful just to set its respective icon, there's no need + // to hard code the app name using it. 'subject' will be used instead. case TimelineNotificationSource_SMS: - l->source = "SMS"; + //l->source = "SMS"; l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); break; case TimelineNotificationSource_Email: - l->source = "Email"; + //l->source = "Email"; + l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); + break; + case TimelineNotificationSource_Twitter: + //l->source = "Twitter"; + l->icon = gbitmap_create_with_resource(RESOURCE_ID_UNKNOWN); + break; + case TimelineNotificationSource_Facebook: + //l->source = "Facebook"; l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); break; default: @@ -98,157 +125,160 @@ extern void single_notification_layer_set_notification(SingleNotificationLayer * l->icon = gbitmap_create_with_resource(RESOURCE_ID_UNKNOWN); break; } - + time_t now = rcore_get_time(); time_t ts = notif->timeline_item.timestamp; struct tm tm_ts; localtime_r(&ts, &tm_ts); - + char buf[32]; - + if (ts > now) l->timestamp = strdup("The future"); - else if (ts > (now - 60 * 60)) { + else if (ts > (now - 60 * 60)) + { sfmt(buf, sizeof(buf), "%d min ago", (ts - now) / 60); l->timestamp = strdup(buf); - } else if (ts > (now - 24 * 60 * 60)) { + } + else if (ts > (now - 24 * 60 * 60)) + { sfmt(buf, sizeof(buf), "%d hours ago", (ts - now) / (60 * 60)); l->timestamp = strdup(buf); - } else if (ts > (now - 7 * 24 * 60 * 60)) { - char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + } + else if (ts > (now - 7 * 24 * 60 * 60)) + { + char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; sfmt(buf, sizeof(buf), "%s, %02d:%02d", days[tm_ts.tm_mday], tm_ts.tm_hour, tm_ts.tm_min); l->timestamp = strdup(buf); - } else { - char *mons[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + } + else + { + char *mons[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; sfmt(buf, sizeof(buf), "%s %d, %02d:%02d", mons[tm_ts.tm_mon], tm_ts.tm_mday, tm_ts.tm_hour, tm_ts.tm_min); l->timestamp = strdup(buf); } - + layer_mark_dirty(&l->layer); } -Layer *single_notification_layer_get_layer(SingleNotificationLayer *l) { +Layer *single_notification_layer_get_layer(SingleNotificationLayer *l) +{ return &l->layer; } -#ifdef PBL_RECT +//#ifdef PBL_RECT -uint16_t single_notification_layer_height(SingleNotificationLayer *l) { +uint16_t single_notification_layer_height(SingleNotificationLayer *l) +{ uint16_t height = 0; - + GRect szrect = layer_get_frame(&l->layer); szrect.size.h = 1000; szrect.size.w -= X_PADDING * 2; - + height += APPNAME_HEIGHT; height += APPNAME_PADDING; if (l->title) height += n_graphics_text_layout_get_content_size_with_attributes( - l->title, fonts_get_system_font(TITLE_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h - + ELEMENT_PADDING; + l->title, fonts_get_system_font(TITLE_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) + .h + + ELEMENT_PADDING; if (l->subtitle) height += n_graphics_text_layout_get_content_size_with_attributes( - l->subtitle, fonts_get_system_font(SUBTITLE_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h - + ELEMENT_PADDING; + l->subtitle, fonts_get_system_font(SUBTITLE_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) + .h + + ELEMENT_PADDING; if (l->body) height += n_graphics_text_layout_get_content_size_with_attributes( - l->body, fonts_get_system_font(BODY_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h - + ELEMENT_PADDING; + l->body, fonts_get_system_font(BODY_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) + .h + + ELEMENT_PADDING; height += n_graphics_text_layout_get_content_size_with_attributes( - l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h - + ELEMENT_PADDING; - + l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) + .h + + ELEMENT_PADDING; + return height; } -static void single_notification_layer_update_proc(Layer *layer, GContext *ctx) { +static void single_notification_layer_update_proc(Layer *layer, GContext *ctx) +{ SingleNotificationLayer *l = container_of(layer, SingleNotificationLayer, layer); GRect szrect = layer_get_frame(layer); GSize outsz; - + graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, szrect, 0, GCornerNone); - + graphics_context_set_text_color(ctx, GColorBlack); - + szrect.origin.x = 0; - szrect.origin.y = 0; - + szrect.origin.y = STATUS_BAR_LAYER_HEIGHT; + szrect.origin.x += X_PADDING; - szrect.size.w -= X_PADDING * 2; - - if (l->source) { - GRect tmpsz = szrect; - tmpsz.origin.x += 1; - tmpsz.origin.y += 6; - tmpsz.size.h = 25; - tmpsz.size.w = 25; - graphics_context_set_compositing_mode(ctx, GCompOpSet); - graphics_draw_bitmap_in_rect(ctx, l->icon, tmpsz); - - tmpsz = szrect; - tmpsz.size.h = APPNAME_HEIGHT; - tmpsz.size.w -= APPNAME_HEIGHT + ELEMENT_PADDING; - tmpsz.origin.x += APPNAME_HEIGHT + ELEMENT_PADDING; - graphics_draw_text(ctx, l->source, fonts_get_system_font(APPNAME_FONT), - tmpsz, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0); - szrect.origin.y += APPNAME_HEIGHT; - szrect.size.h -= APPNAME_HEIGHT; - } else { - /* no source, just a centered icon */ - GRect tmpsz = szrect; - tmpsz.origin.x += (tmpsz.size.w - 25) / 2; - tmpsz.origin.y += 5; - tmpsz.size.h = 25; - tmpsz.size.w = 25; - graphics_context_set_compositing_mode(ctx, GCompOpSet); - graphics_draw_bitmap_in_rect(ctx, l->icon, tmpsz); + szrect.size.w -= X_PADDING * 2; + + /* +from libpebble2.services.notifications import Notifications +Notifications(pebble, None).send_notification(subject = "hello", sender = "How Are you?") + */ + + GRect tmpsz = szrect; + tmpsz.size.h = 25; + tmpsz.size.w = 25; + graphics_context_set_compositing_mode(ctx, GCompOpSet); + graphics_draw_bitmap_in_rect(ctx, l->icon, tmpsz); + + tmpsz = szrect; + tmpsz.size.h = APPNAME_HEIGHT; // Align text vertically + tmpsz.size.w -= APPNAME_HEIGHT + ELEMENT_PADDING; + tmpsz.origin.x += APPNAME_HEIGHT; + if (l->title) + { + graphics_draw_text(ctx, l->title, fonts_get_system_font(APPNAME_FONT), + tmpsz, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0); szrect.origin.y += APPNAME_HEIGHT; - szrect.size.h -= APPNAME_HEIGHT; + szrect.size.h -= APPNAME_HEIGHT; } - + graphics_context_set_stroke_color(ctx, GColorBlack); - graphics_context_set_stroke_width(ctx, 3); + graphics_context_set_stroke_width(ctx, 1); + /* XXX: make this a drawrect */ graphics_draw_line(ctx, - GPoint(szrect.origin.x, szrect.origin.y + 5), - GPoint(szrect.origin.x + szrect.size.w, szrect.origin.y + 5)); - szrect.origin.y += APPNAME_PADDING; - szrect.size.h -= APPNAME_PADDING; - - if (l->title) { - graphics_draw_text_ex(ctx, - l->title, fonts_get_system_font(TITLE_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); - szrect.origin.y += outsz.h + ELEMENT_PADDING; - szrect.size.h -= outsz.h + ELEMENT_PADDING; - } - if (l->subtitle) { + GPoint(szrect.origin.x, szrect.origin.y), + GPoint(szrect.origin.x + szrect.size.w, szrect.origin.y)); + szrect.origin.y += 0; + szrect.size.h -= APPNAME_PADDING; + + if (l->subtitle) + { graphics_draw_text_ex(ctx, - l->subtitle, fonts_get_system_font(SUBTITLE_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); - szrect.origin.y += outsz.h + ELEMENT_PADDING; - szrect.size.h -= outsz.h + ELEMENT_PADDING; + l->subtitle, fonts_get_system_font(SUBTITLE_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); + szrect.origin.y += outsz.h; + szrect.size.h -= outsz.h; } - if (l->body) { + if (l->body) + { graphics_draw_text_ex(ctx, - l->body, fonts_get_system_font(BODY_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); + l->body, fonts_get_system_font(BODY_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); szrect.origin.y += outsz.h + ELEMENT_PADDING; - szrect.size.h -= outsz.h + ELEMENT_PADDING; + szrect.size.h -= outsz.h + ELEMENT_PADDING; } graphics_draw_text_ex(ctx, - l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); + l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); szrect.origin.y += outsz.h + ELEMENT_PADDING; - szrect.size.h -= outsz.h + ELEMENT_PADDING; + szrect.size.h -= outsz.h + ELEMENT_PADDING; } -#else /* !PBL_RECT */ -# error single_notification_layer not implemented on non-rectangular Pebbles -#endif +//#else /* !PBL_RECT */ +//#error single_notification_layer not implemented on non-rectangular Pebbles +//#endif diff --git a/rwatch/ui/notification_window.c b/rwatch/ui/notification_window.c index 34a78914..cce628e4 100644 --- a/rwatch/ui/notification_window.c +++ b/rwatch/ui/notification_window.c @@ -5,21 +5,27 @@ * Author: Joshua Wise */ +#include "rebbleos.h" #include "notification_window.h" #include "timeline.h" +#include "status_bar_layer.h" + static void _notification_window_load(Window *window); static void _notification_window_unload(Window *window); +static StatusBarLayer *_notif_window_status; + #ifndef PBL_RECT -# error notification_window not implemented on round Pebble +#error notification_window not implemented on round Pebble #endif #define VIEWPORT_HEIGHT DISPLAY_ROWS #define NUDGE_HEIGHT 40 #define SCROLL_INCR 20 -void notification_window_ctor(NotificationWindow *w, Window *win) { +void notification_window_ctor(NotificationWindow *w, Window *win) +{ w->window = win; win->user_data = w; /* we use this because the noty / overlay subsystem uses context */ @@ -28,43 +34,46 @@ void notification_window_ctor(NotificationWindow *w, Window *win) { frame.origin.y = 0; frame.size.w = DISPLAY_COLS; frame.size.h = 2048; - + w->uuids = NULL; w->nuuids = 0; - - w->curnotif = (size_t) -1; + + w->curnotif = (size_t)-1; w->curnotif_nudging = 0; - + single_notification_layer_ctor(&w->n1, frame); single_notification_layer_ctor(&w->n2, frame); - - window_set_window_handlers(w->window, (WindowHandlers) { - .load = _notification_window_load, - .unload = _notification_window_unload - }); + + window_set_window_handlers(w->window, (WindowHandlers){ + .load = _notification_window_load, + .unload = _notification_window_unload}); } -void notification_window_dtor(NotificationWindow *w) { +void notification_window_dtor(NotificationWindow *w) +{ single_notification_layer_dtor(&w->n1); single_notification_layer_dtor(&w->n2); } -void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, size_t count, size_t curnotif) { +void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, size_t count, size_t curnotif) +{ void *newuuids = realloc(w->uuids, count * sizeof(Uuid)); - if (!newuuids) { + if (!newuuids) + { free(w->uuids); w->nuuids = 0; w->uuids = NULL; - w->curnotif = (size_t) -1; + w->curnotif = (size_t)-1; return; } w->uuids = newuuids; - + memcpy(w->uuids, uuids, count * sizeof(Uuid)); w->nuuids = count; - - if (curnotif >= count) { - w->curnotif = (size_t) -1; + + if (curnotif >= count) + { + w->curnotif = (size_t)-1; return; } @@ -79,19 +88,21 @@ void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, s w->curnotif_nudging = 0; w->curnotif = curnotif; - + rebble_notification *notif = timeline_get_notification(w->uuids + curnotif); - if (!notif) { - w->curnotif = (size_t) -1; + if (!notif) + { + w->curnotif = (size_t)-1; return; } single_notification_layer_set_notification(&w->n1, notif); timeline_destroy(notif); - + w->curnotif_height = single_notification_layer_height(&w->n1); } -void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) { +void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) +{ #if 0 void *newuuids = realloc(w->uuids, (w->nuuids + 1) * sizeof(Uuid)); if (!newuuids) @@ -108,76 +119,84 @@ void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) { #endif *w->uuids = *uuid; w->nuuids++; - - if (w->curnotif || w->curnotif_scroll) { + + if (w->curnotif || w->curnotif_scroll) + { w->curnotif++; return; } - + /* We're the top notification and haven't scrolled, so we reset the * notification to view the new one. */ rebble_notification *notif = timeline_get_notification(w->uuids); - if (!notif) { - w->curnotif = (size_t) -1; + if (!notif) + { + w->curnotif = (size_t)-1; return; } single_notification_layer_set_notification(&w->n1, notif); timeline_destroy(notif); - + w->curnotif_height = single_notification_layer_height(&w->n1); } -Window *notification_window_get_window(NotificationWindow *w) { +Window *notification_window_get_window(NotificationWindow *w) +{ return w->window; } -static void _down_single_click_handler(ClickRecognizerRef _, void *_w) { +static void _down_single_click_handler(ClickRecognizerRef _, void *_w) +{ NotificationWindow *w = _w; - + w->curnotif_scroll += SCROLL_INCR; if (w->curnotif == -1) return; - + int16_t curnotif_maxscroll = w->curnotif_height - VIEWPORT_HEIGHT; if (curnotif_maxscroll < 0) curnotif_maxscroll = 0; - int16_t curnotif_nudge = curnotif_maxscroll + NUDGE_HEIGHT; - if (w->curnotif_nudging) { + int16_t curnotif_nudge = curnotif_maxscroll + NUDGE_HEIGHT; + if (w->curnotif_nudging) + { /* We are nudging and moving still scrolling down -- swap the * notifications to the next. We can only be nudging if there is a * next notification, so we're good on that front. */ w->curnotif++; w->curnotif_scroll = 0; w->curnotif_nudging = 0; - + rebble_notification *notif = timeline_get_notification(w->uuids + w->curnotif); - if (!notif) { - w->curnotif = (size_t) -1; + if (!notif) + { + w->curnotif = (size_t)-1; return; } single_notification_layer_set_notification(&w->n1, notif); timeline_destroy(notif); layer_remove_from_parent(single_notification_layer_get_layer(&w->n2)); - + GRect frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = 0; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); - + w->curnotif_height = single_notification_layer_height(&w->n1); - - } else if ((w->curnotif_scroll > curnotif_maxscroll) && !w->curnotif_nudging && ((w->curnotif + 1) < w->nuuids)) { + } + else if ((w->curnotif_scroll > curnotif_maxscroll) && !w->curnotif_nudging && ((w->curnotif + 1) < w->nuuids)) + { /* We're moving down and about to run out, and there's another * notification ready. Load it into the nudge box at the bottom. */ w->curnotif_scroll = curnotif_nudge; w->curnotif_nudging = 1; - + /* Load the next one in place. */ rebble_notification *notif = timeline_get_notification(w->uuids + w->curnotif + 1); - if (!notif) { - w->curnotif = (size_t) -1; + if (!notif) + { + w->curnotif = (size_t)-1; return; } single_notification_layer_set_notification(&w->n2, notif); @@ -188,66 +207,72 @@ static void _down_single_click_handler(ClickRecognizerRef _, void *_w) { layer_set_frame(single_notification_layer_get_layer(&w->n2), frame); layer_add_child(window_get_root_layer(w->window), single_notification_layer_get_layer(&w->n2)); - + frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = -curnotif_nudge; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); - - } else { + } + else + { if (w->curnotif_scroll > curnotif_maxscroll) w->curnotif_scroll = curnotif_maxscroll; - + GRect frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = -w->curnotif_scroll; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); } } -static void _up_single_click_handler(ClickRecognizerRef _, void *_w) { +static void _up_single_click_handler(ClickRecognizerRef _, void *_w) +{ NotificationWindow *w = _w; - + int16_t curnotif_maxscroll = w->curnotif_height - VIEWPORT_HEIGHT; if (curnotif_maxscroll < 0) curnotif_maxscroll = 0; - - if (w->curnotif == (size_t) -1) + + if (w->curnotif == (size_t)-1) return; - + w->curnotif_scroll -= SCROLL_INCR; - - if (w->curnotif_nudging) { + + if (w->curnotif_nudging) + { /* Un-nudge. */ w->curnotif_scroll = curnotif_maxscroll; GRect frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = -w->curnotif_scroll; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); - + w->curnotif_nudging = 0; layer_remove_from_parent(single_notification_layer_get_layer(&w->n2)); - - } else if (w->curnotif_scroll == -SCROLL_INCR && w->curnotif > 0) { + } + else if (w->curnotif_scroll == -SCROLL_INCR && w->curnotif > 0) + { /* Kick ourselves to the bottom of the screen, make the previous one * active. Load ourselves first. */ rebble_notification *notif = timeline_get_notification(w->uuids + w->curnotif); - if (!notif) { - w->curnotif = (size_t) -1; + if (!notif) + { + w->curnotif = (size_t)-1; return; } single_notification_layer_set_notification(&w->n2, notif); timeline_destroy(notif); - + GRect frame = layer_get_frame(single_notification_layer_get_layer(&w->n2)); frame.origin.y = VIEWPORT_HEIGHT - NUDGE_HEIGHT; layer_set_frame(single_notification_layer_get_layer(&w->n2), frame); - + layer_add_child(window_get_root_layer(w->window), single_notification_layer_get_layer(&w->n2)); w->curnotif_nudging = 1; - + /* Now load the previous one. */ w->curnotif--; notif = timeline_get_notification(w->uuids + w->curnotif); - if (!notif) { - w->curnotif = (size_t) -1; + if (!notif) + { + w->curnotif = (size_t)-1; return; } single_notification_layer_set_notification(&w->n1, notif); @@ -258,45 +283,59 @@ static void _up_single_click_handler(ClickRecognizerRef _, void *_w) { if (curnotif_maxscroll < 0) curnotif_maxscroll = 0; w->curnotif_scroll = curnotif_maxscroll + NUDGE_HEIGHT; - + frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = -w->curnotif_scroll; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); - - } else { + } + else + { /* Normal scroll. */ if (w->curnotif_scroll < 0) w->curnotif_scroll = 0; - + GRect frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = -w->curnotif_scroll; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); } } -static void _notification_window_click_config_provider(NotificationWindow *w) { +static void _notification_window_click_config_provider(NotificationWindow *w) +{ window_single_repeating_click_subscribe(BUTTON_ID_DOWN, 500, _down_single_click_handler); - window_single_repeating_click_subscribe(BUTTON_ID_UP , 500, _up_single_click_handler ); + window_single_repeating_click_subscribe(BUTTON_ID_UP, 500, _up_single_click_handler); window_set_click_context(BUTTON_ID_DOWN, w); - window_set_click_context(BUTTON_ID_UP , w); - + window_set_click_context(BUTTON_ID_UP, w); + if (w->clickconfig) w->clickconfig(w->clickconfigcontext); } -void notification_window_set_click_config(NotificationWindow *w, ClickConfigProvider config, void *context) { +void notification_window_set_click_config(NotificationWindow *w, ClickConfigProvider config, void *context) +{ w->clickconfig = config; w->clickconfigcontext = context; } -static void _notification_window_load(Window *window) { +static void _notification_window_load(Window *window) +{ NotificationWindow *w = window->user_data; Layer *window_layer = window_get_root_layer(window); - + layer_add_child(window_layer, single_notification_layer_get_layer(&w->n1)); - - window_set_click_config_provider_with_context(window, (ClickConfigProvider) _notification_window_click_config_provider, w); + + _notif_window_status = status_bar_layer_create(); + // By defauld, keep the status bar with these colors. + status_bar_layer_set_colors(_notif_window_status, + GColorWhite /* Get the color of the notification window. Until now, it's just white. w->n1.layer.sibling->window->background_color */, + GColorBlack); + status_bar_layer_set_separator_mode(_notif_window_status, StatusBarLayerSeparatorModeNone); + + layer_add_child(window_layer, status_bar_layer_get_layer(_notif_window_status)); + + window_set_click_config_provider_with_context(window, (ClickConfigProvider)_notification_window_click_config_provider, w); } -static void _notification_window_unload(Window *window) { +static void _notification_window_unload(Window *window) +{ } From 7f4192734479cf1d72b3ad75ee7e883befab9661 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 1 Mar 2021 13:14:46 -0300 Subject: [PATCH 2/2] solve formatting problems --- rwatch/ui/layer/single_notification_layer.c | 174 ++++++++------------ rwatch/ui/notification_window.c | 113 +++++-------- 2 files changed, 110 insertions(+), 177 deletions(-) diff --git a/rwatch/ui/layer/single_notification_layer.c b/rwatch/ui/layer/single_notification_layer.c index 5010d680..771a4ce5 100644 --- a/rwatch/ui/layer/single_notification_layer.c +++ b/rwatch/ui/layer/single_notification_layer.c @@ -26,14 +26,13 @@ static void single_notification_layer_update_proc(Layer *layer, GContext *ctx); #define APPNAME_HEIGHT 28 #define APPNAME_PADDING 8 #define ELEMENT_PADDING 8 -#define APPNAME_FONT FONT_KEY_GOTHIC_24_BOLD -#define TITLE_FONT FONT_KEY_GOTHIC_18_BOLD -#define SUBTITLE_FONT FONT_KEY_GOTHIC_18 -#define BODY_FONT FONT_KEY_GOTHIC_24_BOLD +#define APPNAME_FONT FONT_KEY_GOTHIC_24_BOLD +#define TITLE_FONT FONT_KEY_GOTHIC_18_BOLD +#define SUBTITLE_FONT FONT_KEY_GOTHIC_18 +#define BODY_FONT FONT_KEY_GOTHIC_24_BOLD #define TIMESTAMP_FONT FONT_KEY_GOTHIC_14 -void single_notification_layer_ctor(SingleNotificationLayer *l, GRect frame) -{ +void single_notification_layer_ctor(SingleNotificationLayer *l, GRect frame) { layer_ctor(&l->layer, frame); layer_set_update_proc(&l->layer, single_notification_layer_update_proc); @@ -41,8 +40,7 @@ void single_notification_layer_ctor(SingleNotificationLayer *l, GRect frame) l->icon = NULL; } -void single_notification_layer_dtor(SingleNotificationLayer *l) -{ +void single_notification_layer_dtor(SingleNotificationLayer *l) { free(l->title); free(l->subtitle); free(l->body); @@ -51,8 +49,7 @@ void single_notification_layer_dtor(SingleNotificationLayer *l) layer_dtor(&l->layer); } -extern void single_notification_layer_set_notification(SingleNotificationLayer *l, rebble_notification *notif) -{ +extern void single_notification_layer_set_notification(SingleNotificationLayer *l, rebble_notification *notif) { free(l->title); free(l->subtitle); free(l->body); @@ -66,62 +63,46 @@ extern void single_notification_layer_set_notification(SingleNotificationLayer * rebble_attribute *a; list_foreach(a, ¬if->attributes, rebble_attribute, node) { - switch (a->timeline_attribute.attribute_id) - { - case TimelineAttributeType_Sender: - sender = (const char *)a->data; - break; - case TimelineAttributeType_Subject: - subject = (const char *)a->data; - break; - case TimelineAttributeType_Message: - message = (const char *)a->data; - break; - case TimelineAttributeType_SourceType: - sourcetype = *(uint32_t *)a->data; - break; - default: - /* we don't care */ - ; + switch (a->timeline_attribute.attribute_id) { + case TimelineAttributeType_Sender: sender = (const char *)a->data; break; + case TimelineAttributeType_Subject: subject = (const char *)a->data; break; + case TimelineAttributeType_Message: message = (const char *)a->data; break; + case TimelineAttributeType_SourceType: + sourcetype = *(uint32_t *)a->data; + break; + default: + /* we don't care */ + ; } } - if (sender && strlen(sender)) - { + if (sender && strlen(sender)) { l->title = strdup(sender); if (subject && strlen(subject)) l->subtitle = strdup(subject); l->body = message ? strdup(message) : NULL; - } - else - { + } else { if (subject && strlen(subject)) l->title = strdup(subject); l->body = message ? strdup(message) : NULL; } - switch (sourcetype) - { - // since the 'source' will be useful just to set its respective icon, there's no need - // to hard code the app name using it. 'subject' will be used instead. + // since the 'source' attribute is useful just to set its respective icon, there's no need + // to hard code the app name using it. 'subject' will be used for that instead. + switch (sourcetype) { case TimelineNotificationSource_SMS: - //l->source = "SMS"; l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); break; case TimelineNotificationSource_Email: - //l->source = "Email"; - l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); + l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); // Change to proper Email icon. break; case TimelineNotificationSource_Twitter: - //l->source = "Twitter"; - l->icon = gbitmap_create_with_resource(RESOURCE_ID_UNKNOWN); + l->icon = gbitmap_create_with_resource(RESOURCE_ID_UNKNOWN); // Change to Twitter icon. break; case TimelineNotificationSource_Facebook: - //l->source = "Facebook"; - l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); + l->icon = gbitmap_create_with_resource(RESOURCE_ID_NOTIFICATION); // Change to Facebook icon. break; default: - l->source = NULL; l->icon = gbitmap_create_with_resource(RESOURCE_ID_UNKNOWN); break; } @@ -135,24 +116,17 @@ extern void single_notification_layer_set_notification(SingleNotificationLayer * if (ts > now) l->timestamp = strdup("The future"); - else if (ts > (now - 60 * 60)) - { + else if (ts > (now - 60 * 60)) { sfmt(buf, sizeof(buf), "%d min ago", (ts - now) / 60); l->timestamp = strdup(buf); - } - else if (ts > (now - 24 * 60 * 60)) - { + } else if (ts > (now - 24 * 60 * 60)) { sfmt(buf, sizeof(buf), "%d hours ago", (ts - now) / (60 * 60)); l->timestamp = strdup(buf); - } - else if (ts > (now - 7 * 24 * 60 * 60)) - { + } else if (ts > (now - 7 * 24 * 60 * 60)) { char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; sfmt(buf, sizeof(buf), "%s, %02d:%02d", days[tm_ts.tm_mday], tm_ts.tm_hour, tm_ts.tm_min); l->timestamp = strdup(buf); - } - else - { + } else { char *mons[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; sfmt(buf, sizeof(buf), "%s %d, %02d:%02d", mons[tm_ts.tm_mon], tm_ts.tm_mday, tm_ts.tm_hour, tm_ts.tm_min); l->timestamp = strdup(buf); @@ -161,15 +135,13 @@ extern void single_notification_layer_set_notification(SingleNotificationLayer * layer_mark_dirty(&l->layer); } -Layer *single_notification_layer_get_layer(SingleNotificationLayer *l) -{ +Layer *single_notification_layer_get_layer(SingleNotificationLayer *l) { return &l->layer; } -//#ifdef PBL_RECT +#ifdef PBL_RECT -uint16_t single_notification_layer_height(SingleNotificationLayer *l) -{ +uint16_t single_notification_layer_height(SingleNotificationLayer *l) { uint16_t height = 0; GRect szrect = layer_get_frame(&l->layer); @@ -180,33 +152,28 @@ uint16_t single_notification_layer_height(SingleNotificationLayer *l) height += APPNAME_PADDING; if (l->title) height += n_graphics_text_layout_get_content_size_with_attributes( - l->title, fonts_get_system_font(TITLE_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) - .h + - ELEMENT_PADDING; + l->title, fonts_get_system_font(TITLE_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h + + ELEMENT_PADDING; if (l->subtitle) height += n_graphics_text_layout_get_content_size_with_attributes( - l->subtitle, fonts_get_system_font(SUBTITLE_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) - .h + - ELEMENT_PADDING; + l->subtitle, fonts_get_system_font(SUBTITLE_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h + + ELEMENT_PADDING; if (l->body) height += n_graphics_text_layout_get_content_size_with_attributes( - l->body, fonts_get_system_font(BODY_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) - .h + - ELEMENT_PADDING; + l->body, fonts_get_system_font(BODY_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h + + ELEMENT_PADDING; height += n_graphics_text_layout_get_content_size_with_attributes( - l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0) - .h + - ELEMENT_PADDING; + l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0).h + + ELEMENT_PADDING; return height; } -static void single_notification_layer_update_proc(Layer *layer, GContext *ctx) -{ +static void single_notification_layer_update_proc(Layer *layer, GContext *ctx) { SingleNotificationLayer *l = container_of(layer, SingleNotificationLayer, layer); GRect szrect = layer_get_frame(layer); GSize outsz; @@ -220,12 +187,7 @@ static void single_notification_layer_update_proc(Layer *layer, GContext *ctx) szrect.origin.y = STATUS_BAR_LAYER_HEIGHT; szrect.origin.x += X_PADDING; - szrect.size.w -= X_PADDING * 2; - - /* -from libpebble2.services.notifications import Notifications -Notifications(pebble, None).send_notification(subject = "hello", sender = "How Are you?") - */ + szrect.size.w -= X_PADDING * 2; GRect tmpsz = szrect; tmpsz.size.h = 25; @@ -238,12 +200,11 @@ Notifications(pebble, None).send_notification(subject = "hello", sender = "How A tmpsz.size.w -= APPNAME_HEIGHT + ELEMENT_PADDING; tmpsz.origin.x += APPNAME_HEIGHT; - if (l->title) - { + if (l->title) { graphics_draw_text(ctx, l->title, fonts_get_system_font(APPNAME_FONT), - tmpsz, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0); + tmpsz, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0); szrect.origin.y += APPNAME_HEIGHT; - szrect.size.h -= APPNAME_HEIGHT; + szrect.size.h -= APPNAME_HEIGHT; } graphics_context_set_stroke_color(ctx, GColorBlack); @@ -251,34 +212,31 @@ Notifications(pebble, None).send_notification(subject = "hello", sender = "How A /* XXX: make this a drawrect */ graphics_draw_line(ctx, - GPoint(szrect.origin.x, szrect.origin.y), - GPoint(szrect.origin.x + szrect.size.w, szrect.origin.y)); + GPoint(szrect.origin.x, szrect.origin.y), + GPoint(szrect.origin.x + szrect.size.w, szrect.origin.y)); szrect.origin.y += 0; - szrect.size.h -= APPNAME_PADDING; + szrect.size.h -= APPNAME_PADDING; - if (l->subtitle) - { + if (l->subtitle) { graphics_draw_text_ex(ctx, - l->subtitle, fonts_get_system_font(SUBTITLE_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); + l->subtitle, fonts_get_system_font(SUBTITLE_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); szrect.origin.y += outsz.h; - szrect.size.h -= outsz.h; - } - if (l->body) - { + szrect.size.h -= outsz.h; + } if (l->body) { graphics_draw_text_ex(ctx, - l->body, fonts_get_system_font(BODY_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); + l->body, fonts_get_system_font(BODY_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); szrect.origin.y += outsz.h + ELEMENT_PADDING; - szrect.size.h -= outsz.h + ELEMENT_PADDING; + szrect.size.h -= outsz.h + ELEMENT_PADDING; } graphics_draw_text_ex(ctx, - l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), - szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); + l->timestamp, fonts_get_system_font(TIMESTAMP_FONT), + szrect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, 0, &outsz); szrect.origin.y += outsz.h + ELEMENT_PADDING; - szrect.size.h -= outsz.h + ELEMENT_PADDING; + szrect.size.h -= outsz.h + ELEMENT_PADDING; } -//#else /* !PBL_RECT */ -//#error single_notification_layer not implemented on non-rectangular Pebbles -//#endif +#else !PBL_RECT +# error single_notification_layer not implemented on non-rectangular Pebbles +#endif diff --git a/rwatch/ui/notification_window.c b/rwatch/ui/notification_window.c index cce628e4..a7cd78d8 100644 --- a/rwatch/ui/notification_window.c +++ b/rwatch/ui/notification_window.c @@ -17,15 +17,14 @@ static void _notification_window_unload(Window *window); static StatusBarLayer *_notif_window_status; #ifndef PBL_RECT -#error notification_window not implemented on round Pebble +# error notification_window not implemented on round Pebble #endif #define VIEWPORT_HEIGHT DISPLAY_ROWS #define NUDGE_HEIGHT 40 #define SCROLL_INCR 20 -void notification_window_ctor(NotificationWindow *w, Window *win) -{ +void notification_window_ctor(NotificationWindow *w, Window *win) { w->window = win; win->user_data = w; /* we use this because the noty / overlay subsystem uses context */ @@ -38,32 +37,30 @@ void notification_window_ctor(NotificationWindow *w, Window *win) w->uuids = NULL; w->nuuids = 0; - w->curnotif = (size_t)-1; + w->curnotif = (size_t) -1; w->curnotif_nudging = 0; single_notification_layer_ctor(&w->n1, frame); single_notification_layer_ctor(&w->n2, frame); window_set_window_handlers(w->window, (WindowHandlers){ - .load = _notification_window_load, - .unload = _notification_window_unload}); + .load = _notification_window_load, + .unload = _notification_window_unload + }); } -void notification_window_dtor(NotificationWindow *w) -{ +void notification_window_dtor(NotificationWindow *w) { single_notification_layer_dtor(&w->n1); single_notification_layer_dtor(&w->n2); } -void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, size_t count, size_t curnotif) -{ +void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, size_t count, size_t curnotif) { void *newuuids = realloc(w->uuids, count * sizeof(Uuid)); - if (!newuuids) - { + if (!newuuids) { free(w->uuids); w->nuuids = 0; w->uuids = NULL; - w->curnotif = (size_t)-1; + w->curnotif = (size_t) -1; return; } w->uuids = newuuids; @@ -71,9 +68,9 @@ void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, s memcpy(w->uuids, uuids, count * sizeof(Uuid)); w->nuuids = count; - if (curnotif >= count) - { - w->curnotif = (size_t)-1; + if (curnotif >= count) { + w->curnotif = (size_t) -1; + return; } @@ -90,9 +87,9 @@ void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, s w->curnotif = curnotif; rebble_notification *notif = timeline_get_notification(w->uuids + curnotif); - if (!notif) - { + if (!notif) { w->curnotif = (size_t)-1; + return; } single_notification_layer_set_notification(&w->n1, notif); @@ -101,8 +98,7 @@ void notification_window_set_notifications(NotificationWindow *w, Uuid *uuids, s w->curnotif_height = single_notification_layer_height(&w->n1); } -void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) -{ +void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) { #if 0 void *newuuids = realloc(w->uuids, (w->nuuids + 1) * sizeof(Uuid)); if (!newuuids) @@ -120,8 +116,7 @@ void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) *w->uuids = *uuid; w->nuuids++; - if (w->curnotif || w->curnotif_scroll) - { + if (w->curnotif || w->curnotif_scroll) { w->curnotif++; return; } @@ -129,9 +124,9 @@ void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) /* We're the top notification and haven't scrolled, so we reset the * notification to view the new one. */ rebble_notification *notif = timeline_get_notification(w->uuids); - if (!notif) - { - w->curnotif = (size_t)-1; + if (!notif) { + w->curnotif = (size_t) -1; + return; } single_notification_layer_set_notification(&w->n1, notif); @@ -140,13 +135,11 @@ void notification_window_push_to_top(NotificationWindow *w, Uuid *uuid) w->curnotif_height = single_notification_layer_height(&w->n1); } -Window *notification_window_get_window(NotificationWindow *w) -{ +Window *notification_window_get_window(NotificationWindow *w) { return w->window; } -static void _down_single_click_handler(ClickRecognizerRef _, void *_w) -{ +static void _down_single_click_handler(ClickRecognizerRef _, void *_w) { NotificationWindow *w = _w; w->curnotif_scroll += SCROLL_INCR; @@ -158,8 +151,7 @@ static void _down_single_click_handler(ClickRecognizerRef _, void *_w) if (curnotif_maxscroll < 0) curnotif_maxscroll = 0; int16_t curnotif_nudge = curnotif_maxscroll + NUDGE_HEIGHT; - if (w->curnotif_nudging) - { + if (w->curnotif_nudging) { /* We are nudging and moving still scrolling down -- swap the * notifications to the next. We can only be nudging if there is a * next notification, so we're good on that front. */ @@ -168,9 +160,8 @@ static void _down_single_click_handler(ClickRecognizerRef _, void *_w) w->curnotif_nudging = 0; rebble_notification *notif = timeline_get_notification(w->uuids + w->curnotif); - if (!notif) - { - w->curnotif = (size_t)-1; + if (!notif) { + w->curnotif = (size_t) -1; return; } single_notification_layer_set_notification(&w->n1, notif); @@ -183,9 +174,7 @@ static void _down_single_click_handler(ClickRecognizerRef _, void *_w) layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); w->curnotif_height = single_notification_layer_height(&w->n1); - } - else if ((w->curnotif_scroll > curnotif_maxscroll) && !w->curnotif_nudging && ((w->curnotif + 1) < w->nuuids)) - { + } else if ((w->curnotif_scroll > curnotif_maxscroll) && !w->curnotif_nudging && ((w->curnotif + 1) < w->nuuids)) { /* We're moving down and about to run out, and there's another * notification ready. Load it into the nudge box at the bottom. */ @@ -194,9 +183,8 @@ static void _down_single_click_handler(ClickRecognizerRef _, void *_w) /* Load the next one in place. */ rebble_notification *notif = timeline_get_notification(w->uuids + w->curnotif + 1); - if (!notif) - { - w->curnotif = (size_t)-1; + if (!notif) { + w->curnotif = (size_t) -1; return; } single_notification_layer_set_notification(&w->n2, notif); @@ -211,9 +199,7 @@ static void _down_single_click_handler(ClickRecognizerRef _, void *_w) frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = -curnotif_nudge; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); - } - else - { + } else { if (w->curnotif_scroll > curnotif_maxscroll) w->curnotif_scroll = curnotif_maxscroll; @@ -223,21 +209,19 @@ static void _down_single_click_handler(ClickRecognizerRef _, void *_w) } } -static void _up_single_click_handler(ClickRecognizerRef _, void *_w) -{ +static void _up_single_click_handler(ClickRecognizerRef _, void *_w) { NotificationWindow *w = _w; int16_t curnotif_maxscroll = w->curnotif_height - VIEWPORT_HEIGHT; if (curnotif_maxscroll < 0) curnotif_maxscroll = 0; - if (w->curnotif == (size_t)-1) + if (w->curnotif == (size_t) -1) return; w->curnotif_scroll -= SCROLL_INCR; - if (w->curnotif_nudging) - { + if (w->curnotif_nudging) { /* Un-nudge. */ w->curnotif_scroll = curnotif_maxscroll; GRect frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); @@ -246,15 +230,12 @@ static void _up_single_click_handler(ClickRecognizerRef _, void *_w) w->curnotif_nudging = 0; layer_remove_from_parent(single_notification_layer_get_layer(&w->n2)); - } - else if (w->curnotif_scroll == -SCROLL_INCR && w->curnotif > 0) - { + } else if (w->curnotif_scroll == -SCROLL_INCR && w->curnotif > 0) { /* Kick ourselves to the bottom of the screen, make the previous one * active. Load ourselves first. */ rebble_notification *notif = timeline_get_notification(w->uuids + w->curnotif); - if (!notif) - { - w->curnotif = (size_t)-1; + if (!notif) { + w->curnotif = (size_t) -1; return; } single_notification_layer_set_notification(&w->n2, notif); @@ -270,8 +251,7 @@ static void _up_single_click_handler(ClickRecognizerRef _, void *_w) /* Now load the previous one. */ w->curnotif--; notif = timeline_get_notification(w->uuids + w->curnotif); - if (!notif) - { + if (!notif) { w->curnotif = (size_t)-1; return; } @@ -287,9 +267,7 @@ static void _up_single_click_handler(ClickRecognizerRef _, void *_w) frame = layer_get_frame(single_notification_layer_get_layer(&w->n1)); frame.origin.y = -w->curnotif_scroll; layer_set_frame(single_notification_layer_get_layer(&w->n1), frame); - } - else - { + } else { /* Normal scroll. */ if (w->curnotif_scroll < 0) w->curnotif_scroll = 0; @@ -300,8 +278,7 @@ static void _up_single_click_handler(ClickRecognizerRef _, void *_w) } } -static void _notification_window_click_config_provider(NotificationWindow *w) -{ +static void _notification_window_click_config_provider(NotificationWindow *w) { window_single_repeating_click_subscribe(BUTTON_ID_DOWN, 500, _down_single_click_handler); window_single_repeating_click_subscribe(BUTTON_ID_UP, 500, _up_single_click_handler); window_set_click_context(BUTTON_ID_DOWN, w); @@ -311,14 +288,12 @@ static void _notification_window_click_config_provider(NotificationWindow *w) w->clickconfig(w->clickconfigcontext); } -void notification_window_set_click_config(NotificationWindow *w, ClickConfigProvider config, void *context) -{ +void notification_window_set_click_config(NotificationWindow *w, ClickConfigProvider config, void *context) { w->clickconfig = config; w->clickconfigcontext = context; } -static void _notification_window_load(Window *window) -{ +static void _notification_window_load(Window *window) { NotificationWindow *w = window->user_data; Layer *window_layer = window_get_root_layer(window); @@ -327,8 +302,8 @@ static void _notification_window_load(Window *window) _notif_window_status = status_bar_layer_create(); // By defauld, keep the status bar with these colors. status_bar_layer_set_colors(_notif_window_status, - GColorWhite /* Get the color of the notification window. Until now, it's just white. w->n1.layer.sibling->window->background_color */, - GColorBlack); + GColorWhite, /* Get the color of the notification window. Until now, it's just white. w->n1.layer.sibling->window->background_color */ + GColorBlack); status_bar_layer_set_separator_mode(_notif_window_status, StatusBarLayerSeparatorModeNone); layer_add_child(window_layer, status_bar_layer_get_layer(_notif_window_status)); @@ -336,6 +311,6 @@ static void _notification_window_load(Window *window) window_set_click_config_provider_with_context(window, (ClickConfigProvider)_notification_window_click_config_provider, w); } -static void _notification_window_unload(Window *window) -{ +static void _notification_window_unload(Window *window) { + }