TizenRefApp-7040 Discard pop-up missing when canceling group creation 83/87283/6
authorNataliia Sydorchuk <n.sydorchuk@samsung.com>
Thu, 8 Sep 2016 10:08:42 +0000 (13:08 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 8 Sep 2016 13:48:09 +0000 (06:48 -0700)
Change-Id: I4a7d268f377923b1b8c06725752fe6490a7f6525
Signed-off-by: Nataliia Sydorchuk <n.sydorchuk@samsung.com>
lib-apps-common/inc/Model2/DataItem.h
lib-apps-common/src/Model2/DataItem.cpp
lib-contacts/inc/Contacts/Groups/InputView.h
lib-contacts/inc/Contacts/Groups/Model/Group.h
lib-contacts/src/Contacts/Groups/InputView.cpp
lib-contacts/src/Contacts/Groups/MembersListView.cpp
lib-contacts/src/Contacts/Groups/Model/Group.cpp

index dd92e70..668d258 100644 (file)
@@ -51,6 +51,7 @@ namespace Model2
                typedef std::function<void()> DeleteCallback;
 
                DataItem();
+               DataItem(const DataItem &);
                virtual ~DataItem() { }
 
                /**
index faf0d47..67bf21d 100644 (file)
@@ -24,6 +24,11 @@ DataItem::DataItem()
 {
 }
 
+DataItem::DataItem(const DataItem &that)
+       : DataItem()
+{
+}
+
 void DataItem::update(void *data)
 {
        m_Changes |= onUpdate(data);
index a512ddc..1c40a35 100644 (file)
@@ -50,15 +50,19 @@ namespace Contacts
                private:
                        virtual Evas_Object *onCreate(Evas_Object *parent) override;
                        virtual void onPageAttached(Ui::NavigatorPage *page) override;
+                       virtual bool onBackPressed() override;
 
                        void onCancelPressed(Evas_Object *button, void *eventInfo);
                        void onDonePressed(Evas_Object *button, void *eventInfo);
                        void onNameFilled(bool isFilled);
+                       bool onCancel();
 
+                       void createCancelPopup();
                        void save();
                        void getGroupMembers();
 
                        Model::Group m_Group;
+                       Model::Group m_InitialGroup;
                        std::vector<int> m_GroupMembers;
 
                        Evas_Object *m_DoneButton;
index 39d9959..1f4028b 100644 (file)
@@ -55,6 +55,12 @@ namespace Contacts
                                 * @param[in]   record  _contacts_group record
                                 */
                                explicit Group(contacts_record_h record);
+
+                               /**
+                                * @brief Create group object
+                                * @param[in]   that    Group that will be copied
+                                */
+                               Group(const Group &that);
                                virtual ~Group() override;
 
                                /**
@@ -105,6 +111,12 @@ namespace Contacts
                                 */
                                bool operator<(const Group &that) const;
 
+                               /**
+                                * @brief Compares group's values
+                                * @return True if name, ringtone path and members count are equal to @a that, otherwise false
+                                */
+                               bool operator==(const Group &that) const;
+
                        private:
                                friend class GroupsProvider;
                                const Utils::UniString &getSortValue() const;
index ce94a18..5f4a914 100644 (file)
@@ -18,7 +18,6 @@
 #include "Contacts/Groups/InputView.h"
 
 #include "Contacts/Groups/AddMembersItem.h"
-#include "Contacts/Groups/Model/Group.h"
 #include "Contacts/Groups/Model/Queries.h"
 #include "Contacts/Groups/NameItem.h"
 #include "Contacts/Groups/RingtoneItem.h"
@@ -29,6 +28,7 @@
 #include "Common/Database/RecordIterator.h"
 #include "Common/Database/RecordUtils.h"
 #include "Ui/Genlist.h"
+#include "Ui/Popup.h"
 #include "Utils/Callback.h"
 
 #include <algorithm>
@@ -40,7 +40,7 @@ using namespace Contacts::Groups;
 using namespace Contacts::Groups::Model;
 
 InputView::InputView(int id)
-       : m_Group(id), m_DoneButton(nullptr), m_Genlist(nullptr),
+       : m_Group(id), m_InitialGroup(m_Group), m_DoneButton(nullptr), m_Genlist(nullptr),
          m_AddMembersItem(nullptr)
 {
 }
@@ -77,9 +77,16 @@ void InputView::onPageAttached(Ui::NavigatorPage *page)
        page->setTitle("IDS_PB_HEADER_CREATE");
 }
 
+bool InputView::onBackPressed()
+{
+       return onCancel();
+}
+
 void InputView::onCancelPressed(Evas_Object *button, void *eventInfo)
 {
-       getPage()->close();
+       if (onCancel()) {
+               getPage()->close();
+       }
 }
 
 void InputView::onDonePressed(Evas_Object *button, void *eventInfo)
@@ -97,6 +104,44 @@ void InputView::onNameFilled(bool isFilled)
        elm_object_disabled_set(m_DoneButton, !isFilled);
 }
 
+bool InputView::onCancel()
+{
+       if (m_InitialGroup == m_Group) {
+               bool hasMembersChanged = false;
+               for (auto &&personId : m_AddMembersItem->getMembers()) {
+                       auto it = std::find_if(m_GroupMembers.begin(), m_GroupMembers.end(), [personId](int id) {
+                               return personId == id;
+                       });
+
+                       if (it == m_GroupMembers.end()) {
+                               hasMembersChanged = true;
+                               break;
+                       }
+               }
+               if (!hasMembersChanged) {
+                       return true;
+               }
+       }
+
+       createCancelPopup();
+       return false;
+}
+
+void InputView::createCancelPopup()
+{
+       Ui::Popup *popup = new Ui::Popup();
+       popup->create(getEvasObject());
+       popup->setTitle("IDS_PB_HEADER_DISCARD_CHANGES_ABB");
+       popup->setText("IDS_PB_POP_ALL_CHANGES_WILL_BE_DISCARDED");
+
+       popup->addButton("IDS_PB_BUTTON_CANCEL");
+       popup->addButton("IDS_PB_BUTTON_DISCARD_ABB", [this] {
+               getPage()->close();
+               return true;
+       });
+       popup->show();
+}
+
 void InputView::save()
 {
        int groupId = m_Group.save();
index e42923c..8ac07eb 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "Contacts/Common/ContactSelectTypes.h"
 #include "Contacts/Groups/InputView.h"
-#include "Contacts/Groups/Model/Group.h"
 #include "Contacts/Groups/Model/MembersProvider.h"
 
 #include "App/AppControlRequest.h"
index 6ab8584..9e0aa0c 100644 (file)
@@ -53,6 +53,13 @@ Group::Group(contacts_record_h record)
        m_MembersCount = Model::getMembersCount(getId());
 }
 
+Group::Group(const Group &that)
+       : m_DbVersion(0), m_Type(that.m_Type), m_SortValue(that.m_SortValue),
+         m_MembersCount(that.m_MembersCount)
+{
+       contacts_record_clone(that.m_Record, &m_Record);
+}
+
 Group::~Group()
 {
        if (isStandalone()) {
@@ -138,6 +145,13 @@ bool Group::operator<(const Group &that) const
        return getSortValue() < that.getSortValue();
 }
 
+bool Group::operator==(const Group &that) const
+{
+       return (compareRecordsStr(m_Record, that.m_Record, _contacts_group.name)
+                       && compareRecordsStr(m_Record, that.m_Record, _contacts_group.ringtone_path)
+                       && (getMembersCount() == that.getMembersCount()));
+}
+
 const Utils::UniString &Group::getSortValue() const
 {
        if (m_SortValue.getI18nStr().empty()) {