Files
MuditaOS/module-apps/application-messages/widgets/ThreadModel.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

81 lines
2.6 KiB
C++

#include "ThreadModel.hpp"
#include "OptionWindow.hpp"
#include "ThreadItem.hpp"
#include "application-messages/ApplicationMessages.hpp"
#include "application-messages/MessagesStyle.hpp"
#include "application-messages/data/SMSdata.hpp"
#include "application-messages/ApplicationMessages.hpp"
#include "application-messages/windows/OptionsWindow.hpp"
#include "service-db/api/DBServiceAPI.hpp"
#include <cassert>
ThreadModel::ThreadModel(app::Application *app) : DatabaseModel(app)
{}
void ThreadModel::requestRecordsCount(void)
{
recordsCount = DBServiceAPI::ThreadGetCount(application);
if (recordsCount > 0) {
DBServiceAPI::ThreadGetLimitOffset(application, 0, messages::threads::pageSize);
}
}
bool ThreadModel::updateRecords(std::unique_ptr<std::vector<ThreadRecord>> records,
const uint32_t offset,
const uint32_t limit,
uint32_t count)
{
DatabaseModel::updateRecords(std::move(records), offset, limit, count);
list->onProviderDataUpdate();
return true;
}
void ThreadModel::requestRecords(uint32_t offset, uint32_t limit)
{
DBServiceAPI::ThreadGetLimitOffset(application, offset, limit);
}
gui::ListItem *ThreadModel::getItem(int index)
{
std::shared_ptr<ThreadRecord> 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");
if (application) {
application->switchWindow(gui::name::window::thread_view, std::make_unique<SMSThreadData>(thread));
}
else {
LOG_ERROR("No application!");
}
return true;
};
item->inputCallback = [this, item](gui::Item &, const gui::InputEvent &event) {
auto app = dynamic_cast<app::ApplicationMessages *>(application);
assert(app);
if (event.state != gui::InputEvent::State::keyReleasedShort) {
return false;
}
if (event.keyCode == gui::KeyCode::KEY_LF) {
app->windowOptions->clearOptions();
app->windowOptions->addOptions(threadWindowOptions(app, item->getThreadItem().get()));
app->switchWindow(app->windowOptions->getName(), nullptr);
}
return false;
};
return item;
}
return nullptr;
}