Skip to content

Commit

Permalink
Make notifications list an application.
Browse files Browse the repository at this point in the history
No dedicated button to show notification, instead swipe left to right on watchface.
  • Loading branch information
jakkra committed Jul 29, 2023
1 parent 680b35c commit 13c65f4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 67 deletions.
2 changes: 2 additions & 0 deletions app/src/applications/notification/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FILE(GLOB app_sources *.c)
target_sources(app PRIVATE ${app_sources})
47 changes: 47 additions & 0 deletions app/src/applications/notification/notification_app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <notification/notification_ui.h>
#include <application_manager.h>
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <notification_manager.h>

// Functions needed for all applications
static void notification_app_start(lv_obj_t *root, lv_group_t *group);
static void notification_app_stop(void);

static application_t app = {
.name = "Notification",
.hidden = true,
.start_func = notification_app_start,
.stop_func = notification_app_stop
};

static void on_notification_page_notification_close(uint32_t not_id)
{
// TODO send to phone that the notification was read.
notification_manager_remove(not_id);
}


static void notification_app_start(lv_obj_t *root, lv_group_t *group)
{
int num_unread;
not_mngr_notification_t notifications[NOTIFICATION_MANAGER_MAX_STORED];

notification_manager_get_all(notifications, &num_unread);
notifications_page_init(on_notification_page_notification_close);
notifications_page_create(notifications, num_unread, group);
}

static void notification_app_stop(void)
{
notifications_page_close();
}

static int notification_app_add(void)
{
application_manager_add_application(&app);

return 0;
}

SYS_INIT(notification_app_add, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#include <notifications_page.h>
#include <notification/notification_ui.h>
#include <lvgl.h>

static void close_button_pressed(lv_event_t *e);
static void not_button_pressed(lv_event_t *e);
static void scroll_event_cb(lv_event_t *e);
static void build_notification_entry(lv_obj_t *parent, not_mngr_notification_t *not, lv_group_t *input_group);

static on_notification_page_closed_cb_t closed_callback;
static on_notification_remove_cb_t not_removed_callback;

static lv_obj_t *main_page;
static lv_group_t *group;

void notifications_page_init(on_notification_page_closed_cb_t closed_cb, on_notification_remove_cb_t not_removed_cb)
void notifications_page_init(on_notification_remove_cb_t not_removed_cb)
{
closed_callback = closed_cb;
not_removed_callback = not_removed_cb;
}

Expand All @@ -40,17 +37,6 @@ void notifications_page_create(not_mngr_notification_t *notifications, uint8_t n
build_notification_entry(main_page, &notifications[i], input_group);
}

lv_obj_t *float_btn = lv_btn_create(main_page);
lv_obj_set_size(float_btn, 50, 50);
lv_obj_add_flag(float_btn, LV_OBJ_FLAG_FLOATING);
lv_obj_align(float_btn, LV_ALIGN_BOTTOM_RIGHT, 0, -lv_obj_get_style_pad_right(main_page, LV_PART_MAIN));
lv_obj_add_event_cb(float_btn, close_button_pressed, LV_EVENT_PRESSED, main_page);
lv_obj_set_style_radius(float_btn, LV_RADIUS_CIRCLE, 0);
lv_obj_set_style_bg_img_src(float_btn, LV_SYMBOL_CLOSE, 0);
lv_obj_set_style_text_font(float_btn, lv_theme_get_font_large(float_btn), 0);

lv_group_focus_obj(float_btn);

/* Update the notifications position manually firt time */
lv_event_send(main_page, LV_EVENT_SCROLL, NULL);

Expand Down Expand Up @@ -112,12 +98,6 @@ static void not_button_pressed(lv_event_t *e)
not_removed_callback((uint32_t)lv_event_get_user_data(e));
}

static void close_button_pressed(lv_event_t *e)
{
lv_obj_del(main_page);
closed_callback();
}

static void scroll_event_cb(lv_event_t *e)
{
lv_obj_t *cont = lv_event_get_target(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#ifndef __NOTIFICATIONS_PAGE_H
#define __NOTIFICATIONS_PAGE_H
#ifndef __NOTIFICATION_UI_H
#define __NOTIFICATION_UI_H

#include <inttypes.h>
#include <notification_manager.h>
#include <lvgl.h>

typedef void(*on_notification_page_closed_cb_t)(void);
typedef void(*on_notification_remove_cb_t)(uint32_t id);

void notifications_page_init(on_notification_page_closed_cb_t closed_cb, on_notification_remove_cb_t not_removed_cb);
void notifications_page_init(on_notification_remove_cb_t not_removed_cb);

void notifications_page_create(not_mngr_notification_t *notifications, uint8_t num_notifications,
lv_group_t *input_group);

void notifications_page_close(void);
#endif // __NOTIFICATIONS_PAGE_H
#endif // __NOTIFICATION_UI_H
43 changes: 3 additions & 40 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <ble_aoa.h>
#include <lv_notifcation.h>
#include <notification_manager.h>
#include <notifications_page.h>
#include <vibration_motor.h>
#include <display_control.h>
#include <applications/application_manager.h>
Expand Down Expand Up @@ -60,7 +59,6 @@ static void run_init_work(struct k_work *item);

static void run_wdt_work(struct k_work *item);
static void enable_bluetoth(void);
static void open_notifications_page(void *unused);
static bool load_retention_ram(void);
static void enocoder_read(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
static void click_feedback(struct _lv_indev_drv_t *drv, uint8_t e);
Expand All @@ -69,8 +67,6 @@ static void ble_data_cb(ble_comm_cb_data_t *cb);
static void open_notification_popup(void *data);
static void async_turn_off_buttons_allocation(void *unused);
static void on_popup_notifcation_closed(uint32_t id);
static void on_notification_page_close(void);
static void on_notification_page_notification_close(uint32_t not_id);
static void zbus_ble_comm_data_callback(const struct zbus_channel *chan);

static void onButtonPressCb(buttonPressType_t type, buttonId_t id);
Expand Down Expand Up @@ -102,7 +98,6 @@ static void run_init_work(struct k_work *item)

load_retention_ram();
heart_rate_sensor_init();
notifications_page_init(on_notification_page_close, on_notification_page_notification_close);
notification_manager_init();
enable_bluetoth();
zsw_imu_init();
Expand Down Expand Up @@ -234,17 +229,6 @@ static void open_notification_popup(void *data)
}
}

static void open_notifications_page(void *unused)
{
not_mngr_notification_t notifications[NOTIFICATION_MANAGER_MAX_STORED];
int num_unread = 0;
watchface_app_stop();
buttons_allocated = true;
watch_state = NOTIFCATION_LIST_STATE;
notification_manager_get_all(notifications, &num_unread);
notifications_page_create(notifications, num_unread, input_group);
}

static void open_application_manager_page(void *unused)
{
watchface_app_stop();
Expand Down Expand Up @@ -292,19 +276,6 @@ static void on_popup_notifcation_closed(uint32_t id)
lv_async_call(async_turn_off_buttons_allocation, NULL);
}

static void on_notification_page_close(void)
{
lv_async_call(async_turn_off_buttons_allocation, NULL);
watch_state = WATCHFACE_STATE;
watchface_app_start(input_group);
}

static void on_notification_page_notification_close(uint32_t not_id)
{
// TODO send to phone that the notification was read.
notification_manager_remove(not_id);
}

static void on_close_application_manager(void)
{
application_manager_delete();
Expand Down Expand Up @@ -354,9 +325,6 @@ static void onButtonPressCb(buttonPressType_t type, buttonId_t id)
if (id == BUTTON_TOP_LEFT) {
LOG_DBG("Close Watchface, open App Manager");
lv_async_call(open_application_manager_page, NULL);
} else if (id == BUTTON_BOTTOM_RIGHT) {
LOG_DBG("CloseWatchface, open Notifications page");
lv_async_call(open_notifications_page, NULL);
} else {
LOG_WRN("Unhandled button %d, type: %d, watch_state: %d", id, type, watch_state);
}
Expand Down Expand Up @@ -430,13 +398,13 @@ static void screen_gesture_event(lv_event_t *e)
application_manager_show(on_close_application_manager, lv_scr_act(), input_group, NULL);
break;
case LV_DIR_TOP:
application_manager_show(on_close_application_manager, lv_scr_act(), input_group, "Music");
application_manager_show(on_close_application_manager, lv_scr_act(), input_group, "Settings");
break;
case LV_DIR_RIGHT:
application_manager_show(on_close_application_manager, lv_scr_act(), input_group, "QR Code");
application_manager_show(on_close_application_manager, lv_scr_act(), input_group, "Music");
break;
case LV_DIR_LEFT:
application_manager_show(on_close_application_manager, lv_scr_act(), input_group, "Sensors");
application_manager_show(on_close_application_manager, lv_scr_act(), input_group, "Notification");
break;
default:
break;
Expand Down Expand Up @@ -515,11 +483,6 @@ static void zbus_ble_comm_data_callback(const struct zbus_channel *chan)
buttons_allocated = false;
watch_state = WATCHFACE_STATE;
watchface_app_start(input_group);
} else if (watch_state == NOTIFCATION_STATE) {
notifications_page_close();
buttons_allocated = false;
watch_state = WATCHFACE_STATE;
watchface_app_start(input_group);
}
} else {
button_set_fake_press((buttonId_t)event->data.data.remote_control.button, true);
Expand Down

0 comments on commit 13c65f4

Please sign in to comment.