mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-19 12:34:31 -04:00
[EGD-3086] added sending sms from new sms window
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <../module-services/service-db/messages/DBNotificationMessage.hpp>
|
||||
#include <service-db/api/DBServiceAPI.hpp>
|
||||
#include <cassert>
|
||||
#include <time/time_conversion.hpp>
|
||||
|
||||
namespace app
|
||||
{
|
||||
@@ -161,6 +162,15 @@ namespace app
|
||||
meta.title = utils::localize.get("common_results_prefix") + query;
|
||||
dialog->update(meta);
|
||||
return switchWindow(gui::name::window::thread_search_none, nullptr);
|
||||
bool ApplicationMessages::sendSms(const UTF8 &number, const UTF8 &body)
|
||||
{
|
||||
SMSRecord record;
|
||||
record.number = number;
|
||||
record.body = body;
|
||||
record.type = SMSType::QUEUED;
|
||||
auto time = utils::time::Timestamp();
|
||||
record.date = time.getTime();
|
||||
return DBServiceAPI::SMSAdd(this, record) != DB_ID_NONE;
|
||||
}
|
||||
|
||||
} /* namespace app */
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace app
|
||||
bool removeSMS_thread(const ThreadRecord *record);
|
||||
/// show dialog with big search icon and text which was used for query
|
||||
bool searchEmpty(const std::string &query = "");
|
||||
bool sendSms(const UTF8 &number, const UTF8 &body);
|
||||
};
|
||||
} /* namespace app */
|
||||
|
||||
|
||||
@@ -1,16 +1,44 @@
|
||||
#include "NewMessage.hpp"
|
||||
|
||||
#include "ThreadViewWindow.hpp"
|
||||
#include "application-phonebook/ApplicationPhonebook.hpp"
|
||||
#include "application-phonebook/windows/PhonebookSearchResults.hpp"
|
||||
#include "service-appmgr/ApplicationManager.hpp"
|
||||
#include "service-db/api/DBServiceAPI.hpp"
|
||||
#include "../ApplicationMessages.hpp"
|
||||
#include "../data/SMSdata.hpp"
|
||||
|
||||
#include <application-phonebook/ApplicationPhonebook.hpp>
|
||||
#include <application-phonebook/windows/PhonebookSearchResults.hpp>
|
||||
#include <service-appmgr/ApplicationManager.hpp>
|
||||
#include <service-db/api/DBServiceAPI.hpp>
|
||||
#include <i18/i18.hpp>
|
||||
#include <widgets/BoxLayout.hpp>
|
||||
#include <widgets/Text.hpp>
|
||||
#include <BoxLayout.hpp>
|
||||
#include <Text.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace gui
|
||||
{
|
||||
NewSMS_Window::NewSMS_Window(app::Application *app) : AppWindow(app, name::window::new_sms)
|
||||
{
|
||||
buildInterface();
|
||||
}
|
||||
|
||||
bool NewSMS_Window::onInput(const InputEvent &inputEvent)
|
||||
{
|
||||
return AppWindow::onInput(inputEvent);
|
||||
}
|
||||
|
||||
void NewSMS_Window::onBeforeShow(ShowMode mode, SwitchData *data)
|
||||
{
|
||||
if (auto pdata = dynamic_cast<PhonebookSearchReuqest *>(data)) {
|
||||
LOG_INFO("received search results");
|
||||
recipient->setText(pdata->result->getFormattedName());
|
||||
contact = pdata->result;
|
||||
}
|
||||
}
|
||||
|
||||
void NewSMS_Window::rebuild()
|
||||
{}
|
||||
|
||||
void NewSMS_Window::buildInterface()
|
||||
{
|
||||
AppWindow::buildInterface();
|
||||
bottomBar->setActive(BottomBar::Side::LEFT, true);
|
||||
@@ -32,32 +60,32 @@ namespace gui
|
||||
label->setFont(style::window::font::small);
|
||||
label->setAlignement(Alignment(Alignment::ALIGN_HORIZONTAL_LEFT, Alignment::ALIGN_VERTICAL_BOTTOM));
|
||||
|
||||
text = new gui::Text(nullptr, 0, 0, body->getWidth(), 43, "", gui::Text::ExpandMode::EXPAND_NONE);
|
||||
text->setEdges(gui::RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM);
|
||||
text->setInputMode(new InputMode({InputMode::phone}));
|
||||
text->setPenFocusWidth(style::window::default_border_focucs_w);
|
||||
text->setPenWidth(style::window::messages::sms_border_no_focus);
|
||||
text->setFont(style::window::font::medium);
|
||||
text->setAlignment(Alignment(Alignment::ALIGN_HORIZONTAL_LEFT, Alignment::ALIGN_VERTICAL_BOTTOM));
|
||||
text->activatedCallback = [=](Item &) -> bool {
|
||||
recipient = new gui::Text(nullptr, 0, 0, body->getWidth(), 43, "", gui::Text::ExpandMode::EXPAND_NONE);
|
||||
recipient->setEdges(gui::RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM);
|
||||
recipient->setInputMode(new InputMode({InputMode::phone}));
|
||||
recipient->setPenFocusWidth(style::window::default_border_focucs_w);
|
||||
recipient->setPenWidth(style::window::messages::sms_border_no_focus);
|
||||
recipient->setFont(style::window::font::medium);
|
||||
recipient->setAlignment(Alignment(Alignment::ALIGN_HORIZONTAL_LEFT, Alignment::ALIGN_VERTICAL_BOTTOM));
|
||||
recipient->activatedCallback = [=](Item &) -> bool {
|
||||
std::shared_ptr<std::vector<ContactRecord>> searchResults =
|
||||
DBServiceAPI::ContactSearch(application, text->getText(), text->getText(), text->getText());
|
||||
DBServiceAPI::ContactSearch(application, {}, {}, recipient->getText());
|
||||
LOG_INFO("Get contact from another app, contacts matching num: %d",
|
||||
static_cast<int>(searchResults.get()->size()));
|
||||
if (searchResults.get()->size() > 0) {
|
||||
std::unique_ptr<PhonebookSearchReuqest> data =
|
||||
std::make_unique<PhonebookSearchReuqest>(text->getText(), searchResults);
|
||||
std::make_unique<PhonebookSearchReuqest>(recipient->getText(), searchResults);
|
||||
data->disableAppClose = true;
|
||||
return sapm::ApplicationManager::messageSwitchApplication(
|
||||
application, app::name_phonebook, name::window::search_results, std::move(data));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
text->focusChangedCallback = [=](Item &) -> bool {
|
||||
recipient->focusChangedCallback = [=](Item &) -> bool {
|
||||
bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("common_select"));
|
||||
return true;
|
||||
};
|
||||
body->addWidget(text);
|
||||
body->addWidget(recipient);
|
||||
|
||||
auto labelMessage = new Label(body, 0, 0, body->getWidth(), 44);
|
||||
labelMessage->setText(utils::localize.get("app_messages_message"));
|
||||
@@ -66,17 +94,52 @@ namespace gui
|
||||
labelMessage->setFont(style::window::font::small);
|
||||
labelMessage->setAlignement(Alignment(Alignment::ALIGN_HORIZONTAL_LEFT, Alignment::ALIGN_VERTICAL_BOTTOM));
|
||||
|
||||
auto message = new gui::Text(nullptr, 0, 0, body->getWidth(), 43, "", gui::Text::ExpandMode::EXPAND_UP);
|
||||
message = new gui::Text(nullptr, 0, 0, body->getWidth(), 43, "", gui::Text::ExpandMode::EXPAND_UP);
|
||||
message->setEdges(gui::RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM);
|
||||
message->setInputMode(new InputMode(
|
||||
{InputMode::ABC, InputMode::abc, InputMode::digit},
|
||||
[=](const UTF8 &text) {},
|
||||
[=](const UTF8 &) {},
|
||||
[=]() { textSelectSpecialCB(); }));
|
||||
message->setPenFocusWidth(style::window::default_border_focucs_w);
|
||||
message->setPenWidth(style::window::messages::sms_border_no_focus);
|
||||
message->setFont(style::window::font::medium);
|
||||
message->setAlignment(Alignment(Alignment::ALIGN_HORIZONTAL_LEFT, Alignment::ALIGN_VERTICAL_BOTTOM));
|
||||
message->activatedCallback = [=](Item &) -> bool { return true; };
|
||||
message->activatedCallback = [=](Item &) -> bool {
|
||||
auto app = dynamic_cast<app::ApplicationMessages *>(application);
|
||||
assert(app != nullptr);
|
||||
// if a valid contact was found, choose it. Otherwise, get a raw entered number
|
||||
UTF8 number =
|
||||
(contact && contact->numbers.size() != 0) ? contact->numbers[0].numberE164 : recipient->getText();
|
||||
auto ret = app->sendSms(number, message->getText());
|
||||
if (!ret) {
|
||||
LOG_ERROR("sendSms failed");
|
||||
return false;
|
||||
}
|
||||
uint32_t contactId;
|
||||
if (!contact || contact->numbers.size() == 0) {
|
||||
// once the sms is send, there is assumption that contact exists
|
||||
auto records = DBServiceAPI::ContactGetByPhoneNumber(application, number);
|
||||
if (records->empty()) {
|
||||
LOG_ERROR("not valid contact for number %s", number.c_str());
|
||||
return false;
|
||||
}
|
||||
contact = std::make_shared<ContactRecord>(records->operator[](0));
|
||||
}
|
||||
|
||||
contactId = contact->ID;
|
||||
|
||||
auto thread = DBServiceAPI::ThreadGetByContact(application, contactId);
|
||||
if (thread) {
|
||||
application->switchWindow(gui::name::window::thread_view,
|
||||
std::make_unique<SMSThreadData>(std::move(thread)));
|
||||
}
|
||||
else {
|
||||
LOG_FATAL("No thread and thread not created!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
message->focusChangedCallback = [=](Item &) -> bool {
|
||||
bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("common_send"));
|
||||
return true;
|
||||
@@ -90,25 +153,10 @@ namespace gui
|
||||
setFocusItem(body);
|
||||
}
|
||||
|
||||
bool NewSMS_Window::onInput(const InputEvent &inputEvent)
|
||||
{
|
||||
return AppWindow::onInput(inputEvent);
|
||||
}
|
||||
|
||||
void NewSMS_Window::onBeforeShow(ShowMode mode, SwitchData *data)
|
||||
{
|
||||
if (auto pdata = dynamic_cast<PhonebookSearchReuqest *>(data)) {
|
||||
LOG_INFO("received search results");
|
||||
text->setText(pdata->result->getFormattedName());
|
||||
}
|
||||
}
|
||||
|
||||
void NewSMS_Window::rebuild()
|
||||
{}
|
||||
|
||||
void NewSMS_Window::buildInterface()
|
||||
{}
|
||||
|
||||
void NewSMS_Window::destroyInterface()
|
||||
{}
|
||||
{
|
||||
AppWindow::destroyInterface();
|
||||
|
||||
children.clear();
|
||||
}
|
||||
}; // namespace gui
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "AppWindow.hpp"
|
||||
#include <AppWindow.hpp>
|
||||
#include <widgets/Text.hpp>
|
||||
#include <service-db/api/DBServiceAPI.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace gui
|
||||
@@ -18,7 +20,9 @@ namespace gui
|
||||
class NewSMS_Window : public AppWindow
|
||||
{
|
||||
private:
|
||||
gui::Text *text = nullptr;
|
||||
gui::Text *recipient = nullptr;
|
||||
gui::Text *message = nullptr;
|
||||
std::shared_ptr<ContactRecord> contact;
|
||||
|
||||
public:
|
||||
NewSMS_Window(app::Application *app);
|
||||
|
||||
@@ -1,35 +1,29 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "service-appmgr/ApplicationManager.hpp"
|
||||
|
||||
#include "i18/i18.hpp"
|
||||
#include "time/time_conversion.hpp"
|
||||
|
||||
#include "Label.hpp"
|
||||
#include "ListView.hpp"
|
||||
#include "Margins.hpp"
|
||||
|
||||
#include "service-db/messages/DBMessage.hpp"
|
||||
|
||||
#include <log/log.hpp>
|
||||
|
||||
#include "ThreadViewWindow.hpp"
|
||||
#include <Style.hpp>
|
||||
|
||||
#include "../widgets/ThreadModel.hpp"
|
||||
|
||||
#include "../ApplicationMessages.hpp"
|
||||
#include "../data/SMSdata.hpp"
|
||||
#include "../widgets/ThreadModel.hpp"
|
||||
#include "OptionsMessages.hpp"
|
||||
#include "service-cellular/api/CellularServiceAPI.hpp"
|
||||
#include <application-phonebook/data/PhonebookItemData.hpp>
|
||||
#include <gui/widgets/Text.hpp>
|
||||
#include <widgets/ListItem.hpp>
|
||||
#include <widgets/ListItemProvider.hpp>
|
||||
#include <widgets/ListView.hpp>
|
||||
|
||||
#include "service-db/api/DBServiceAPI.hpp"
|
||||
#include <Text.hpp>
|
||||
#include <ListItem.hpp>
|
||||
#include <ListItemProvider.hpp>
|
||||
#include <ListView.hpp>
|
||||
#include <Label.hpp>
|
||||
#include <Margins.hpp>
|
||||
#include <service-db/api/DBServiceAPI.hpp>
|
||||
#include <service-appmgr/ApplicationManager.hpp>
|
||||
#include <service-db/messages/DBMessage.hpp>
|
||||
#include <service-cellular/api/CellularServiceAPI.hpp>
|
||||
#include <application-phonebook/data/PhonebookItemData.hpp>
|
||||
#include <i18/i18.hpp>
|
||||
#include <time/time_conversion.hpp>
|
||||
#include <log/log.hpp>
|
||||
#include <Style.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
namespace style
|
||||
{}; // namespace style
|
||||
@@ -96,15 +90,9 @@ namespace gui
|
||||
LOG_DEBUG("No text to send in SMS");
|
||||
return true;
|
||||
}
|
||||
SMSRecord record;
|
||||
record.number = title->getText();
|
||||
record.body = text->getText();
|
||||
record.type = SMSType::QUEUED;
|
||||
auto time = utils::time::Timestamp();
|
||||
record.date = time.getTime();
|
||||
DBServiceAPI::SMSAdd(this->application, record);
|
||||
|
||||
return true;
|
||||
auto app = dynamic_cast<app::ApplicationMessages *>(application);
|
||||
assert(app != nullptr);
|
||||
return app->sendSms(title->getText(), text->getText());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -366,7 +354,7 @@ namespace gui
|
||||
showMessages(Action::Start);
|
||||
auto ret = DBServiceAPI::ContactGetByID(application, pdata->thread->contactID);
|
||||
// should be name number for now - easier to handle
|
||||
setTitle(ret->front().number);
|
||||
setTitle(ret->front().getFormattedName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user