From: Eugene Kurzberg Date: Thu, 17 Mar 2016 07:43:31 +0000 (+0200) Subject: Added possibility to store additional selection result in SelectItem. X-Git-Tag: submit/tizen/20160524.113145~109^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd9810566b4176259f33495bf968488fca942c8b;p=profile%2Fmobile%2Fapps%2Fnative%2Fphone-contacts.git Added possibility to store additional selection result in SelectItem. Added possibility to control items checking in SelectView from outside. Change-Id: I583939d512f9a86e8bcf7e0eacd7c5312495a369 Signed-off-by: Eugene Kurzberg --- diff --git a/lib-common/inc/Contacts/SelectItem.h b/lib-common/inc/Contacts/SelectItem.h index ec8d332..198e267 100644 --- a/lib-common/inc/Contacts/SelectItem.h +++ b/lib-common/inc/Contacts/SelectItem.h @@ -41,11 +41,26 @@ namespace Contacts */ void setSelectMode(SelectMode selectMode); - protected: /** * @return Selection result associated with the item. */ - virtual SelectResult getSelectResult() const = 0; + SelectResult getSelectResult() const; + + /** + * @brief Set custom selection result to override the default result. + */ + void setCustomResult(SelectResult result); + + /** + * @brief Unset custom selection result to use default result. + */ + void unsetCustomResult(); + + protected: + /** + * @return Default selection result associated with the item. + */ + virtual SelectResult getDefaultResult() const = 0; /** * @see GenlistItem::getContent() @@ -67,6 +82,8 @@ namespace Contacts friend class SelectView; SelectMode m_SelectMode; + SelectResult m_CustomResult; + bool m_HasCustomResult; }; } diff --git a/lib-common/inc/Contacts/SelectTypes.h b/lib-common/inc/Contacts/SelectTypes.h index caeabc7..e3d7273 100644 --- a/lib-common/inc/Contacts/SelectTypes.h +++ b/lib-common/inc/Contacts/SelectTypes.h @@ -51,7 +51,7 @@ namespace Contacts /** * @brief Range of consecutive selection results. */ - typedef Utils::Range SelectResults; + typedef Utils::Range SelectResults; /** * @brief Callback to be called when selection is done. diff --git a/lib-common/inc/Contacts/SelectView.h b/lib-common/inc/Contacts/SelectView.h index b27b67d..8c28f83 100644 --- a/lib-common/inc/Contacts/SelectView.h +++ b/lib-common/inc/Contacts/SelectView.h @@ -40,6 +40,15 @@ namespace Contacts class EXPORT_API SelectView : public Ui::View { public: + /** + * @brief Called when item's "checked" state changed in #SelectMulti mode. + * @remark Use SelectView::setCheckCallback() to properly change item's state + * if necessary. + * @param[in] Changed item + * @param[in] Whether item is checked + */ + typedef std::function CheckCallback; + SelectView(); /** @@ -60,6 +69,21 @@ namespace Contacts */ void setSelectCallback(SelectCallback callback); + /** + * @brief Set item check callback. + * @param[in] callback Check callback + */ + void setCheckCallback(CheckCallback callback); + + /** + * @brief Set item's "checked" state. + * @remark Item "checked" state should always be changed via this function, + * otherwise SelectView wouldn't know to update the select count. + * @param[in] item Item to change state for + * @param[in] isChecked Whether item should be checked + */ + void setCheckedItem(SelectItem *item, bool isChecked); + protected: /** * @return View selection mode. @@ -67,7 +91,7 @@ namespace Contacts SelectMode getSelectMode() const; /** - * @return Current seleciton limit. + * @return Current selection limit. */ size_t getSelectLimit() const; @@ -167,6 +191,7 @@ namespace Contacts SelectMode m_SelectMode; SelectCallback m_OnSelected; + CheckCallback m_OnChecked; }; } diff --git a/lib-common/src/Contacts/SelectItem.cpp b/lib-common/src/Contacts/SelectItem.cpp index 70a25ec..a9bf36f 100644 --- a/lib-common/src/Contacts/SelectItem.cpp +++ b/lib-common/src/Contacts/SelectItem.cpp @@ -20,7 +20,7 @@ using namespace Contacts; SelectItem::SelectItem() - : m_SelectMode(SelectNone) + : m_SelectMode(SelectNone), m_CustomResult{ 0, 0 }, m_HasCustomResult(false) { } @@ -37,6 +37,22 @@ void SelectItem::setSelectMode(SelectMode selectMode) onSelectModeChanged(m_SelectMode); } +SelectResult SelectItem::getSelectResult() const +{ + return m_HasCustomResult ? m_CustomResult : getDefaultResult(); +} + +void SelectItem::setCustomResult(SelectResult result) +{ + m_CustomResult = result; + m_HasCustomResult = true; +} + +void SelectItem::unsetCustomResult() +{ + m_HasCustomResult = false; +} + Evas_Object *SelectItem::getContent(Evas_Object *parent, const char *part) { if (m_SelectMode == SelectMulti) { diff --git a/lib-common/src/Contacts/SelectView.cpp b/lib-common/src/Contacts/SelectView.cpp index 871f013..dd8c051 100644 --- a/lib-common/src/Contacts/SelectView.cpp +++ b/lib-common/src/Contacts/SelectView.cpp @@ -78,6 +78,17 @@ void SelectView::setSelectCallback(SelectCallback callback) m_OnSelected = std::move(callback); } +void SelectView::setCheckCallback(CheckCallback callback) +{ + m_OnChecked = std::move(callback); +} + +void SelectView::setCheckedItem(SelectItem *item, bool isChecked) +{ + item->setChecked(isChecked); + updateSelectCount(isChecked ? CountIncrement : CountDecrement); +} + SelectMode SelectView::getSelectMode() const { return m_SelectMode; @@ -290,6 +301,10 @@ bool SelectView::onItemChecked(SelectItem *item, bool isChecked) return false; } + if (m_OnChecked && !m_OnChecked(item, isChecked)) { + return false; + } + updateSelectCount(isChecked ? CountIncrement : CountDecrement); return true; } diff --git a/lib-contact/inc/Contacts/Details/FieldItem.h b/lib-contact/inc/Contacts/Details/FieldItem.h index 8c3153b..c0784eb 100644 --- a/lib-contact/inc/Contacts/Details/FieldItem.h +++ b/lib-contact/inc/Contacts/Details/FieldItem.h @@ -74,7 +74,7 @@ namespace Contacts /** * @see SelectItem::getSelectResult() */ - virtual SelectResult getSelectResult() const override; + virtual SelectResult getDefaultResult() const override; /** * @see ContactField::UpdatedCallback diff --git a/lib-contact/inc/Contacts/List/PersonItem.h b/lib-contact/inc/Contacts/List/PersonItem.h index d97f043..da9c533 100644 --- a/lib-contact/inc/Contacts/List/PersonItem.h +++ b/lib-contact/inc/Contacts/List/PersonItem.h @@ -53,7 +53,7 @@ namespace Contacts private: virtual char *getText(Evas_Object *parent, const char *part) override; virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override; - virtual SelectResult getSelectResult() const override; + virtual SelectResult getDefaultResult() const override; Model::Person &m_Person; }; diff --git a/lib-contact/src/Contacts/Details/FieldItem.cpp b/lib-contact/src/Contacts/Details/FieldItem.cpp index 78f3b60..f81c4b4 100644 --- a/lib-contact/src/Contacts/Details/FieldItem.cpp +++ b/lib-contact/src/Contacts/Details/FieldItem.cpp @@ -89,7 +89,7 @@ Evas_Object *FieldItem::getContent(Evas_Object *parent, const char *part) return nullptr; } -SelectResult FieldItem::getSelectResult() const +SelectResult FieldItem::getDefaultResult() const { return { m_Object.getSubType(), m_Object.getRecordId() }; } diff --git a/lib-contact/src/Contacts/List/PersonItem.cpp b/lib-contact/src/Contacts/List/PersonItem.cpp index df4dc45..e045f0f 100644 --- a/lib-contact/src/Contacts/List/PersonItem.cpp +++ b/lib-contact/src/Contacts/List/PersonItem.cpp @@ -60,7 +60,7 @@ Evas_Object *PersonItem::getContent(Evas_Object *parent, const char *part) return nullptr; } -SelectResult PersonItem::getSelectResult() const +SelectResult PersonItem::getDefaultResult() const { return { ResultPerson, m_Person.getId() }; } diff --git a/lib-logs/inc/Logs/Details/LogDetailItem.h b/lib-logs/inc/Logs/Details/LogDetailItem.h index 08752c6..535e249 100644 --- a/lib-logs/inc/Logs/Details/LogDetailItem.h +++ b/lib-logs/inc/Logs/Details/LogDetailItem.h @@ -43,7 +43,7 @@ namespace Logs virtual char *getText(Evas_Object *parent, const char *part) override; virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override; virtual void onSelectModeChanged(Contacts::SelectMode selectMode) override; - virtual Contacts::SelectResult getSelectResult() const override; + virtual Contacts::SelectResult getDefaultResult() const override; static Evas_Object *createIcon(Evas_Object *parent, const char *path); static const char *getImagePath(int type); diff --git a/lib-logs/inc/Logs/List/LogItem.h b/lib-logs/inc/Logs/List/LogItem.h index bf081af..964b181 100644 --- a/lib-logs/inc/Logs/List/LogItem.h +++ b/lib-logs/inc/Logs/List/LogItem.h @@ -70,7 +70,7 @@ namespace Logs private: virtual char *getText(Evas_Object *parent, const char *part) override; virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override; - virtual Contacts::SelectResult getSelectResult() const override; + virtual Contacts::SelectResult getDefaultResult() const override; Evas_Object *createThumbnail(Evas_Object *parent); Evas_Object *createLayout(Evas_Object *parent, const char *layoutName); diff --git a/lib-logs/src/Logs/Details/LogDetailItem.cpp b/lib-logs/src/Logs/Details/LogDetailItem.cpp index f971ce6..c7a182d 100644 --- a/lib-logs/src/Logs/Details/LogDetailItem.cpp +++ b/lib-logs/src/Logs/Details/LogDetailItem.cpp @@ -81,7 +81,7 @@ void LogDetailItem::onSelectModeChanged(SelectMode selectMode) } } -SelectResult LogDetailItem::getSelectResult() const +SelectResult LogDetailItem::getDefaultResult() const { return { 0, m_Log }; } diff --git a/lib-logs/src/Logs/List/LogItem.cpp b/lib-logs/src/Logs/List/LogItem.cpp index c9ee5d1..0232d20 100644 --- a/lib-logs/src/Logs/List/LogItem.cpp +++ b/lib-logs/src/Logs/List/LogItem.cpp @@ -133,7 +133,7 @@ Evas_Object *LogItem::getContent(Evas_Object *parent, const char *part) return nullptr; } -SelectResult LogItem::getSelectResult() const +SelectResult LogItem::getDefaultResult() const { return { 0, m_Group }; }