~aleteoryx/muditaos

8dccfeef72f47319bff50fb9b3f3c6a97fc57c66 — rrandomsky 2 years ago d9a1194
[MOS-1042] Fixed inability to save a contact that did not previously have a phone number

Fixed inability to save a contact without a phone number
when contact lose the number after replace similar number and
visibility of the SAVE button when editing/creating a contact.
M module-apps/application-phonebook/models/NewContactModel.cpp => module-apps/application-phonebook/models/NewContactModel.cpp +15 -0
@@ 225,6 225,21 @@ bool NewContactModel::emptyData()
    return true;
}

bool NewContactModel::readyToSave()
{
    // The contact model is ready to be saved when any of the phone number fields are not empty
    for (const auto &item : internalData) {
        if (auto itemWidget = dynamic_cast<gui::InputLinesWithLabelWidget *>(item); itemWidget != nullptr) {
            if (auto typeOfItem = itemWidget->getListItemName();
                (typeOfItem == phonebookInternals::ListItemName::Number ||
                 typeOfItem == phonebookInternals::ListItemName::SecondNumber) &&
                itemWidget->onEmptyCallback && !itemWidget->onEmptyCallback()) {
                return false;
            }
        }
    }
    return true;
}
[[nodiscard]] auto NewContactModel::getRequestType() -> PhonebookItemData::RequestType
{
    return requestType;

M module-apps/application-phonebook/models/NewContactModel.hpp => module-apps/application-phonebook/models/NewContactModel.hpp +1 -0
@@ 28,6 28,7 @@ class NewContactModel : public app::InternalModel<gui::ContactListItem *>, publi
    void createData();
    bool verifyData();
    bool emptyData();
    bool readyToSave();
    bool isAnyUnsavedChange(std::shared_ptr<ContactRecord> contactRecord);
    [[nodiscard]] auto getRequestType() -> PhonebookItemData::RequestType;


M module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.cpp => module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.cpp +5 -0
@@ 117,6 117,11 @@ namespace gui
        setEdges(RectangleEdge::None);
    }

    auto InputLinesWithLabelWidget::getListItemName() -> phonebookInternals::ListItemName
    {
        return listItemName;
    }

    void InputLinesWithLabelWidget::applyItemNameSpecificSettings()
    {
        switch (listItemName) {

M module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.hpp => module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.hpp +2 -0
@@ 30,6 30,8 @@ namespace gui
        Label *titleLabel        = nullptr;
        TextFixedSize *inputText = nullptr;

        auto getListItemName() -> phonebookInternals::ListItemName;

      private:
        phonebookInternals::ListItemName listItemName;
        void applyItemNameSpecificSettings();

M module-apps/application-phonebook/windows/PhonebookNewContact.cpp => module-apps/application-phonebook/windows/PhonebookNewContact.cpp +4 -4
@@ 74,7 74,7 @@ namespace gui
            break;
        }

        setSaveButtonVisible(!newContactModel->emptyData());
        setSaveButtonVisible(!newContactModel->readyToSave());
    }

    void PhonebookNewContact::onClose(Window::CloseReason reason)


@@ 138,8 138,6 @@ namespace gui

    auto PhonebookNewContact::onInput(const InputEvent &inputEvent) -> bool
    {
        setSaveButtonVisible(!newContactModel->emptyData());

        if (inputEvent.isShortRelease(gui::KeyCode::KEY_ENTER) && !newContactModel->emptyData() &&
            newContactModel->verifyData()) {
            auto tmpId  = contact->ID;


@@ 160,7 158,9 @@ namespace gui
                    return true;
                }
            }
            return AppWindow::onInput(inputEvent);
            auto retunrVal = AppWindow::onInput(inputEvent);
            setSaveButtonVisible(!newContactModel->readyToSave());
            return retunrVal;
        }

        auto returnWhenCurrentAppShouldBeIgnoredOnSwitchBack = [this]() {

M module-db/Interface/ContactRecord.cpp => module-db/Interface/ContactRecord.cpp +8 -3
@@ 1579,11 1579,16 @@ auto ContactRecordInterface::matchedNumberRefersToTemporary(const ContactNumberH
auto ContactRecordInterface::changeNumberRecordInPlaceIfCountryCodeIsOnlyDifferent(
    const std::vector<std::uint32_t> &oldNumberIDs, std::vector<ContactRecord::Number> &newNumbers) -> bool
{
    if (oldNumberIDs.empty() || newNumbers.empty()) {
        LOG_ERROR("Failed to change number record in place if country code is only different. "
                  "Empty input data.");
    if (newNumbers.empty()) {
        LOG_ERROR("Cannot to change number record in place if country code is only different. "
                  "Empty new number data");
        return false;
    }
    if (oldNumberIDs.empty()) {
        LOG_WARN("Cannot to change number record in place if country code is only different. "
                 "Empty old number data.");
        return true;
    }
    for (const auto id : oldNumberIDs) {
        if (id == 0)
            LOG_WARN("Number ID == 0");

M pure_changelog.md => pure_changelog.md +1 -0
@@ 40,6 40,7 @@
* Fixed crash on transferring audio file with big metadata.
* Fixed possibility of OS crash during update package size check.
* Fixed cut off VoLTE checking label in some languages.
* Fixed inability to save a contact that did not previously have a phone number

## [1.8.0 2023-09-27]