Files
MuditaOS/module-apps/application-call/windows/EnterNumberWindow.hpp
T
Marcin Smoczyński c47923d70a [EGD-3107] Call number validation
Use specialized class to to pass phone number between apps and services
instead of ambigious std::string. Introduced class (utils::PhoneNumber)
wraps calls to libphonenumber providing more convienient interface.
However using libphonenumber directly may be resource hungry in terms
of stack, heap and cpu usage, so helper class has been introduced to
pass information about phone numbers (utils::PhoneNumber::View). It is
designed to maintain integrity thus can be created from an instance of
utils::PhoneNumber only or moved/copied to.

Add new field to the calllog db holding e164 formatted number. Both
entered and e164 numbers will be needed to be able to match with
contacts correctly.

Add constexpr information about country codes (utils::country).
2020-05-05 00:51:53 +02:00

78 lines
2.2 KiB
C++

/*
* @file EnterNumberWindow.hpp
* @author Robert Borzecki (robert.borzecki@mudita.com)
* @date 1 lip 2019
* @brief
* @copyright Copyright (C) 2019 mudita.com
* @details
*/
#pragma once
#include "../ApplicationCall.hpp"
#include "../widgets/Icons.hpp"
#include <Application.hpp>
#include <AppWindow.hpp>
#include <ContactRecord.hpp>
#include <country.hpp>
#include <gui/input/Translator.hpp>
#include <gui/widgets/BottomBar.hpp>
#include <gui/widgets/Image.hpp>
#include <gui/widgets/Label.hpp>
#include <gui/widgets/TopBar.hpp>
#include <gui/widgets/Window.hpp>
#include <phonenumbers/phonenumberutil.h>
#include <phonenumbers/asyoutypeformatter.h>
#include <memory>
#include <string>
namespace gui
{
class EnterNumberWindow : public AppWindow
{
public:
using CountryCode = utils::country::Id;
private:
using PhoneNumberUtil = i18n::phonenumbers::PhoneNumberUtil;
using Formatter = i18n::phonenumbers::AsYouTypeFormatter;
protected:
gui::Label *numberLabel = nullptr;
gui::AddContactIcon *newContactIcon = nullptr;
void setNumberLabel(const std::string num);
public:
EnterNumberWindow() = delete;
EnterNumberWindow(app::Application *app, std::string windowName = app::window::name_enterNumber);
virtual ~EnterNumberWindow();
bool onInput(const InputEvent &inputEvent) override;
bool handleSwitchData(SwitchData *data) override;
const std::string &getEnteredNumber() const noexcept;
void rebuild() override;
void buildInterface() override;
void destroyInterface() override;
private:
CountryCode defaultCountry = utils::country::defaultCountry;
CountryCode currentCountry;
gui::KeyInputMappedTranslation translator;
PhoneNumberUtil &numberUtil;
std::unique_ptr<Formatter> formatter;
std::string formattedNumber;
std::string enteredNumber;
bool addNewContact();
void switchFormatter(const std::string &countryCode);
void initFormatterInput(const std::string &number);
void addDigit(const std::string::value_type &digit);
void clearInput();
};
} /* namespace gui */