From b66ae1fa8bd4dc87ca18bbabb823a9a199f260dd Mon Sep 17 00:00:00 2001 From: kkleczkowski <49439739+kkleczkowski@users.noreply.github.com> Date: Wed, 27 Nov 2019 10:09:03 +0100 Subject: [PATCH] Edg 2286 browsing history of conversations (#92) * WiP on thread view. * Missing db code. * Fixes in sericeDB, working on listView in threads window. * Changes in thread Db message. * Missing responseTo value bug tracking. * Fixed threads DB getter. * Show threads list. * Added missing code in service-db. * Small fixes. * WiP listView swich page. * Code clean-up. * Code formatted. * PR sugestions applied. --- image/sms.db | Bin 16384 -> 16384 bytes .../ApplicationMessages.cpp | 78 +++++++----- .../ApplicationMessages.hpp | 15 ++- .../application-messages/CMakeLists.txt | 11 ++ .../application-messages/MessagesStyle.hpp | 32 +++++ .../widgets/ThreadItem.cpp | 96 ++++++++++++++ .../widgets/ThreadItem.hpp | 35 +++++ .../widgets/ThreadModel.cpp | 65 ++++++++++ .../widgets/ThreadModel.hpp | 42 ++++++ .../windows/MessagesMainWindow.cpp | 120 +++++++++++------- .../windows/MessagesMainWindow.hpp | 37 +++--- .../windows/ThreadViewWindow.cpp | 3 + .../windows/ThreadViewWindow.hpp | 3 + module-db/Tables/ThreadsTable.cpp | 2 +- module-gui/gui/widgets/ListItemProvider.hpp | 1 + module-services/service-db/ServiceDB.cpp | 33 ++++- .../service-db/api/DBServiceAPI.cpp | 33 ++++- .../service-db/api/DBServiceAPI.hpp | 4 +- .../service-db/messages/DBMessage.hpp | 10 +- source/MessageType.hpp | 2 + source/main.cpp | 9 +- 21 files changed, 517 insertions(+), 114 deletions(-) create mode 100644 module-apps/application-messages/MessagesStyle.hpp create mode 100644 module-apps/application-messages/widgets/ThreadItem.cpp create mode 100644 module-apps/application-messages/widgets/ThreadItem.hpp create mode 100644 module-apps/application-messages/widgets/ThreadModel.cpp create mode 100644 module-apps/application-messages/widgets/ThreadModel.hpp diff --git a/image/sms.db b/image/sms.db index b5975fe7e38278b972112b425253b0061de2fffa..2b9ed339f6256fb5c8a539b3339e0e66005b0409 100644 GIT binary patch delta 411 zcmaiwu}T9$5Qb;=?sB(*+<1bGvDi)o6%;H4gM}6r_F`eN+#Yh^Ws}0u%w<~{)*n@8l-U z+vjZ0|HrxS&*Fo5e9LnbTTr29ganK;$G{W_bfLz)0hoUTs_!AB2}{Qw9-YjFSo delta 64 wcmZo@U~Fh$oFL7}JWr0)8e2fz5&jFZm}<5M<+J00LZG01UDZ@&Et; diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index 9cfeafadc..061f88bb7 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -15,66 +15,76 @@ namespace app { -ApplicationMessages::ApplicationMessages(std::string name, std::string parent, bool startBackgound) : - Application( name, parent, startBackgound, 4096 ) { +ApplicationMessages::ApplicationMessages(std::string name, std::string parent, + bool startBackgound) : + Application(name, parent, startBackgound, 4096) { } -ApplicationMessages::~ApplicationMessages() {} +ApplicationMessages::~ApplicationMessages() { +} // Invoked upon receiving data message -sys::Message_t ApplicationMessages::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage* resp) { +sys::Message_t ApplicationMessages::DataReceivedHandler(sys::DataMessage *msgl, + sys::ResponseMessage *resp) { + auto retMsg = Application::DataReceivedHandler(msgl); + // if message was handled by application's template there is no need to process further. + if (reinterpret_cast(retMsg.get())->retCode + == sys::ReturnCodes::Success) { + return retMsg; + } - auto retMsg = Application::DataReceivedHandler(msgl); - // if message was handled by application's template there is no need to process further. - if (reinterpret_cast(retMsg.get())->retCode == sys::ReturnCodes::Success) { - return retMsg; - } + // this variable defines whether message was processed. + bool handled = false; - // this variable defines whether message was processed. - bool handled = false; - - //handle database response - if( resp != nullptr ) { + //handle database response + if (resp != nullptr) { handled = true; uint32_t msgType = resp->responseTo; - switch( msgType ) { - case static_cast(MessageType::DBContactGetLimitOffset): { - if( currentWindow->onDatabaseMessage( resp ) ) - refreshWindow( gui::RefreshModes::GUI_REFRESH_FAST ); - }break; + switch (msgType) { + case static_cast(MessageType::DBThreadGetLimitOffset): { + if (currentWindow->onDatabaseMessage(resp)) + refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + } + break; } } - if (handled) - return std::make_shared(); - else - return std::make_shared(sys::ReturnCodes::Unresolved); + if (handled) + return std::make_shared(); + else + return std::make_shared( + sys::ReturnCodes::Unresolved); } // Invoked during initialization sys::ReturnCodes ApplicationMessages::InitHandler() { - auto ret = Application::InitHandler(); - if (ret != sys::ReturnCodes::Success) - return ret; + auto ret = Application::InitHandler(); + if (ret != sys::ReturnCodes::Success) + return ret; - createUserInterface(); + createUserInterface(); - setActiveWindow("MainWindow"); + setActiveWindow("MainWindow"); - return ret; + return ret; } -sys::ReturnCodes ApplicationMessages::DeinitHandler() { return sys::ReturnCodes::Success; } +sys::ReturnCodes ApplicationMessages::DeinitHandler() { + return sys::ReturnCodes::Success; +} void ApplicationMessages::createUserInterface() { - gui::AppWindow *window = nullptr; + gui::AppWindow *window = nullptr; + + window = new gui::MessagesMainWindow(this); + windows.insert( + std::pair(window->getName(), window)); - window = new gui::MessagesMainWindow(this); - windows.insert(std::pair(window->getName(), window)); } -void ApplicationMessages::destroyUserInterface() {} +void ApplicationMessages::destroyUserInterface() { +} } /* namespace app */ diff --git a/module-apps/application-messages/ApplicationMessages.hpp b/module-apps/application-messages/ApplicationMessages.hpp index ee47fe363..c7823329e 100644 --- a/module-apps/application-messages/ApplicationMessages.hpp +++ b/module-apps/application-messages/ApplicationMessages.hpp @@ -15,22 +15,23 @@ namespace app { class ApplicationMessages: public app::Application { public: - ApplicationMessages( std::string name="ApplicationMessages", std::string parent="", bool startBackgound = false); + ApplicationMessages(std::string name = "ApplicationMessages", + std::string parent = "", bool startBackgound = false); virtual ~ApplicationMessages(); - sys::Message_t DataReceivedHandler(sys::DataMessage* msgl,sys::ResponseMessage* resp) override; + sys::Message_t DataReceivedHandler(sys::DataMessage *msgl, + sys::ResponseMessage *resp) override; sys::ReturnCodes InitHandler() override; sys::ReturnCodes DeinitHandler() override; - sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final{return sys::ReturnCodes::Success;} + sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) + override final { + return sys::ReturnCodes::Success; + } void createUserInterface() override; void destroyUserInterface() override; }; - } /* namespace app */ - - - #endif /* MODULE_APPS_APPLICATION_MESSAGES_APPLICATIONMESSAGES_HPP_ */ diff --git a/module-apps/application-messages/CMakeLists.txt b/module-apps/application-messages/CMakeLists.txt index 630a2fbd9..bcb47cad0 100644 --- a/module-apps/application-messages/CMakeLists.txt +++ b/module-apps/application-messages/CMakeLists.txt @@ -15,15 +15,26 @@ target_sources( ${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/ApplicationMessages.cpp" #"${CMAKE_CURRENT_LIST_DIR}/MessagesModel.cpp" + #"${CMAKE_CURRENT_LIST_DIR}/widgets/MessagesItem.cpp" #"${CMAKE_CURRENT_LIST_DIR}/widgets/MessagesListView.cpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/ThreadModel.cpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/ThreadItem.cpp" + "${CMAKE_CURRENT_LIST_DIR}/windows/MessagesMainWindow.cpp" "${CMAKE_CURRENT_LIST_DIR}/windows/ThreadViewWindow.cpp" + PUBLIC #"${CMAKE_CURRENT_LIST_DIR}/MessagesModel.hpp" "${CMAKE_CURRENT_LIST_DIR}/ApplicationMessages.hpp" + "${CMAKE_CURRENT_LIST_DIR}/MessagesStyle.hpp" + + "${CMAKE_CURRENT_LIST_DIR}/widgets/ThreadModel.hpp" + "${CMAKE_CURRENT_LIST_DIR}/widgets/ThreadItem.hpp" #"${CMAKE_CURRENT_LIST_DIR}/widgets/MessagesListView.hpp" #"${CMAKE_CURRENT_LIST_DIR}/widgets/MessagesItem.hpp" + #"${CMAKE_CURRENT_LIST_DIR}/windows/MessagesNewContact.hpp" + ) diff --git a/module-apps/application-messages/MessagesStyle.hpp b/module-apps/application-messages/MessagesStyle.hpp new file mode 100644 index 000000000..bc23b3ce0 --- /dev/null +++ b/module-apps/application-messages/MessagesStyle.hpp @@ -0,0 +1,32 @@ +/* + * MessagesStyle.hpp + * + * Created on: 25 lis 2019 + * Author: kuba + */ + +#pragma once + +namespace messages { +namespace threads { +constexpr auto pageSize = 4; + +constexpr auto listHeight = 445; +constexpr auto listWidth = 458; +constexpr auto listPositionX = 11; +constexpr auto ListPositionY = 105; +} //namespace threads + +namespace threadItem { + +constexpr auto contactPositionX = 14; +constexpr auto contactPositionY = 10; +constexpr auto cotactWidthOffset = 133; + +constexpr auto timestampWidth = 100; + +constexpr auto prewievPositionX = 14; +constexpr auto previewWidthOffset = 20; +} +} //namespace messages + diff --git a/module-apps/application-messages/widgets/ThreadItem.cpp b/module-apps/application-messages/widgets/ThreadItem.cpp new file mode 100644 index 000000000..46e75aecf --- /dev/null +++ b/module-apps/application-messages/widgets/ThreadItem.cpp @@ -0,0 +1,96 @@ +/* + * ThreadItem.cpp + * + * Created on: 15 lis 2019 + * Author: kuba + */ +#include "ThreadItem.hpp" +#include "time/time_conversion.hpp" + +#include "service-db/api/DBServiceAPI.hpp" + +#include +#include "../MessagesStyle.hpp" + +namespace gui { + +ThreadItem::ThreadItem(ThreadModel *threadmodel) { + using namespace style; + + model = threadmodel; + minWidth = 431; + minHeight = 100; + maxWidth = 431; + maxHeight = 100; + + setRadius(0); + setEdges( + RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM + | RectangleEdgeFlags::GUI_RECT_EDGE_TOP); + + setPenFocusWidth(window::default_border_focucs_w); + setPenWidth(window::default_border_no_focus_w); + + contact = new gui::Label(this, 0, 0, 0, 0); + contact->setPenFocusWidth(window::default_border_no_focus_w); + contact->setPenWidth(window::default_border_no_focus_w); + contact->setFont(style::window::font::big); + contact->setDotsMode(true); + contact->setAlignement(gui::Alignment { + gui::Alignment::ALIGN_HORIZONTAL_LEFT, + gui::Alignment::ALIGN_VERTICAL_CENTER }); + + timestamp = new gui::Label(this, 0, 0, 0, 0); + timestamp->setPenFocusWidth(window::default_border_no_focus_w); + timestamp->setPenWidth(window::default_border_no_focus_w); + timestamp->setFont(style::window::font::small); + timestamp->setDotsMode(true); + timestamp->setAlignement(gui::Alignment { + gui::Alignment::ALIGN_HORIZONTAL_RIGHT, + gui::Alignment::ALIGN_VERTICAL_CENTER }); + + preview = new gui::Label(this, 0, 0, 0, 0); + preview->setPenFocusWidth(window::default_border_no_focus_w); + preview->setPenWidth(window::default_border_no_focus_w); + preview->setFont(style::window::font::small); + preview->setDotsMode(true); + preview->setAlignement(gui::Alignment { + gui::Alignment::ALIGN_HORIZONTAL_LEFT, + gui::Alignment::ALIGN_VERTICAL_CENTER }); + +} + +bool ThreadItem::onDimensionChanged(const BoundingBox &oldDim, + const BoundingBox &newDim) { + using namespace messages::threadItem; + + contact->setPosition(contactPositionX, contactPositionY); + contact->setSize(newDim.w - cotactWidthOffset, newDim.h / 2); + + timestamp->setPosition(newDim.w - timestampWidth, 0); + timestamp->setSize(timestampWidth, newDim.h / 2); + + preview->setPosition(14, newDim.h / 2); + preview->setSize(newDim.w - previewWidthOffset, newDim.h / 2); + + return true; +} + +void ThreadItem::setThreadItem(std::shared_ptr &thread) { + this->thread = thread; + + if (model != nullptr) { + auto contactRec = DBServiceAPI::ContactGetByID(model->getApplication(), + thread->contactID); + auto cont = contactRec->front(); + contact->setText(cont.primaryName + " " + cont.alternativeName); + } + + timestamp->setText(utils::time::SysTime(thread->date)); + + preview->setText(thread->snippet); + +} + +} /*namespace gui*/ + diff --git a/module-apps/application-messages/widgets/ThreadItem.hpp b/module-apps/application-messages/widgets/ThreadItem.hpp new file mode 100644 index 000000000..03d695dc7 --- /dev/null +++ b/module-apps/application-messages/widgets/ThreadItem.hpp @@ -0,0 +1,35 @@ +/* + * ThreadItem.hpp + * + * Created on: 15 lis 2019 + * Author: kuba + */ + +#pragma once + +#include "Label.hpp" +#include "Image.hpp" +#include "ListItem.hpp" +#include "ThreadModel.hpp" + +namespace gui { + +class ThreadItem: public ListItem { + +private: + ThreadModel *model = nullptr; + + std::shared_ptr thread = nullptr; + gui::Label *contact = nullptr; + gui::Label *timestamp = nullptr; + gui::Label *preview = nullptr; + + gui::Image *dot = nullptr; +public: + ThreadItem(ThreadModel *model); + + bool onDimensionChanged(const BoundingBox &oldDim, + const BoundingBox &newDim) override; + void setThreadItem(std::shared_ptr &thread); +}; +} /*namespace gui*/ diff --git a/module-apps/application-messages/widgets/ThreadModel.cpp b/module-apps/application-messages/widgets/ThreadModel.cpp new file mode 100644 index 000000000..d8208c839 --- /dev/null +++ b/module-apps/application-messages/widgets/ThreadModel.cpp @@ -0,0 +1,65 @@ +/* + * ThreadModel.cpp + * + * Created on: 15 lis 2019 + * Author: kuba + */ + +#include "ThreadModel.hpp" +#include "ThreadItem.hpp" + +#include "Application.hpp" + +#include "../MessagesStyle.hpp" + +#include "service-db/api/DBServiceAPI.hpp" +ThreadModel::ThreadModel(app::Application *app) : + DatabaseModel(app, messages::threads::pageSize) { + +} + +void ThreadModel::requestRecordsCount(void) { + recordsCount = DBServiceAPI::ThreadGetCount(application); + + if (recordsCount > 0) { + + DBServiceAPI::ThreadGetLimitOffset(application, 0, + messages::threads::pageSize); + if (recordsCount >= messages::threads::pageSize) { + DBServiceAPI::ThreadGetLimitOffset(application, + messages::threads::pageSize, messages::threads::pageSize); + } + } +} +bool ThreadModel::updateRecords( + std::unique_ptr> records, + const uint32_t offset, const uint32_t limit, uint32_t count) { + DatabaseModel::updateRecords(std::move(records), offset, limit, count); + + return true; +} + +void ThreadModel::requestRecords(uint32_t offset, uint32_t limit) { + DBServiceAPI::ThreadGetLimitOffset(application, offset, limit); +} + +gui::ListItem* ThreadModel::getItem(int index, int fistElement, int prevElement, + uint32_t limit, int remaining, bool topDown) { + std::shared_ptr thread = getRecord(index); + + if (thread.get() == nullptr) { + return nullptr; + } + + auto item = new gui::ThreadItem(this); + if (item != nullptr) { + item->setThreadItem(thread); + item->setID(index); + item->activatedCallback = [=](gui::Item &item) { + LOG_INFO("ThreadItem ActivatedCallback"); + return true; + }; + return item; + } + return nullptr; +} diff --git a/module-apps/application-messages/widgets/ThreadModel.hpp b/module-apps/application-messages/widgets/ThreadModel.hpp new file mode 100644 index 000000000..4cb36f13a --- /dev/null +++ b/module-apps/application-messages/widgets/ThreadModel.hpp @@ -0,0 +1,42 @@ +/* + * ThreadeModel.hpp + * + * Created on: 13 lis 2019 + * Author: kuba + */ + +#pragma once + +#include +#include + +#include "DatabaseModel.hpp" +#include "Application.hpp" +#include "ListItemProvider.hpp" +#include "Interface/ThreadRecord.hpp" + +class ThreadModel: public app::DatabaseModel, + public gui::ListItemProvider { +public: + ThreadModel() = delete; + ThreadModel(app::Application *app); + virtual ~ThreadModel() = default; + + void requestRecordsCount() override; + bool updateRecords(std::unique_ptr> records, + const uint32_t offset, const uint32_t limit, uint32_t count) + override; + void requestRecords(const uint32_t offset, const uint32_t limit) override; + + gui::ListItem* getItem(int index, int firstElement, int prevElement, + uint32_t limit, int remaining, bool topDown) override; + int getItemCount() const override { + return recordsCount; + } + ; + app::Application* getApplication(void) { + return application; + } + ; +}; + diff --git a/module-apps/application-messages/windows/MessagesMainWindow.cpp b/module-apps/application-messages/windows/MessagesMainWindow.cpp index 2d42743d7..ffad9762e 100644 --- a/module-apps/application-messages/windows/MessagesMainWindow.cpp +++ b/module-apps/application-messages/windows/MessagesMainWindow.cpp @@ -11,7 +11,6 @@ #include "service-appmgr/ApplicationManager.hpp" -//#include "../ApplicationPhonebook.hpp" #include "service-db/messages/DBMessage.hpp" #include "i18/i18.hpp" @@ -19,6 +18,7 @@ #include "ListView.hpp" #include "Margins.hpp" #include "MessagesMainWindow.hpp" +#include "../MessagesStyle.hpp" #include "service-db/api/DBServiceAPI.hpp" @@ -28,82 +28,112 @@ namespace gui { MessagesMainWindow::MessagesMainWindow(app::Application *app) : - AppWindow(app, "MainWindow") -// phonebookModel{ new PhonebookModel(app)} -{ - setSize(480, 600); - buildInterface(); + AppWindow(app, "MainWindow"), threadModel { new ThreadModel(app) } { + setSize(style::window_width, style::window_height); + buildInterface(); } void MessagesMainWindow::rebuild() { - destroyInterface(); - buildInterface(); + destroyInterface(); + buildInterface(); } void MessagesMainWindow::buildInterface() { + using namespace messages; + AppWindow::buildInterface(); -// list = new gui::PhonebookListView(this, 11, 105, 480-22, 600-105-50 ); -// list->setMaxElements(7); -// list->setPageSize(7); -// list->setPenFocusWidth(0); -// list->setPenWidth(0); -// list->setProvider( phonebookModel ); -// list->setApplication( application ); + list = new gui::ListView(this, threads::listPositionX, + threads::ListPositionY, threads::listWidth, threads::listWidth); + list->setMaxElements(threads::pageSize); + list->setPageSize(threads::pageSize); + list->setPenFocusWidth(0); + list->setPenWidth(0); + list->setProvider(threadModel); bottomBar->setActive(BottomBar::Side::LEFT, true); - bottomBar->setActive(BottomBar::Side::CENTER, true); - bottomBar->setActive(BottomBar::Side::RIGHT, true); - bottomBar->setText(BottomBar::Side::LEFT, utils::localize.get("common_options")); - bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("common_open")); - bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get("common_back")); + bottomBar->setActive(BottomBar::Side::CENTER, true); + bottomBar->setActive(BottomBar::Side::RIGHT, true); + bottomBar->setText(BottomBar::Side::LEFT, + utils::localize.get("common_options")); + bottomBar->setText(BottomBar::Side::CENTER, + utils::localize.get("common_open")); + bottomBar->setText(BottomBar::Side::RIGHT, + utils::localize.get("common_back")); - topBar->setActive(TopBar::Elements::TIME, true); + topBar->setActive(TopBar::Elements::TIME, true); - setTitle(utils::localize.get("app_messages_title_main")); + setTitle(utils::localize.get("app_messages_title_main")); - leftArrowImage = new gui::Image( this, 30,62,0,0, "arrow_left" ); - rightArrowImage = new gui::Image( this, 480-30-13,62,0,0, "arrow_right" ); - newMessageImage = new gui::Image( this, 48,55,0,0, "cross" ); - searchImage = new gui::Image( this, 480-48-26,55,0,0, "search" ); + leftArrowImage = new gui::Image(this, 30, 62, 0, 0, "arrow_left"); + rightArrowImage = new gui::Image(this, 480 - 30 - 13, 62, 0, 0, + "arrow_right"); + newMessageImage = new gui::Image(this, 48, 55, 0, 0, "cross"); + searchImage = new gui::Image(this, 480 - 48 - 26, 55, 0, 0, "search"); + +// setFocusItem( list ); } void MessagesMainWindow::destroyInterface() { - AppWindow::destroyInterface(); -// if( list ) { removeWidget(list); delete list; list = nullptr; } - if( leftArrowImage ) { removeWidget(leftArrowImage); delete leftArrowImage; leftArrowImage = nullptr; } - if( rightArrowImage ) { removeWidget(rightArrowImage); delete rightArrowImage; rightArrowImage = nullptr; } - if( newMessageImage ) { removeWidget(newMessageImage); delete newMessageImage; newMessageImage = nullptr; } - if( searchImage ) { removeWidget(searchImage); delete searchImage; searchImage = nullptr; } + AppWindow::destroyInterface(); + if (list) { + removeWidget(list); + delete list; + list = nullptr; + } + if (leftArrowImage) { + removeWidget(leftArrowImage); + delete leftArrowImage; + leftArrowImage = nullptr; + } + if (rightArrowImage) { + removeWidget(rightArrowImage); + delete rightArrowImage; + rightArrowImage = nullptr; + } + if (newMessageImage) { + removeWidget(newMessageImage); + delete newMessageImage; + newMessageImage = nullptr; + } + if (searchImage) { + removeWidget(searchImage); + delete searchImage; + searchImage = nullptr; + } - children.clear(); -// delete phonebookModel; + children.clear(); + delete threadModel; } MessagesMainWindow::~MessagesMainWindow() { destroyInterface(); } - void MessagesMainWindow::onBeforeShow(ShowMode mode, SwitchData *data) { -// setFocusItem(list); -// phonebookModel->clear(); -// phonebookModel->requestRecordsCount(); + if (mode == ShowMode::GUI_SHOW_INIT) { + threadModel->clear(); + threadModel->requestRecordsCount(); + list->clear(); + list->setElementsCount(threadModel->getItemCount()); + + setFocusItem(list); + } -// list->clear(); -// list->setElementsCount( phonebookModel->getItemCount() ); } bool MessagesMainWindow::onInput(const InputEvent &inputEvent) { //check if any of the lower inheritance onInput methods catch the event - return AppWindow::onInput( inputEvent ); + return AppWindow::onInput(inputEvent); } -bool MessagesMainWindow::onDatabaseMessage( sys::Message* msgl ) { -// DBContactResponseMessage* msg = reinterpret_cast( msgl ); -// if( phonebookModel->updateRecords( std::move(msg->records), msg->offset, msg->limit, msg->count, msg->favourite ) ) -// return true; +bool MessagesMainWindow::onDatabaseMessage(sys::Message *msgl) { + DBThreadResponseMessage *msg = + reinterpret_cast(msgl); + if (threadModel->updateRecords(std::move(msg->records), msg->offset, + msg->limit, msg->count)) + return true; return false; } diff --git a/module-apps/application-messages/windows/MessagesMainWindow.hpp b/module-apps/application-messages/windows/MessagesMainWindow.hpp index c9ee6259b..e030caf83 100644 --- a/module-apps/application-messages/windows/MessagesMainWindow.hpp +++ b/module-apps/application-messages/windows/MessagesMainWindow.hpp @@ -17,37 +17,38 @@ #include "gui/widgets/Label.hpp" #include "gui/widgets/Window.hpp" #include "ListView.hpp" -//#include "../PhonebookModel.hpp" -//#include "../widgets/PhonebookListView.hpp" +#include "../widgets/ThreadModel.hpp" namespace gui { class MessagesMainWindow: public AppWindow { - protected: +protected: // PhonebookListView* list; // PhonebookModel* phonebookModel = nullptr; - Image* leftArrowImage = nullptr; - Image* rightArrowImage = nullptr; - Image* newMessageImage = nullptr; - Image* searchImage = nullptr; + Image *leftArrowImage = nullptr; + Image *rightArrowImage = nullptr; + Image *newMessageImage = nullptr; + Image *searchImage = nullptr; - public: - MessagesMainWindow(app::Application *app); - virtual ~MessagesMainWindow(); + ThreadModel *threadModel = nullptr; + gui::ListView *list = nullptr; - // virtual methods - bool onInput(const InputEvent &inputEvent) override; - void onBeforeShow(ShowMode mode, SwitchData *data) override; +public: + MessagesMainWindow(app::Application *app); + virtual ~MessagesMainWindow(); - bool onDatabaseMessage( sys::Message* msgl ); + // virtual methods + bool onInput(const InputEvent &inputEvent) override; + void onBeforeShow(ShowMode mode, SwitchData *data) override; - void rebuild() override; - void buildInterface() override; - void destroyInterface() override; + bool onDatabaseMessage(sys::Message *msgl); + + void rebuild() override; + void buildInterface() override; + void destroyInterface() override; }; } /* namespace gui */ - #endif /* MODULE_APPS_APPLICATION_MESSAGES_WINDOWS_MESSAGESMAINWINDOW_HPP_ */ diff --git a/module-apps/application-messages/windows/ThreadViewWindow.cpp b/module-apps/application-messages/windows/ThreadViewWindow.cpp index 83980cd49..e722a4f08 100644 --- a/module-apps/application-messages/windows/ThreadViewWindow.cpp +++ b/module-apps/application-messages/windows/ThreadViewWindow.cpp @@ -25,6 +25,9 @@ #include "ThreadViewWindow.hpp" #include +#include "../widgets/ThreadModel.hpp" + + namespace gui { ThreadViewWindow::ThreadViewWindow(app::Application *app) : diff --git a/module-apps/application-messages/windows/ThreadViewWindow.hpp b/module-apps/application-messages/windows/ThreadViewWindow.hpp index 62c533b17..e7ecdb61d 100644 --- a/module-apps/application-messages/windows/ThreadViewWindow.hpp +++ b/module-apps/application-messages/windows/ThreadViewWindow.hpp @@ -37,6 +37,9 @@ public: void rebuild() override; void buildInterface() override; void destroyInterface() override; + +private: + ListView* list; }; } /* namespace gui */ diff --git a/module-db/Tables/ThreadsTable.cpp b/module-db/Tables/ThreadsTable.cpp index 29ea5acc9..298618a7b 100644 --- a/module-db/Tables/ThreadsTable.cpp +++ b/module-db/Tables/ThreadsTable.cpp @@ -77,7 +77,7 @@ ThreadsTableRow ThreadsTable::GetByID(uint32_t id) { std::vector ThreadsTable::GetLimitOffset(uint32_t offset, uint32_t limit) { - auto retQuery = db->Query("SELECT * from threads ORDER BY date LIMIT %lu OFFSET %lu;", + auto retQuery = db->Query("SELECT * from threads ORDER BY date DESC LIMIT %lu OFFSET %lu;", limit, offset); diff --git a/module-gui/gui/widgets/ListItemProvider.hpp b/module-gui/gui/widgets/ListItemProvider.hpp index 4a6f2f5c3..9022d7f07 100644 --- a/module-gui/gui/widgets/ListItemProvider.hpp +++ b/module-gui/gui/widgets/ListItemProvider.hpp @@ -22,6 +22,7 @@ public: ListItemProvider(); virtual ~ListItemProvider(); + virtual int getItemCount() const = 0; /** * @brief Requests from Provider element that is no index position out of givent count of visible elements diff --git a/module-services/service-db/ServiceDB.cpp b/module-services/service-db/ServiceDB.cpp index 3d574e740..439933e90 100644 --- a/module-services/service-db/ServiceDB.cpp +++ b/module-services/service-db/ServiceDB.cpp @@ -199,10 +199,26 @@ sys::Message_t ServiceDB::DataReceivedHandler(sys::DataMessage *msgl,sys::Respon #if SHOW_DB_ACCESS_PERF == 1 LOG_DEBUG("DBThreadGetLimitOffset time: %lu",cpp_freertos::Ticks::GetTicks()-timestamp); #endif - responseMsg = std::make_shared(std::move(ret), true); + LOG_INFO("Thread get limit offset"); + responseMsg = std::make_shared(std::move(ret), true, msg->limit, msg->offset, ret->size()); } break; + case MessageType::DBThreadGetCount: + { + // DBThreadMessage *msg = reinterpret_cast(msgl); + #if SHOW_DB_ACCESS_PERF == 1 + timestamp = cpp_freertos::Ticks::GetTicks(); + #endif + auto ret = threadRecordInterface->GetCount(); + #if SHOW_DB_ACCESS_PERF == 1 + LOG_DEBUG("DBThreadGetCount time: %lu",cpp_freertos::Ticks::GetTicks()-timestamp); + #endif + //DBThreadResponseMessage(std::unique_ptr> rec,uint32_t retCode=0,uint32_t count=0,uint32_t respTo=0) + responseMsg = std::make_shared(nullptr, true, 0, 0, ret); + } + break; + case MessageType::DBContactAdd: { DBContactMessage *msg = reinterpret_cast(msgl); #if SHOW_DB_ACCESS_PERF == 1 @@ -228,6 +244,21 @@ sys::Message_t ServiceDB::DataReceivedHandler(sys::DataMessage *msgl,sys::Respon static_cast(MessageType::DBContactGetByName)); } break; + case MessageType::DBContactGetByID: { + DBContactMessage *msg = reinterpret_cast(msgl); +#if SHOW_DB_ACCESS_PERF == 1 + timestamp = cpp_freertos::Ticks::GetTicks(); +#endif + auto ret = contactRecordInterface->GetByID( msg->record.dbID ); +#if SHOW_DB_ACCESS_PERF == 1 + LOG_DEBUG("DBContactGetByName time: %lu",cpp_freertos::Ticks::GetTicks()-timestamp); +#endif + auto records = std::make_unique>(); + records->push_back(ret); + responseMsg = std::make_shared(std::move(records), true, msg->limit, msg->offset, msg->favourite, 1, + static_cast(MessageType::DBContactGetByID)); + } break; + case MessageType::DBContactGetBySpeedDial: { DBContactMessage *msg = reinterpret_cast(msgl); #if SHOW_DB_ACCESS_PERF == 1 diff --git a/module-services/service-db/api/DBServiceAPI.cpp b/module-services/service-db/api/DBServiceAPI.cpp index 660a89cfa..8b6d9e614 100644 --- a/module-services/service-db/api/DBServiceAPI.cpp +++ b/module-services/service-db/api/DBServiceAPI.cpp @@ -151,19 +151,27 @@ bool DBServiceAPI::ThreadRemove(sys::Service *serv, uint32_t id) { } } -std::unique_ptr> DBServiceAPI::ThreadGetLimitOffset(sys::Service *serv, uint32_t offset, - uint32_t limit) { +bool DBServiceAPI::ThreadGetLimitOffset(sys::Service *serv, uint32_t offset, uint32_t limit) { std::shared_ptr msg = std::make_shared(MessageType::DBThreadGetLimitOffset); msg->offset = offset; msg->limit = limit; + sys::Bus::SendUnicast(msg,ServiceDB::serviceName,serv); + + return true; +} + +uint32_t DBServiceAPI::ThreadGetCount(sys::Service * serv) +{ + std::shared_ptr msg = std::make_shared(MessageType::DBThreadGetCount); + auto ret = sys::Bus::SendUnicast(msg,ServiceDB::serviceName,serv,5000); DBThreadResponseMessage* threadResponse = reinterpret_cast(ret.second.get()); if((ret.first == sys::ReturnCodes::Success) && (threadResponse->retCode == true)){ - return std::move(threadResponse->records); + return threadResponse->count; } else{ - return std::make_unique>(); + return false; } } @@ -185,6 +193,23 @@ std::unique_ptr> DBServiceAPI::ContactGetByName(sys:: } } +std::unique_ptr> DBServiceAPI::ContactGetByID(sys::Service *serv, uint32_t contactID ) { + + ContactRecord rec; + rec.dbID = contactID; + + std::shared_ptr msg = std::make_shared(MessageType::DBContactGetByID,rec ); + + auto ret = sys::Bus::SendUnicast(msg,ServiceDB::serviceName,serv,5000); + DBContactResponseMessage* contactResponse = reinterpret_cast(ret.second.get()); + if((ret.first == sys::ReturnCodes::Success) && (contactResponse->retCode == true)){ + return std::move(contactResponse->records); + } + else{ + return std::make_unique>(); + } +} + std::unique_ptr> DBServiceAPI::ContactGetBySpeeddial(sys::Service *serv, uint8_t speeddial ) { ContactRecord rec; rec.speeddial = speeddial; diff --git a/module-services/service-db/api/DBServiceAPI.hpp b/module-services/service-db/api/DBServiceAPI.hpp index c2645f1b2..9912ab125 100644 --- a/module-services/service-db/api/DBServiceAPI.hpp +++ b/module-services/service-db/api/DBServiceAPI.hpp @@ -35,7 +35,8 @@ public: static ThreadRecord ThreadGet(sys::Service* serv,uint32_t id); static bool ThreadRemove(sys::Service* serv,uint32_t id); - static std::unique_ptr> ThreadGetLimitOffset(sys::Service *serv,uint32_t offset,uint32_t limit); + static bool ThreadGetLimitOffset(sys::Service *serv,uint32_t offset,uint32_t limit); + static uint32_t ThreadGetCount(sys::Service* serv); /** * @brief Function is checking if new contact can be added to database. Function is blocking. @@ -52,6 +53,7 @@ public: ContactRecord& errName, ContactRecord& errPhone1, ContactRecord& errPhone2, ContactRecord& speedDial ); static std::unique_ptr> ContactGetByName(sys::Service *serv, UTF8 primaryName, UTF8 alternativeName ); + static std::unique_ptr> ContactGetByID(sys::Service *serv, uint32_t contactID ); static std::unique_ptr> ContactGetBySpeeddial(sys::Service *serv, uint8_t speeddial ); static std::unique_ptr> ContactGetByPhoneNumber(sys::Service *serv, UTF8 phoneNumber); static bool ContactAdd(sys::Service* serv,const ContactRecord& rec); diff --git a/module-services/service-db/messages/DBMessage.hpp b/module-services/service-db/messages/DBMessage.hpp index b68f97f15..3046411ee 100644 --- a/module-services/service-db/messages/DBMessage.hpp +++ b/module-services/service-db/messages/DBMessage.hpp @@ -93,10 +93,18 @@ public: class DBThreadResponseMessage: public DBResponseMessage { public: - DBThreadResponseMessage(std::unique_ptr> rec,uint32_t retCode=0,uint32_t count=0,uint32_t respTo=0) : DBResponseMessage(retCode,count,respTo),records(std::move(rec)){}; + DBThreadResponseMessage(std::unique_ptr> rec,uint32_t retCode=0, uint32_t limit=0,uint32_t offset=0,uint32_t count=0,uint32_t respTo=0) : DBResponseMessage(retCode,count,respTo), + records(std::move(rec)), + limit( limit ), + offset( offset ) + { + this->count = count; + }; virtual ~DBThreadResponseMessage() {}; std::unique_ptr> records; + uint32_t limit = 0; + uint32_t offset = 0; }; class DBContactMessage : public DBMessage{ diff --git a/source/MessageType.hpp b/source/MessageType.hpp index 94e16c5eb..ac3734ae8 100644 --- a/source/MessageType.hpp +++ b/source/MessageType.hpp @@ -38,10 +38,12 @@ enum class MessageType { DBThreadGet, // Get thread by ID DBThreadRemove, // Remove thread by ID DBThreadGetLimitOffset, // Get Thread record by limit,offset + DBThreadGetCount, //get Thread count DBContactVerify, //checks database for a contact that has the same name (primary+" "+alternative) or phone number 1 or phone number 2 or //speed dial key DBContactGetByName, //used to ask for a contact with specified primary and alternative name. + DBContactGetByID, //used to ask for a contact with specified id DBContactGetBySpeedDial, //used to ask for a contact with specified speed dial key assigned DBContactGetByNumber, //used to ask for a contact with specified primary or secondary phone number DBContactAdd, // Add contact record diff --git a/source/main.cpp b/source/main.cpp index 729592721..9f332c721 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -57,7 +57,13 @@ public: ~BlinkyService() { } - + // DBThreadResponseMessage* threadResponse = reinterpret_cast(ret.second.get()); + // if((ret.first == sys::ReturnCodes::Success) && (threadResponse->retCode == true)){ + // return std::move(threadResponse->records); + // } + // else{ + // return std::make_unique>(); + // } // Invoked upon receiving data message sys::Message_t DataReceivedHandler(sys::DataMessage *msgl,sys::ResponseMessage* resp=nullptr) override { @@ -159,7 +165,6 @@ int main() { applications.push_back(app::CreateLauncher("ApplicationCallLog")); applications.push_back(app::CreateLauncher("ApplicationPhonebook")); applications.push_back(app::CreateLauncher("ApplicationMessages")); - //start application manager ret |= sysmgr->CreateService(std::make_shared("ApplicationManager", sysmgr.get(), applications), sysmgr.get());