Files
MuditaOS/module-apps/application-messages/widgets/SMSTemplateModel.cpp
Alek Rudnik 16eaab6b50 Egd 3169 sms templates (#336)
* [EGD-3169] added sms templates model and item
fixed common class name convention

* [EGD-3169] added templates window
Passing template to new sms window is already working

* [EGD-3169] PR fixes from DB PR

* [EGD-3169] add universal callback for templates items

* [EGD-3169] requesting templates from more 2 windows

* [EGD-3169] missign change - display template in threads window

* [EGD-3169] minor fixes

* [EGD-3169] minimal clean up

* [EGD-3169] fixed some layout constatnt

* [EGD-3169] rem minor comments and logs

* [EGD-3089] rem redundant vector include

* [EGD-3169] PR fixes

* [EGD-3169] fixes afeter rebase

* [EGD-3169] workaround for list view issue - added 2 dump entries

* [EGD-3169] PR fixes

* [EGD-3169] style fixes

* [EGD-3169] fix for 0x0D char on enter in text widget

* [EGD-3169] PR fixes

* [EGD-3169] compilation issue
2020-04-30 13:48:23 +02:00

66 lines
2.0 KiB
C++

#include "SMSTemplateModel.hpp"
#include "SMSTemplateItem.hpp"
#include "application-messages/data/SMSdata.hpp"
#include "application-messages/MessagesStyle.hpp"
#include "application-messages/ApplicationMessages.hpp"
#include <service-db/api/DBServiceAPI.hpp>
SMSTemplateModel::SMSTemplateModel(app::Application *app) : DatabaseModel(app)
{}
void SMSTemplateModel::requestRecordsCount()
{
recordsCount = DBServiceAPI::SMSTemplateGetCount(application);
LOG_DEBUG("SMSTemplateGetCount %" PRIu32, recordsCount);
// request first
if (recordsCount > 0) {
LOG_DEBUG("SMSTemplateGetLimitOffset");
auto pageSize = messages::templates::list::pageSize;
DBServiceAPI::SMSTemplateGetLimitOffset(application, 0, pageSize);
}
}
void SMSTemplateModel::requestRecords(const uint32_t offset, const uint32_t limit)
{
DBServiceAPI::SMSTemplateGetLimitOffset(application, offset, limit);
}
bool SMSTemplateModel::updateRecords(std::unique_ptr<std::vector<SMSTemplateRecord>> records,
const uint32_t offset,
const uint32_t limit,
uint32_t count)
{
LOG_INFO("Offset: %" PRIu32 ", Limit: %" PRIu32 " Count:%" PRIu32 "", offset, limit, count);
if (DatabaseModel::updateRecords(std::move(records), offset, limit, count)) {
list->onProviderDataUpdate();
return true;
}
return false;
}
gui::ListItem *SMSTemplateModel::getItem(int index)
{
auto templ = getRecord(index);
if (!templ) {
return nullptr;
}
auto item = new gui::SMSTemplateItem();
item->setTemplate(templ);
item->setID(index);
item->activatedCallback = [=](gui::Item &it) {
LOG_INFO("activatedCallback");
if (auto app = dynamic_cast<app::ApplicationMessages *>(application)) {
if (app->templatesCallback) {
return app->templatesCallback(templ);
}
}
return false;
};
return item;
}