diff options
author | Denis Dolzhenko <d.dolzhenko@samsung.com> | 2017-03-28 16:13:56 +0300 |
---|---|---|
committer | Denis Dolzhenko <d.dolzhenko@samsung.com> | 2017-03-28 16:25:21 +0300 |
commit | 43270a33a8ad71a7890750ed3ead615cebd48a5b (patch) | |
tree | bbfeb903ccc79938c26a4645fd1d169e0955ccfd | |
parent | c30ed5c9a61cfcc7d9cb7ac3ff9bd25269bc7ff0 (diff) | |
download | message-43270a33a8ad71a7890750ed3ead615cebd48a5b.tar.gz message-43270a33a8ad71a7890750ed3ead615cebd48a5b.tar.bz2 message-43270a33a8ad71a7890750ed3ead615cebd48a5b.zip |
TizenRefApp-8259 Implement deletion of ConvListItem in conversation list.
Update ThreadList class.
Move getCheckedItemsCount(), getCheckableItemsCount() to ListView.
Change-Id: I878eca9cdb74ef60fc28653f745810a2dd993bee
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
-rw-r--r-- | src/Common/MsgEngine/src/dummy/MsgStorageDummy.cpp | 8 | ||||
-rw-r--r-- | src/Common/View/inc/ListItem.h | 8 | ||||
-rw-r--r-- | src/Common/View/inc/ListView.h | 16 | ||||
-rw-r--r-- | src/Common/View/src/ListItem.cpp | 3 | ||||
-rw-r--r-- | src/Common/View/src/ListView.cpp | 40 | ||||
-rw-r--r-- | src/Conversation/Controller/inc/ConvFrame.h | 4 | ||||
-rw-r--r-- | src/Conversation/Controller/inc/ConvList.h | 5 | ||||
-rw-r--r-- | src/Conversation/Controller/src/ConvFrame.cpp | 36 | ||||
-rw-r--r-- | src/Conversation/Controller/src/ConvList.cpp | 34 | ||||
-rw-r--r-- | src/Conversation/View/inc/ConvListViewItem.h | 5 | ||||
-rw-r--r-- | src/Conversation/View/src/ConvListViewItem.cpp | 17 | ||||
-rw-r--r-- | src/MsgThread/Controller/inc/ThreadList.h | 4 | ||||
-rw-r--r-- | src/MsgThread/Controller/src/MsgThreadFrame.cpp | 8 | ||||
-rw-r--r-- | src/MsgThread/Controller/src/ThreadList.cpp | 30 | ||||
-rw-r--r-- | src/MsgThread/View/inc/ThreadListViewItem.h | 1 | ||||
-rw-r--r-- | src/MsgThread/View/src/ThreadListViewItem.cpp | 5 |
16 files changed, 152 insertions, 72 deletions
diff --git a/src/Common/MsgEngine/src/dummy/MsgStorageDummy.cpp b/src/Common/MsgEngine/src/dummy/MsgStorageDummy.cpp index ec48375..46a2371 100644 --- a/src/Common/MsgEngine/src/dummy/MsgStorageDummy.cpp +++ b/src/Common/MsgEngine/src/dummy/MsgStorageDummy.cpp @@ -90,7 +90,7 @@ MsgThreadItemRef MsgStorageDummy::getThread(ThreadId id) bool MsgStorageDummy::deleteThread(ThreadId id) { - return false; + return true; } MsgConversationListRef MsgStorageDummy::getConversationList(ThreadId id) @@ -117,7 +117,7 @@ MessageRef MsgStorageDummy::getMessage(MsgId id) MsgId MsgStorageDummy::saveMessage(Message &msg, bool updateExisting, StorageResult *result) { if (result) - *result = StorageFail; + *result = StorageSuccess; MsgId newMsgId; return newMsgId; @@ -125,12 +125,12 @@ MsgId MsgStorageDummy::saveMessage(Message &msg, bool updateExisting, StorageRes bool MsgStorageDummy::deleteMessage(MsgId id) { - return false; + return true; } bool MsgStorageDummy::deleteMessages(const MsgIdList &idList) { - return false; + return true; } MessageListRef MsgStorageDummy::searchMessage(const std::string &word) diff --git a/src/Common/View/inc/ListItem.h b/src/Common/View/inc/ListItem.h index 1daebf5..a7d2632 100644 --- a/src/Common/View/inc/ListItem.h +++ b/src/Common/View/inc/ListItem.h @@ -158,7 +158,7 @@ namespace Msg * @param[in] state a new checked-state to be applied. * @param[in] updateUi if true all list-item's content will be forced to update. */ - void setCheckedState(bool state, bool updateUi); + virtual void setCheckedState(bool state, bool updateUi); /** * @brief Checks whether list- item is checked or not. @@ -167,10 +167,10 @@ namespace Msg bool getCheckedState() const; /** - * @brief Checks whether checkbox was created and put into specific list-item's part. - * @return true if checkbox is created and available to manage, false otherwise. + * @brief Checks whether item is Checkable + * @return true if checkable, false otherwise. */ - bool isCheckable() const; + virtual bool isCheckable() const; /** * @brief Compare two items diff --git a/src/Common/View/inc/ListView.h b/src/Common/View/inc/ListView.h index 89d52e6..5483da0 100644 --- a/src/Common/View/inc/ListView.h +++ b/src/Common/View/inc/ListView.h @@ -229,9 +229,9 @@ namespace Msg /** * @brief Checks(unchecks) all list-view items in selection mode and updates realized items. * @param[in] check if true all items will be checked, if false - unchecks all items. - * @param[in] updateFullItem if false only check part will be updated, if true whole item will be updated. + * @param[in] updateUi if true Ui will be forced update. */ - void checkAllItems(bool check, bool updateFullItem = false); + void checkAllItems(bool check, bool updateUi = true); /** @@ -250,6 +250,18 @@ namespace Msg unsigned getItemsCount() const; /** + * @brief Gets all checked items count. + * @return count of checked items. + */ + unsigned getCheckedItemsCount() const; + + /** + * @brief Gets all checkable items count. + * @return count of checkable items. + */ + unsigned getCheckableItemsCount() const; + + /** * @brief Updates the contents of all realized items. */ void updateRealizedItems(); diff --git a/src/Common/View/src/ListItem.cpp b/src/Common/View/src/ListItem.cpp index 46ae4a0..20b31c5 100644 --- a/src/Common/View/src/ListItem.cpp +++ b/src/Common/View/src/ListItem.cpp @@ -190,8 +190,7 @@ bool ListItem::getCheckedState() const bool ListItem::isCheckable() const { - ListItem &self = const_cast<ListItem&>(*this); - return self.getCheckPart(self) != nullptr; + return false; } bool ListItem::isSame(const ListItem &item) const diff --git a/src/Common/View/src/ListView.cpp b/src/Common/View/src/ListView.cpp index f8b04ba..bd01246 100644 --- a/src/Common/View/src/ListView.cpp +++ b/src/Common/View/src/ListView.cpp @@ -287,22 +287,13 @@ bool ListView::getCheckMode() const return m_CheckMode; } -void ListView::checkAllItems(bool check, bool updateFullItem) +void ListView::checkAllItems(bool check, bool updateUi) { for (ListItem *item: getItems()) { if (item->isCheckable()) - item->setCheckedState(check, false); + item->setCheckedState(check, updateUi); } - - if (updateFullItem) - updateRealizedItems(); - else - for (ListItem *item: getRealizedItems()) - { - if (item->isCheckable()) - item->updateFields(item->getCheckPart(*item), ELM_GENLIST_ITEM_FIELD_ALL); - } } void ListView::updateRealizedItems() @@ -325,13 +316,34 @@ bool ListView::getMultiSelection() const return elm_genlist_multi_select_get(getEo()); } +unsigned ListView::getCheckedItemsCount() const +{ + unsigned count = 0; + auto items = getItems(); + for(auto *item : items) { + if (item->getCheckedState()) + ++count; + } + return count; +} + +unsigned ListView::getCheckableItemsCount() const +{ + unsigned count = 0; + auto items = getItems(); + for(auto *item : items) { + if (item->isCheckable()) + ++count; + } + return count; +} + void ListView::on_item_selected_cb(void *data, Evas_Object *obj, void *event_info) { ListItem *item = ListItem::staticCast<ListItem*>(event_info); - item->setSelected(false); - if (item->getOwner()->getCheckMode() && item->isCheckable()) - { + + if (item->getOwner()->getCheckMode() && item->isCheckable()) { item->changeCheckedState(true); notifyListener(data, obj, event_info, &IListViewListener::onListItemChecked); } else { diff --git a/src/Conversation/Controller/inc/ConvFrame.h b/src/Conversation/Controller/inc/ConvFrame.h index c69f6df..a768a50 100644 --- a/src/Conversation/Controller/inc/ConvFrame.h +++ b/src/Conversation/Controller/inc/ConvFrame.h @@ -71,6 +71,9 @@ namespace Msg void onSelectAllButtonClicked(CtxPopupItem &item); void onDeselectAllButtonClicked(CtxPopupItem &item); + // IConvListListener: + void onItemChecked(ConvListItem &item) override; + void onListChanged(ConvList &list) override; private: void prepareWorkingDir(); @@ -79,6 +82,7 @@ namespace Msg void prepareDeleteViews(); void prepareList(); void showSelectPopup(); + void updateDeleteViews(); void setMode(Mode mode); void setDeleteMode(bool value); diff --git a/src/Conversation/Controller/inc/ConvList.h b/src/Conversation/Controller/inc/ConvList.h index 235898e..5ee156c 100644 --- a/src/Conversation/Controller/inc/ConvList.h +++ b/src/Conversation/Controller/inc/ConvList.h @@ -43,7 +43,8 @@ namespace Msg { void setThreadId(ThreadId id); void setListener(IConvListListener *l); void setDeleteMode(bool value); - bool getDeleteMode() const; + bool isDeleteModeEnabled() const; + bool deleteCheckedItems(); private: typedef std::unordered_map<MsgId::Type, ConvListItem*> ConvListItemMap; @@ -64,7 +65,7 @@ namespace Msg { void clear(); private: - bool m_DeleteMode; + bool m_IsDeleteMode; ThreadId m_ThreadId; IConvListListener *m_pListener; PaddingListViewItem *m_pBottomPadItem; diff --git a/src/Conversation/Controller/src/ConvFrame.cpp b/src/Conversation/Controller/src/ConvFrame.cpp index ddff70e..ae53619 100644 --- a/src/Conversation/Controller/src/ConvFrame.cpp +++ b/src/Conversation/Controller/src/ConvFrame.cpp @@ -20,6 +20,7 @@ #include "SelectButton.h" #include "MoreOption.h" #include "SelectCtxPopup.h" +#include "ToastPopup.h" using namespace Msg; @@ -85,6 +86,7 @@ void ConvFrame::setDeleteMode(bool value) m_pLayout->showBottomButton(true); m_pLayout->showMoreOption(false); m_pList->setDeleteMode(true); + updateDeleteViews(); } } @@ -161,10 +163,8 @@ void ConvFrame::setThreadId(ThreadId id) void ConvFrame::showSelectPopup() { auto *ctx = new SelectCtxPopup; - - // TODO: remove hardcode - int checkedCount = 1; - int checkableCount = 2; + unsigned checkedCount = m_pList->getCheckedItemsCount(); + unsigned checkableCount = m_pList->getCheckableItemsCount(); if (checkedCount < checkableCount) ctx->appendTopItem(msg("WDS_MSG_OPT_SELECT_ALL_ABB"), makeCbLast(&ConvFrame::onSelectAllButtonClicked), this); @@ -177,6 +177,15 @@ void ConvFrame::showSelectPopup() ctx->go(); } +void ConvFrame::updateDeleteViews() +{ + if (m_Mode == DeleteMode) { + unsigned count = m_pList->getCheckedItemsCount(); + m_pSelectButton->setText(std::to_string(count)); + m_pDeleteButton->disabled(count == 0); + } +} + void ConvFrame::onAttached(ViewItem &item) { MSG_LOG(""); @@ -194,9 +203,24 @@ void ConvFrame::onHwBackButtonPreessed(Evas_Object *obj, void *event) pop(); } +void ConvFrame::onItemChecked(ConvListItem &item) +{ + MSG_LOG(""); + updateDeleteViews(); +} + +void ConvFrame::onListChanged(ConvList &list) +{ + MSG_LOG(""); + updateDeleteViews(); +} + void ConvFrame::onDelButtonClicked(Evas_Object *obj, void *event) { MSG_LOG(""); + if (m_pList->deleteCheckedItems()) + ToastPopup::toast(msgt("WDS_ALM_TPOP_DELETED_ABB"), DELETEG_MORE_ICON); + setMode(NormalMode); } void ConvFrame::onSelectButtonClicked(Evas_Object *obj, void *event) @@ -208,11 +232,15 @@ void ConvFrame::onSelectButtonClicked(Evas_Object *obj, void *event) void ConvFrame::onSelectAllButtonClicked(CtxPopupItem &item) { MSG_LOG(""); + m_pList->checkAllItems(true); + updateDeleteViews(); } void ConvFrame::onDeselectAllButtonClicked(CtxPopupItem &item) { MSG_LOG(""); + m_pList->checkAllItems(false); + updateDeleteViews(); } void ConvFrame::onReplyClicked(MoreOption &obj) diff --git a/src/Conversation/Controller/src/ConvList.cpp b/src/Conversation/Controller/src/ConvList.cpp index 4d14320..31a868d 100644 --- a/src/Conversation/Controller/src/ConvList.cpp +++ b/src/Conversation/Controller/src/ConvList.cpp @@ -30,7 +30,7 @@ using namespace Msg; ConvList::ConvList(Evas_Object *parent, WorkingDirRef &workingDir) : ListView(parent, App::getInst().getWindow().getCircleSurface()) - , m_DeleteMode(false) + , m_IsDeleteMode(false) , m_pListener(nullptr) , m_pBottomPadItem(nullptr) , m_pReplyItem(nullptr) @@ -50,15 +50,32 @@ ConvList::~ConvList() void ConvList::setDeleteMode(bool value) { - if (m_DeleteMode != value) { - m_DeleteMode = value; - // TODO: impl. + if (m_IsDeleteMode != value) { + m_IsDeleteMode = value; + ListView::setCheckMode(value); + ListView::checkAllItems(false, false); } } -bool ConvList::getDeleteMode() const +bool ConvList::isDeleteModeEnabled() const { - return m_DeleteMode; + return m_IsDeleteMode; +} + +bool ConvList::deleteCheckedItems() +{ + bool res = false;; + MsgIdList idList; + auto items = getItems<ConvListItem>(); + + for (auto *item : items) { + if (item->getCheckedState()) + idList.push_back(item->getMsgId()); + } + if (!idList.empty()) + res = getMsgStorage().deleteMessages(idList); + + return res; } void ConvList::setListener(IConvListListener *l) @@ -203,4 +220,9 @@ void ConvList::onListItemLongPressed(ListItem &listItem) void ConvList::onListItemChecked(ListItem &listItem) { MSG_LOG(""); + if (m_pListener) { + auto *convItem = dynamic_cast<ConvListItem*>(&listItem); + if (convItem) + m_pListener->onItemChecked(*convItem); + } } diff --git a/src/Conversation/View/inc/ConvListViewItem.h b/src/Conversation/View/inc/ConvListViewItem.h index 4a068cd..467ed8c 100644 --- a/src/Conversation/View/inc/ConvListViewItem.h +++ b/src/Conversation/View/inc/ConvListViewItem.h @@ -37,7 +37,7 @@ namespace Msg { ConvListViewItem(ConvItemType type); virtual ~ConvListViewItem(); - void setCheckedState(bool state); + void setCheckedState(bool state, bool updateUi) override; void setInfoStatus(InfoStatusType statusType); protected: @@ -51,6 +51,9 @@ namespace Msg { private: std::string getText(ListItem &item, const char *part) override; Evas_Object *getContent(ListItem &item, const char *part) override; + bool isCheckable() const override; + void onRealized(ListItem &item) override; + void onUnrealized(ListItem &item) override; Evas_Object *createProgress(); Evas_Object *createFailedButton(); diff --git a/src/Conversation/View/src/ConvListViewItem.cpp b/src/Conversation/View/src/ConvListViewItem.cpp index 43b9d18..c3b2796 100644 --- a/src/Conversation/View/src/ConvListViewItem.cpp +++ b/src/Conversation/View/src/ConvListViewItem.cpp @@ -43,7 +43,7 @@ ConvListViewItem::~ConvListViewItem() { } -void ConvListViewItem::setCheckedState(bool state) +void ConvListViewItem::setCheckedState(bool state, bool updateUi) { const char *sig = state ? "show_selected" : "hide_selected"; ListItem::setCheckedState(state, false); @@ -76,6 +76,11 @@ std::string ConvListViewItem::getText(ListItem &item, const char *part) return ""; } +bool ConvListViewItem::isCheckable() const +{ + return true; +} + Evas_Object *ConvListViewItem::getContent(ListItem &item, const char *part) { if (!strcmp(part, bubbleContentPart)) { @@ -132,3 +137,13 @@ void ConvListViewItem::updateItemType(ConvItemType type) break; } } + +void ConvListViewItem::onRealized(ListItem &item) +{ + // Update CheckedState + setCheckedState(getCheckedState(), true); +} + +void ConvListViewItem::onUnrealized(ListItem &item) +{ +} diff --git a/src/MsgThread/Controller/inc/ThreadList.h b/src/MsgThread/Controller/inc/ThreadList.h index 692c76f..48c254c 100644 --- a/src/MsgThread/Controller/inc/ThreadList.h +++ b/src/MsgThread/Controller/inc/ThreadList.h @@ -48,9 +48,7 @@ namespace Msg { void setListener(IThreadListListener *l); void setDeleteMode(bool value); bool isDeleteModeEnabled() const; - void deleteSelectedItems(); - unsigned getThreadsCheckedCount() const; - unsigned getCheckableItemsCount() const; + bool deleteCheckedItems(); private: // IMsgStorageListener: diff --git a/src/MsgThread/Controller/src/MsgThreadFrame.cpp b/src/MsgThread/Controller/src/MsgThreadFrame.cpp index 7526417..0bded0b 100644 --- a/src/MsgThread/Controller/src/MsgThreadFrame.cpp +++ b/src/MsgThread/Controller/src/MsgThreadFrame.cpp @@ -144,7 +144,7 @@ void MsgThreadFrame::prepareDeleteViews() void MsgThreadFrame::updateDeleteViews() { if (m_Mode == DeleteMode) { - int count = m_pThreadList->getThreadsCheckedCount(); + int count = m_pThreadList->getCheckedItemsCount(); m_pSelectButton->setText(std::to_string(count)); m_pDeleteButton->disabled(count <= 0); } @@ -153,7 +153,7 @@ void MsgThreadFrame::updateDeleteViews() void MsgThreadFrame::showSelectPopup() { auto *ctx = new SelectCtxPopup; - int checkedCount = m_pThreadList->getThreadsCheckedCount(); + int checkedCount = m_pThreadList->getCheckedItemsCount(); int checkableCount = m_pThreadList->getCheckableItemsCount(); if (checkedCount < checkableCount) @@ -193,8 +193,8 @@ void MsgThreadFrame::onHwBackButtonPreessed(Evas_Object *obj, void *event_info) void MsgThreadFrame::onDelButtonClicked(Evas_Object *obj, void *event) { MSG_LOG(""); - ToastPopup::toast(msgt("WDS_ALM_TPOP_DELETED_ABB"), DELETEG_MORE_ICON); - m_pThreadList->deleteSelectedItems(); + if (m_pThreadList->deleteCheckedItems()) + ToastPopup::toast(msgt("WDS_ALM_TPOP_DELETED_ABB"), DELETEG_MORE_ICON); setNormalMode(true); } diff --git a/src/MsgThread/Controller/src/ThreadList.cpp b/src/MsgThread/Controller/src/ThreadList.cpp index 242e3b5..1c62e65 100644 --- a/src/MsgThread/Controller/src/ThreadList.cpp +++ b/src/MsgThread/Controller/src/ThreadList.cpp @@ -83,35 +83,15 @@ bool ThreadList::isDeleteModeEnabled() const return m_DeleteMode; } -void ThreadList::deleteSelectedItems() +bool ThreadList::deleteCheckedItems() { + bool res = false; auto items = getItems<ThreadListItem>(); for (ThreadListItem *it : items) { if (it->getCheckedState()) - m_App.getMsgEngine().getStorage().deleteThread(it->getThreadId()); + res |= m_App.getMsgEngine().getStorage().deleteThread(it->getThreadId()); } -} - -unsigned ThreadList::getThreadsCheckedCount() const -{ - auto items = getItems<ThreadListItem>(); - unsigned count = 0; - for (ThreadListItem *item : items) { - if (item->isCheckable() && item->getCheckedState()) - ++count; - } - return count; -} - -unsigned ThreadList::getCheckableItemsCount() const -{ - auto items = getItems(); - unsigned count = 0; - for (ListItem *item : items) { - if (item->isCheckable()) - ++count; - } - return count; + return res; } bool ThreadList::isAllThreadListItemChecked() const @@ -119,7 +99,7 @@ bool ThreadList::isAllThreadListItemChecked() const // Simple impl. but not fast: auto items = getItems<ThreadListItem>(); for (ThreadListItem *item : items) { - if (item->isCheckable() && !item->getCheckedState()) + if (!item->getCheckedState()) return false; } return true; diff --git a/src/MsgThread/View/inc/ThreadListViewItem.h b/src/MsgThread/View/inc/ThreadListViewItem.h index e1ebbfa..02975e8 100644 --- a/src/MsgThread/View/inc/ThreadListViewItem.h +++ b/src/MsgThread/View/inc/ThreadListViewItem.h @@ -51,6 +51,7 @@ namespace Msg { std::string getText(ListItem &item, const char *part) override; Evas_Object *getContent(ListItem &item, const char *part) override; const char *getCheckPart(ListItem &item) override; + bool isCheckable() const override; private: State m_State; diff --git a/src/MsgThread/View/src/ThreadListViewItem.cpp b/src/MsgThread/View/src/ThreadListViewItem.cpp index 1a20ac5..7957905 100644 --- a/src/MsgThread/View/src/ThreadListViewItem.cpp +++ b/src/MsgThread/View/src/ThreadListViewItem.cpp @@ -74,6 +74,11 @@ const char *ThreadListViewItem::getCheckPart(ListItem &item) return checkBoxPart; } +bool ThreadListViewItem::isCheckable() const +{ + return true; +} + void ThreadListViewItem::setState(State state, bool updateUi) { m_State = state; |