Added new functions to the API, work is almost done for the popup part of the notification, still need to design the notification history app

This commit is contained in:
Th3maz1ng 2023-10-22 08:57:23 +02:00
parent 5b74ae2676
commit 77a87d401e
3 changed files with 99 additions and 11 deletions

View File

@ -7,11 +7,13 @@
bool _notification_list_is_empty(NotificationDataList_t notificationList);
void _notification_list_add_head(NotificationDataList_t *notificationList, NotificationData_t *notification);
NotificationData_t *_notification_list_remove_tail(NotificationDataList_t *notificationList);
NotificationData_t *_notification_list_remove_by_handle(NotificationDataList_t *notificationList, uint32_t handle);
uint8_t _notification_list_count(NotificationDataList_t notificationList);
uint8_t _notification_list_unread_count(NotificationDataList_t notificationList);
void _notification_list_debug(NotificationDataList_t notificationList);
/* Internal UI API */
void _display_message_notification(NotificationScreen_t * const notificationScreen, const NotificationData_t *notification);
void _display_message_notification(NotificationScreen_t * const notificationScreen, NotificationData_t *notification);
void _notification_popup_destroy(NotificationScreen_t * const notificationScreen);
const char *_notification_type_to_char(NotificationType_e notificationType);
const char *_notification_timestamp_to_date(time_t timestamp);
@ -19,6 +21,7 @@ const char *_notification_timestamp_to_date(time_t timestamp);
static void notification_scrolled_event_cb(lv_event_t *e)
{
NotificationScreen_t *notificationScreen = lv_event_get_user_data(e);
NotificationData_t *notification = lv_obj_get_user_data(lv_event_get_target(e));
//If we didn't scroll down enough, make the notif pop again
if(lv_obj_get_scroll_y(e->target) >= 83)
{
@ -33,6 +36,8 @@ static void notification_scrolled_event_cb(lv_event_t *e)
{
LV_LOG_USER("Notification closed");
_notification_popup_destroy(notificationScreen);
notificationScreen->new_notification_available = false;
notification->read = true;
if(notificationScreen->notificationOnStateChangeCb) notificationScreen->notificationOnStateChangeCb(NOTIFICATION_STATE_CLEARED);
}
}
@ -97,17 +102,44 @@ void notification_screen_notify(NotificationScreen_t * const notificationScreen,
notification->read = false;
_notification_list_add_head(&notificationScreen->notificationList, notification);
notificationScreen->new_notification_available = true;
switch(notificationType)
{
case NOTIFICATION_TYPE_CALL:
break;
default:
_display_message_notification(notificationScreen, notification);
if(notificationScreen->notificationOnStateChangeCb) notificationScreen->notificationOnStateChangeCb(NOTIFICATION_STATE_DISPLAYED);
_display_message_notification(notificationScreen, notification);
}
}
bool notification_screen_new_notification_available(NotificationScreen_t * const notificationScreen)
{
if(!notificationScreen)
{
LV_LOG_ERROR("NULL pointer given !");
return false;
}
if(notificationScreen->new_notification_available)
{
notificationScreen->new_notification_available = false;
return true;
}
return false;
}
uint8_t notification_screen_notification_count(NotificationScreen_t * const notificationScreen)
{
return _notification_list_count(notificationScreen->notificationList);
}
uint8_t notification_screen_unread_notification_count(NotificationScreen_t * const notificationScreen)
{
return _notification_list_unread_count(notificationScreen->notificationList);;
}
void notification_screen_destroy(NotificationScreen_t * const notificationScreen)
{
if(!notificationScreen)
@ -162,6 +194,39 @@ NotificationData_t *_notification_list_remove_tail(NotificationDataList_t *notif
return toReturn;
}
NotificationData_t *_notification_list_remove_by_handle(NotificationDataList_t *notificationList, uint32_t handle)
{
if(!notificationList) return NULL;
if(_notification_list_is_empty(*notificationList)) return NULL;
NotificationData_t *toReturn = NULL;
//There is only one item in the list
if((*notificationList)->next == NULL)
{
if((*notificationList)->handle == handle)
{
toReturn = *notificationList;
*notificationList = NULL;
}
return toReturn;
}
NotificationDataList_t cursor = *notificationList;
while(!_notification_list_is_empty(cursor->next))
{
if(cursor->next->handle == handle)
{
toReturn = cursor->next;
cursor->next = NULL;
return toReturn;
}
cursor = cursor->next;
}
return toReturn;
}
uint8_t _notification_list_count(NotificationDataList_t notificationList)
{
uint8_t count = 0;
@ -174,7 +239,19 @@ uint8_t _notification_list_count(NotificationDataList_t notificationList)
return count;
}
void _display_message_notification(NotificationScreen_t * const notificationScreen, const NotificationData_t *notification)
uint8_t _notification_list_unread_count(NotificationDataList_t notificationList)
{
uint8_t count = 0;
while(!_notification_list_is_empty(notificationList))
{
if(!notificationList->read)count++;
notificationList = notificationList->next;
}
return count;
}
void _display_message_notification(NotificationScreen_t * const notificationScreen, NotificationData_t *notification)
{
//Create and display a graphical widget containing the notification
lv_obj_t *notification_display = lv_layer_top();
@ -190,6 +267,8 @@ void _display_message_notification(NotificationScreen_t * const notificationScre
2) A notification is currently being shown and all UI elements were already created / allocated
*/
lv_obj_set_user_data(notification_display, notification);
if(lv_obj_get_child_cnt(notification_display) == 0)
{
//Only allow to scroll down and not up (LV_DIR_TOP makes it, is it a bug ?)
@ -288,6 +367,7 @@ void _display_message_notification(NotificationScreen_t * const notificationScre
void _notification_popup_destroy(NotificationScreen_t * const notificationScreen)
{
lv_obj_clean(lv_layer_top());
lv_obj_remove_event_cb_with_user_data(lv_layer_top(), &(notification_scrolled_event_cb), notificationScreen);
notificationScreen->type_label = NULL;
notificationScreen->title_label = NULL;
notificationScreen->date_label = NULL;

View File

@ -16,7 +16,7 @@ typedef enum NotificationType
NOTIFICATION_TYPE_WHATSAPP,
NOTIFICATION_TYPE_GADGET_BRIDGE,
NOTIFICATION_TYPE_UNKNOWN,
/* This enum value has no match in GadgetBridge's enum */
// This enum value has no match in GadgetBridge's enum
NOTIFICATION_TYPE_CALL,
} NotificationType_e;
@ -42,20 +42,22 @@ typedef void (*NotificationOnStateChangeCb_t)(NotificationState_e notificationSt
typedef struct NotificationScreen
{
//Can be erased attributes
// Can be erased attributes
lv_obj_t *display;
//Should not be erased attributes
//Notification UI object
// Should not be erased attributes
// Notification UI object
lv_obj_t *type_label;
lv_obj_t *title_label;
lv_obj_t *date_label;
lv_obj_t *body_label;
NotificationOnStateChangeCb_t notificationOnStateChangeCb;
//Notification history data structure
// Notification history data structure
NotificationData_t notificationPool[MAX_NOTIFICATIONS_COUNT];
NotificationDataList_t notificationList; //Actual notifications
NotificationDataList_t freeNotificationList; //Free notification object pool
NotificationDataList_t notificationList; // Actual notifications
NotificationDataList_t freeNotificationList; // Free notification object pool
// Miscellaneous
bool new_notification_available;
} NotificationScreen_t;
void notification_screen_init(NotificationScreen_t * const notificationScreen);
@ -64,6 +66,12 @@ void notification_screen_register_on_state_change_cb(NotificationScreen_t * cons
void notification_screen_notify(NotificationScreen_t * const notificationScreen, uint32_t handle, time_t dateOfArrival, NotificationType_e notificationType, char * title, char * body);
bool notification_screen_new_notification_available(NotificationScreen_t * const notificationScreen);
uint8_t notification_screen_notification_count(NotificationScreen_t * const notificationScreen);
uint8_t notification_screen_unread_notification_count(NotificationScreen_t * const notificationScreen);
void notification_screen_create(NotificationScreen_t * const notificationScreen);
void notification_screen_destroy(NotificationScreen_t * const notificationScreen);

View File

@ -108,8 +108,8 @@ void notification_screen_notify(NotificationScreen_t * const notificationScreen,
case NOTIFICATION_TYPE_CALL:
break;
default:
_display_message_notification(notificationScreen, notification);
if(notificationScreen->notificationOnStateChangeCb) notificationScreen->notificationOnStateChangeCb(NOTIFICATION_STATE_DISPLAYED);
_display_message_notification(notificationScreen, notification);
}
}