From 8dccfeef72f47319bff50fb9b3f3c6a97fc57c66 Mon Sep 17 00:00:00 2001 From: rrandomsky Date: Tue, 17 Oct 2023 13:30:25 +0200 Subject: [PATCH] [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. --- .../models/NewContactModel.cpp | 15 +++++++++++++++ .../models/NewContactModel.hpp | 1 + .../widgets/InputLinesWithLabelWidget.cpp | 5 +++++ .../widgets/InputLinesWithLabelWidget.hpp | 2 ++ .../windows/PhonebookNewContact.cpp | 8 ++++---- module-db/Interface/ContactRecord.cpp | 11 ++++++++--- pure_changelog.md | 1 + 7 files changed, 36 insertions(+), 7 deletions(-) diff --git a/module-apps/application-phonebook/models/NewContactModel.cpp b/module-apps/application-phonebook/models/NewContactModel.cpp index 667e8290e863937acabc94decf1920959491263f..45a671b62097a1f0b5df0c9958ad8f59df44103a 100644 --- a/module-apps/application-phonebook/models/NewContactModel.cpp +++ b/module-apps/application-phonebook/models/NewContactModel.cpp @@ -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(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; diff --git a/module-apps/application-phonebook/models/NewContactModel.hpp b/module-apps/application-phonebook/models/NewContactModel.hpp index 6e2304615d77e9f27be6feb4d5e69999fb995020..2bacf396c0bedeb7f877edc34d5bdd4efbcc9d93 100644 --- a/module-apps/application-phonebook/models/NewContactModel.hpp +++ b/module-apps/application-phonebook/models/NewContactModel.hpp @@ -28,6 +28,7 @@ class NewContactModel : public app::InternalModel, publi void createData(); bool verifyData(); bool emptyData(); + bool readyToSave(); bool isAnyUnsavedChange(std::shared_ptr contactRecord); [[nodiscard]] auto getRequestType() -> PhonebookItemData::RequestType; diff --git a/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.cpp b/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.cpp index 192847188e036c6fd2c475c9433ad05904a32ff4..6e76eeeabf3db00ad2efcd25543aa8cd328548dc 100644 --- a/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.cpp +++ b/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.cpp @@ -117,6 +117,11 @@ namespace gui setEdges(RectangleEdge::None); } + auto InputLinesWithLabelWidget::getListItemName() -> phonebookInternals::ListItemName + { + return listItemName; + } + void InputLinesWithLabelWidget::applyItemNameSpecificSettings() { switch (listItemName) { diff --git a/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.hpp b/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.hpp index 17488f3aa7eebe6d1e8ed70e97d535461b0f684a..91e32ef61600800ac4979a9a7815c66fbc917050 100644 --- a/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.hpp +++ b/module-apps/application-phonebook/widgets/InputLinesWithLabelWidget.hpp @@ -30,6 +30,8 @@ namespace gui Label *titleLabel = nullptr; TextFixedSize *inputText = nullptr; + auto getListItemName() -> phonebookInternals::ListItemName; + private: phonebookInternals::ListItemName listItemName; void applyItemNameSpecificSettings(); diff --git a/module-apps/application-phonebook/windows/PhonebookNewContact.cpp b/module-apps/application-phonebook/windows/PhonebookNewContact.cpp index 4bfb55b9a58ad46aeff75fdc0749bd97538032ee..6628b446ac758218797e553d5e5eebe6c01fbb3b 100644 --- a/module-apps/application-phonebook/windows/PhonebookNewContact.cpp +++ b/module-apps/application-phonebook/windows/PhonebookNewContact.cpp @@ -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]() { diff --git a/module-db/Interface/ContactRecord.cpp b/module-db/Interface/ContactRecord.cpp index d390511322a20e228d9362c812c58d9b46f21b0e..d62eba1d08fe749e1fdbfa847b3fafa2da29564d 100644 --- a/module-db/Interface/ContactRecord.cpp +++ b/module-db/Interface/ContactRecord.cpp @@ -1579,11 +1579,16 @@ auto ContactRecordInterface::matchedNumberRefersToTemporary(const ContactNumberH auto ContactRecordInterface::changeNumberRecordInPlaceIfCountryCodeIsOnlyDifferent( const std::vector &oldNumberIDs, std::vector &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"); diff --git a/pure_changelog.md b/pure_changelog.md index f18997b71da9d956e8968266efa7b3b0ad1c2c6e..47cfa5d274ae0cc8c8ed640ab2fcf2d08d4029b9 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -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]