Merge branch 'notification-title' into develop
This commit is contained in:
commit
4560e9ed60
7 changed files with 47 additions and 18 deletions
|
@ -158,13 +158,17 @@ void AlertNotificationClient::OnNotification(ble_gap_event *event) {
|
||||||
const auto maxMessageSize{NotificationManager::MaximumMessageSize()};
|
const auto maxMessageSize{NotificationManager::MaximumMessageSize()};
|
||||||
const auto maxBufferSize{maxMessageSize + headerSize};
|
const auto maxBufferSize{maxMessageSize + headerSize};
|
||||||
|
|
||||||
const auto dbgPacketLen = OS_MBUF_PKTLEN(event->notify_rx.om);
|
// Ignore notifications with empty message
|
||||||
size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
|
const auto packetLen = OS_MBUF_PKTLEN(event->notify_rx.om);
|
||||||
|
if(packetLen <= headerSize) return;
|
||||||
|
|
||||||
|
size_t bufferSize = std::min(packetLen + stringTerminatorSize, maxBufferSize);
|
||||||
auto messageSize = std::min(maxMessageSize, (bufferSize - headerSize));
|
auto messageSize = std::min(maxMessageSize, (bufferSize - headerSize));
|
||||||
|
|
||||||
NotificationManager::Notification notif;
|
NotificationManager::Notification notif;
|
||||||
os_mbuf_copydata(event->notify_rx.om, headerSize, messageSize - 1, notif.message.data());
|
os_mbuf_copydata(event->notify_rx.om, headerSize, messageSize - 1, notif.message.data());
|
||||||
notif.message[messageSize - 1] = '\0';
|
notif.message[messageSize - 1] = '\0';
|
||||||
|
notif.size = messageSize;
|
||||||
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
|
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
|
||||||
notificationManager.Push(std::move(notif));
|
notificationManager.Push(std::move(notif));
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,11 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
|
||||||
const auto maxMessageSize {NotificationManager::MaximumMessageSize()};
|
const auto maxMessageSize {NotificationManager::MaximumMessageSize()};
|
||||||
const auto maxBufferSize{maxMessageSize + headerSize};
|
const auto maxBufferSize{maxMessageSize + headerSize};
|
||||||
|
|
||||||
const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om);
|
// Ignore notifications with empty message
|
||||||
size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
|
const auto packetLen = OS_MBUF_PKTLEN(ctxt->om);
|
||||||
|
if(packetLen <= headerSize) return 0;
|
||||||
|
|
||||||
|
size_t bufferSize = std::min(packetLen + stringTerminatorSize, maxBufferSize);
|
||||||
auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize));
|
auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize));
|
||||||
Categories category;
|
Categories category;
|
||||||
|
|
||||||
|
@ -75,6 +78,7 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
|
||||||
os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data());
|
os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data());
|
||||||
os_mbuf_copydata(ctxt->om, 0, 1, &category);
|
os_mbuf_copydata(ctxt->om, 0, 1, &category);
|
||||||
notif.message[messageSize-1] = '\0';
|
notif.message[messageSize-1] = '\0';
|
||||||
|
notif.size = messageSize;
|
||||||
|
|
||||||
// TODO convert all ANS categories to NotificationController categories
|
// TODO convert all ANS categories to NotificationController categories
|
||||||
switch(category) {
|
switch(category) {
|
||||||
|
|
|
@ -191,7 +191,6 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_
|
||||||
data[notifSize] = '\0';
|
data[notifSize] = '\0';
|
||||||
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
||||||
char *s = (char *) &data[0];
|
char *s = (char *) &data[0];
|
||||||
NRF_LOG_INFO("DATA : %s", s);
|
|
||||||
if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msArtistCharUuid) == 0) {
|
if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msArtistCharUuid) == 0) {
|
||||||
artistName = s;
|
artistName = s;
|
||||||
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msTrackCharUuid) == 0) {
|
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &msTrackCharUuid) == 0) {
|
||||||
|
|
|
@ -101,7 +101,6 @@ int Pinetime::Controllers::NavigationService::OnCommand(uint16_t conn_handle, ui
|
||||||
data[notifSize] = '\0';
|
data[notifSize] = '\0';
|
||||||
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
||||||
char *s = (char *) &data[0];
|
char *s = (char *) &data[0];
|
||||||
NRF_LOG_INFO("DATA : %s", s);
|
|
||||||
if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navFlagCharUuid) == 0) {
|
if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navFlagCharUuid) == 0) {
|
||||||
m_flag = s;
|
m_flag = s;
|
||||||
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navNarrativeCharUuid) == 0) {
|
} else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *) &navNarrativeCharUuid) == 0) {
|
||||||
|
|
|
@ -87,3 +87,19 @@ size_t NotificationManager::NbNotifications() const {
|
||||||
return std::count_if(notifications.begin(), notifications.end(), [](const Notification& n){ return n.valid;});
|
return std::count_if(notifications.begin(), notifications.end(), [](const Notification& n){ return n.valid;});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* NotificationManager::Notification::Message() const {
|
||||||
|
const char* itField = std::find(message.begin(), message.begin()+size-1, '\0');
|
||||||
|
if(itField != message.begin()+size-1) {
|
||||||
|
const char* ptr = (itField)+1;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
return const_cast<char*>(message.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* NotificationManager::Notification::Title() const {
|
||||||
|
const char * itField = std::find(message.begin(), message.begin()+size-1, '\0');
|
||||||
|
if(itField != message.begin()+size-1) {
|
||||||
|
return message.data();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
|
@ -17,8 +17,12 @@ namespace Pinetime {
|
||||||
Id id;
|
Id id;
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
uint8_t size;
|
||||||
std::array<char, MessageSize+1> message;
|
std::array<char, MessageSize+1> message;
|
||||||
Categories category = Categories::Unknown;
|
Categories category = Categories::Unknown;
|
||||||
|
|
||||||
|
const char* Message() const;
|
||||||
|
const char* Title() const;
|
||||||
};
|
};
|
||||||
Notification::Id nextId {0};
|
Notification::Id nextId {0};
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ Notifications::Notifications(DisplayApp *app,
|
||||||
auto notification = notificationManager.GetLastNotification();
|
auto notification = notificationManager.GetLastNotification();
|
||||||
if(notification.valid) {
|
if(notification.valid) {
|
||||||
currentId = notification.id;
|
currentId = notification.id;
|
||||||
currentItem = std::make_unique<NotificationItem>("\nNotification",
|
currentItem = std::make_unique<NotificationItem>(notification.Title(),
|
||||||
notification.message.data(),
|
notification.Message(),
|
||||||
notification.index,
|
notification.index,
|
||||||
notification.category,
|
notification.category,
|
||||||
notificationManager.NbNotifications(),
|
notificationManager.NbNotifications(),
|
||||||
|
@ -68,6 +68,8 @@ bool Notifications::Refresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||||
|
if(mode != Modes::Normal) return true;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case Pinetime::Applications::TouchEvents::SwipeDown: {
|
case Pinetime::Applications::TouchEvents::SwipeDown: {
|
||||||
Controllers::NotificationManager::Notification previousNotification;
|
Controllers::NotificationManager::Notification previousNotification;
|
||||||
|
@ -82,8 +84,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||||
currentId = previousNotification.id;
|
currentId = previousNotification.id;
|
||||||
currentItem.reset(nullptr);
|
currentItem.reset(nullptr);
|
||||||
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
|
||||||
currentItem = std::make_unique<NotificationItem>("\nNotification",
|
currentItem = std::make_unique<NotificationItem>(previousNotification.Title(),
|
||||||
previousNotification.message.data(),
|
previousNotification.Message(),
|
||||||
previousNotification.index,
|
previousNotification.index,
|
||||||
previousNotification.category,
|
previousNotification.category,
|
||||||
notificationManager.NbNotifications(),
|
notificationManager.NbNotifications(),
|
||||||
|
@ -107,8 +109,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||||
currentId = nextNotification.id;
|
currentId = nextNotification.id;
|
||||||
currentItem.reset(nullptr);
|
currentItem.reset(nullptr);
|
||||||
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
|
||||||
currentItem = std::make_unique<NotificationItem>("\nNotification",
|
currentItem = std::make_unique<NotificationItem>(nextNotification.Title(),
|
||||||
nextNotification.message.data(),
|
nextNotification.Message(),
|
||||||
nextNotification.index,
|
nextNotification.index,
|
||||||
nextNotification.category,
|
nextNotification.category,
|
||||||
notificationManager.NbNotifications(),
|
notificationManager.NbNotifications(),
|
||||||
|
@ -170,8 +172,9 @@ namespace {
|
||||||
|
|
||||||
lv_obj_t* alert_type = lv_label_create(lv_scr_act(), nullptr);
|
lv_obj_t* alert_type = lv_label_create(lv_scr_act(), nullptr);
|
||||||
lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x888888));
|
lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x888888));
|
||||||
|
if(title == nullptr) title = "Notification";
|
||||||
lv_label_set_text(alert_type, title);
|
lv_label_set_text(alert_type, title);
|
||||||
lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, -4);
|
lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 16);
|
||||||
|
|
||||||
/////////
|
/////////
|
||||||
switch(category) {
|
switch(category) {
|
||||||
|
|
Loading…
Reference in a new issue