TizenRefApp-8082 Implement delete mode in thread list 60/116860/1
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 28 Feb 2017 14:36:05 +0000 (16:36 +0200)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 28 Feb 2017 14:36:05 +0000 (16:36 +0200)
Change-Id: Id85310af3edac8c2ee3be5b9f8ac221c0f9f57d7
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
13 files changed:
src/Common/View/inc/BottomButton.h
src/Common/View/inc/ListItem.h
src/Common/View/inc/SelectButton.h
src/Common/View/inc/SelectCtxPopup.h
src/Common/View/src/BottomButton.cpp
src/Common/View/src/CtxPopup.cpp
src/Common/View/src/ListItem.cpp
src/Common/View/src/ListView.cpp
src/Common/View/src/SelectButton.cpp
src/MsgThread/Controller/inc/MsgThreadFrame.h
src/MsgThread/Controller/inc/ThreadList.h
src/MsgThread/Controller/src/MsgThreadFrame.cpp
src/MsgThread/Controller/src/ThreadList.cpp

index c3521531374a93ae79a1318fcac510b931afeb14..e1981828d63d9d04c87d2e3b924170702721d204 100644 (file)
@@ -28,6 +28,7 @@ namespace Msg {
             Evas_Object *getInnerButton() const;
 
             void setText(const TText &text);
+            void disabled(bool value);
 
         private:
             Evas_Object *m_pButton;
index 171616d5f0b969d2a27b90ead8e44255a5935ca8..1daebf5d6d77b8185f1776c0f35cb37339e707ed 100644 (file)
@@ -172,6 +172,13 @@ namespace Msg
              */
             bool isCheckable() const;
 
+            /**
+             * @brief Compare two items
+             * @param[in] item for compare
+             * @return true if items is same, false otherwise
+             */
+            bool isSame(const ListItem &item) const;
+
         protected:
             virtual std::string getText(ListItem &item, const char *part);
             virtual Evas_Object *getContent(ListItem &item, const char *part);
index c23b4cdb923f720f00c70fa624b1c4aaf9dd7419..3ea1562d645d924884aa9919e92aa45e3888459a 100644 (file)
@@ -27,6 +27,7 @@ namespace Msg {
             SelectButton(Evas_Object *parent);
             Evas_Object *getInnerButton() const;
             void showButton(bool show);
+            void setText(const std::string &text);
 
         private:
             Evas_Object *m_pButton;
index fa7e6ee8842e435f1b45cf98145917b7c3705d75..02c831c5fee334cda6e72acba23a9856a9f19b35 100644 (file)
@@ -36,6 +36,8 @@ namespace Msg {
 
     inline SelectCtxPopup::SelectCtxPopup()
         : CtxPopup()
+        , m_pTopItem(nullptr)
+        , m_pBottomItem(nullptr)
     {
         setStyle("select_mode");
     }
index 2e6726c02f299218e7af9878e45a975345cd9e8f..eb3db5e5dfd3ac83f47e7abf61e6a6cbc6994578 100644 (file)
@@ -38,3 +38,7 @@ void BottomButton::setText(const TText &text)
     View::setText(m_pButton, text);
 }
 
+void BottomButton::disabled(bool value)
+{
+    elm_object_disabled_set(m_pButton, value);
+}
index e8c5727d87a7cbc8a306fd628b8169192d44beb7..67ba6676ebdd82d723d76fd744a6ced6c4765747 100644 (file)
@@ -93,8 +93,11 @@ void CtxPopup::on_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
 void CtxPopup::on_item_pressed_cb(void *data, Evas_Object *obj, void *event_info)
 {
     auto *item = static_cast<CtxPopupItem*>(data);
-    if (item && item->m_pUserCb)
-        item->m_pUserCb(*item, item->m_pUserData);
+    if (item) {
+        if (item->m_pUserCb)
+            item->m_pUserCb(*item, item->m_pUserData);
+        item->getParent().destroy();
+    }
 }
 
 void CtxPopup::align(Window &win)
@@ -126,6 +129,6 @@ void CtxPopup::align(Evas_Object *obj)
     Evas_Coord w = 0;
     Evas_Coord h = 0;
     evas_object_geometry_get(obj, &x, &y, &w, &h);
-    evas_object_move(getEo(), x + (w / 2), y + (h /2));
+    evas_object_move(getEo(), x + (w / 2), y + (h / 2));
 }
 
index 5614b02c1557c0af6b5ddc80afd81b51cc9c169a..9f7fcc06a171f94f91319a9509b6ea61566b6332 100644 (file)
@@ -193,6 +193,11 @@ bool ListItem::isCheckable() const
     return self.getCheckPart(self) != nullptr;
 }
 
+bool ListItem::isSame(const ListItem &item) const
+{
+    return item.getElmObjItem() == getElmObjItem();
+}
+
 void ListItem::onCheckChanged(Evas_Object *obj, void *eventInfo)
 {
     m_Checked = elm_check_state_get(obj);
index 7fdffdfc2629a55634c353b1a47a864150661721..215375b898331f6db069176b4ea3ee67c021caee 100644 (file)
@@ -31,6 +31,15 @@ namespace
     {
         return obj ? static_cast<ListItem*>(elm_object_item_data_get(obj)) : nullptr;
     }
+
+    inline int normalizeCmpValue(int value)
+    {
+        if (value > 0)
+            return 1;
+        if (value < 0)
+            return -1;
+        return 0;
+    }
 }
 
 // ListView:
@@ -122,8 +131,7 @@ bool ListView::sortedInsertItem(ListItem &listItem, ListItem *parent)
             ListItem *item1 = (ListItem*)elm_object_item_data_get((Elm_Object_Item*)data1);
             ListItem *item2 = (ListItem*)elm_object_item_data_get((Elm_Object_Item*)data2);
             if (item1->m_pOwner->m_CmpFunc)
-                res = item1->m_pOwner->m_CmpFunc(*item1, *item2);
-
+                res = normalizeCmpValue(item1->m_pOwner->m_CmpFunc(*item1, *item2));
             return res;
         },
         on_item_selected_cb,
index a1b78775b214de749c3baf66190cec2f213a3f61..d94f59b091136d857c6a6a6ff4efef78a45f616e 100644 (file)
@@ -38,3 +38,8 @@ void SelectButton::showButton(bool show)
     const char *sig = show ? "select_mode,button,show" : "select_mode,button,hide";
     emitSignal(sig);
 }
+
+void SelectButton::setText(const std::string &text)
+{
+    View::setText(m_pButton, text);
+}
index 6c432780e03c5589d9b963000ae8cd0f266d0311..2e3ad11a0ea6fdd703bffed4143177bad8097beb 100644 (file)
@@ -46,6 +46,7 @@ namespace Msg {
             void prepareMainLayout();
             void prepareMoreOption();
             void prepareDeleteViews();
+            void updateDeleteViews();
 
             void setMode(Mode mode);
             void setDeleteMode(bool value);
index 0821e865e2d99a59ad1a34e5bc77c0c3a7a1c65e..9ed7da5cac5bd01c32aa228d624a0c65ce32dc18 100644 (file)
@@ -22,7 +22,9 @@
 #include "ContactManager.h"
 #include "SystemSettingsManager.h"
 #include "ThreadComposeListViewItem.h"
+#include "PaddingListViewItem.h"
 #include "MsgTypes.h"
+
 #include <set>
 
 namespace Msg {
@@ -46,7 +48,8 @@ namespace Msg {
             void setDeleteMode(bool value);
             bool isDeleteModeEnabled() const;
             void deleteSelectedItems();
-            int getThreadsCheckedCount() const;
+            unsigned getThreadsCheckedCount() const;
+            unsigned getCheckableItemsCount() const;
 
         private:
             // IMsgStorageListener:
@@ -80,7 +83,6 @@ namespace Msg {
             void navigateTo(ThreadListItem &item);
             ThreadListItem *getItem(ThreadId id) const;
             bool isAllThreadListItemChecked() const;
-            void updateSelectAllItem();
             std::set<ThreadId> getThreadIdSet(const MsgIdList &idList);
             static int cmpFunc(const ListItem &item1, const ListItem &item2);
 
@@ -89,6 +91,8 @@ namespace Msg {
             App &m_App;
             bool m_DeleteMode;
             ThreadComposeListViewItem *m_ComposeItem;
+            PaddingListViewItem *m_pTopPadItem;
+            PaddingListViewItem *m_pBottomPadItem;
     };
 
     class IThreadListListener {
index bbf8c1a2aa838e97ec1d4604eef4c93003ad525b..0c9feac8b00afda9a0d72f1d1dde52d6629f128d 100644 (file)
@@ -39,7 +39,6 @@ MsgThreadFrame::MsgThreadFrame(NaviFrameController &parent)
     MSG_LOG("");
     prepareMainLayout();
     prepareMoreOption();
-    prepareDeleteViews();
     prepareThreadList();
     setMode(NormalMode);
 }
@@ -74,18 +73,24 @@ void MsgThreadFrame::setNormalMode(bool value)
     m_Mode = NormalMode;
     m_pLayout->showMoreOption(true);
     m_pLayout->showBottomButton(false);
-    m_pSelectButton->showButton(false);
+    if (m_pSelectButton)
+        m_pSelectButton->showButton(false);
     m_pThreadList->setDeleteMode(false);
 }
 
 void MsgThreadFrame::setDeleteMode(bool value)
 {
     MSG_LOG("");
-    m_Mode = DeleteMode;
-    m_pLayout->showBottomButton(true);
-    m_pLayout->showMoreOption(false);
-    m_pSelectButton->showButton(true);
-    m_pThreadList->setDeleteMode(true);
+    if (m_Mode != DeleteMode) {
+        prepareDeleteViews();
+        m_Mode = DeleteMode;
+        m_pSelectButton->setText("0");
+        m_pSelectButton->showButton(true);
+        m_pDeleteButton->disabled(true);
+        m_pLayout->showBottomButton(true);
+        m_pLayout->showMoreOption(false);
+        m_pThreadList->setDeleteMode(true);
+    }
 }
 
 void MsgThreadFrame::prepareThreadList()
@@ -134,13 +139,29 @@ void MsgThreadFrame::prepareDeleteViews()
     }
 }
 
+void MsgThreadFrame::updateDeleteViews()
+{
+    if (m_Mode == DeleteMode) {
+        int count = m_pThreadList->getThreadsCheckedCount();
+        m_pSelectButton->setText(std::to_string(count));
+        m_pDeleteButton->disabled(count <= 0);
+    }
+}
+
 void MsgThreadFrame::showSelectPopup()
 {
     auto *ctx = new SelectCtxPopup;
-    ctx->appendTopItem("Select all", makeCbLast(&MsgThreadFrame::onSelectAllButtonClicked), this);
-    ctx->appendBottomItem("Deselect all", makeCbLast(&MsgThreadFrame::onDeselectAllButtonClicked), this);
+    int checkedCount = m_pThreadList->getThreadsCheckedCount();
+    int checkableCount = m_pThreadList->getCheckableItemsCount();
+
+    if (checkedCount < checkableCount)
+        ctx->appendTopItem("Select all", makeCbLast(&MsgThreadFrame::onSelectAllButtonClicked), this);
+    if (checkedCount > 0)
+        ctx->appendBottomItem("Deselect all", makeCbLast(&MsgThreadFrame::onDeselectAllButtonClicked), this);
+
     if (m_pSelectButton)
         ctx->align(m_pSelectButton->getInnerButton());
+
     ctx->go();
 }
 
@@ -164,6 +185,8 @@ void MsgThreadFrame::onDelButtonClicked(Evas_Object *obj, void *event)
 {
     MSG_LOG("");
     ToastPopup::toast(msgt("IDS_MSG_BUTTON_DELETE_ABB4"), DELETEG_MORE_ICON);
+    m_pThreadList->deleteSelectedItems();
+    setNormalMode(true);
 }
 
 void MsgThreadFrame::onSelectButtonClicked(Evas_Object *obj, void *event)
@@ -175,11 +198,15 @@ void MsgThreadFrame::onSelectButtonClicked(Evas_Object *obj, void *event)
 void MsgThreadFrame::onSelectAllButtonClicked(CtxPopupItem &item)
 {
     MSG_LOG("");
+    m_pThreadList->checkAllItems(true);
+    updateDeleteViews();
 }
 
 void MsgThreadFrame::onDeselectAllButtonClicked(CtxPopupItem &item)
 {
     MSG_LOG("");
+    m_pThreadList->checkAllItems(false);
+    updateDeleteViews();
 }
 
 void MsgThreadFrame::onNewMessageClicked(MoreOption &obj)
@@ -201,11 +228,13 @@ void MsgThreadFrame::onListItemSelected(ThreadId id)
 void MsgThreadFrame::onThreadListChanged()
 {
     MSG_LOG("");
+    updateDeleteViews();
 }
 
 void MsgThreadFrame::onThreadListItemChecked()
 {
     MSG_LOG("");
+    updateDeleteViews();
 }
 
 void MsgThreadFrame::onComposeButtonClicked()
index 1c72a31ac33e560fe0a73e57e9a83484c3fad510..2182fbd9b38cea625d13e0c98268fdfbebcc40fe 100644 (file)
@@ -39,6 +39,8 @@ ThreadList::ThreadList(Evas_Object *parent)
     , m_App(App::getInst())
     , m_DeleteMode(false)
     , m_ComposeItem(nullptr)
+    , m_pTopPadItem(nullptr)
+    , m_pBottomPadItem(nullptr)
 {
     ListView::setListener(this);
     ListView::setHomogeneous(false);
@@ -90,10 +92,10 @@ void ThreadList::deleteSelectedItems()
     }
 }
 
-int ThreadList::getThreadsCheckedCount() const
+unsigned ThreadList::getThreadsCheckedCount() const
 {
     auto items = getItems<ThreadListItem>();
-    int count = 0;
+    unsigned count = 0;
     for (ThreadListItem *item : items) {
         if (item->isCheckable() && item->getCheckedState())
             ++count;
@@ -101,6 +103,17 @@ int ThreadList::getThreadsCheckedCount() const
     return count;
 }
 
+unsigned ThreadList::getCheckableItemsCount() const
+{
+    auto items = getItems();
+    unsigned count = 0;
+    for (ListItem *item : items) {
+        if (item->isCheckable())
+            ++count;
+    }
+    return count;
+}
+
 bool ThreadList::isAllThreadListItemChecked() const
 {
     // Simple impl. but not fast:
@@ -112,19 +125,11 @@ bool ThreadList::isAllThreadListItemChecked() const
     return true;
 }
 
-void ThreadList::updateSelectAllItem()
-{
-    if (!m_DeleteMode)
-        return;
-
-  //  bool allChecked = isAllThreadListItemChecked();
-}
 
 void ThreadList::checkHandler(ThreadListItem &item)
 {
     ThreadId threadId = item.getThreadId();
     MSG_LOG("Checked (id : state) = ", threadId, ":", item.getCheckedState());
-    updateSelectAllItem();
     if (m_pListener)
         m_pListener->onThreadListItemChecked();
 }
@@ -137,8 +142,10 @@ int ThreadList::cmpFunc(const ListItem &item1, const ListItem &item2)
     if (!isTh1 && !isTh2)
         return 0;
 
-    if (!isTh1 || !isTh2)
-        return !isTh1;
+    if (isTh2) {
+        auto *self = static_cast<ThreadList*>(item1.getOwner());
+        return self->m_pBottomPadItem->isSame(item1) ? 1 : -1;
+    }
 
     auto &threadItem1 = static_cast<const ThreadListItem&>(item1);
     auto &threadItem2 = static_cast<const ThreadListItem&>(item2);
@@ -168,7 +175,8 @@ ThreadListItem *ThreadList::getItem(ThreadId id) const
 void ThreadList::fillList()
 {
     // Top padding:
-    ListView::appendItem(*new PaddingListViewItem);
+    m_pTopPadItem = new PaddingListViewItem;
+    ListView::appendItem(*m_pTopPadItem);
 
     // Compose Item:
     m_ComposeItem = new ThreadComposeListViewItem;
@@ -190,7 +198,8 @@ void ThreadList::fillList()
     }
 
     // Bottom padding:
-    ListView::appendItem(*new PaddingListViewItem);
+    m_pBottomPadItem = new PaddingListViewItem;
+    ListView::appendItem(*m_pBottomPadItem);
 }
 
 void ThreadList::deleteItems()
@@ -212,8 +221,6 @@ void ThreadList::deleteItems()
         if (threadIdSet.count(item->getThreadId()) == 0)
             ListView::deleteItem(*item);
     }
-
-    updateSelectAllItem();
 }
 
 void ThreadList::navigateTo(ThreadListItem &item)
@@ -303,7 +310,6 @@ void ThreadList::onMsgStorageThreadInsert(const ThreadId &threadId)
 {
     MSG_LOG("");
     insertItem(threadId);
-    updateSelectAllItem();
     if (m_pListener)
         m_pListener->onThreadListChanged();
 }
@@ -312,10 +318,8 @@ void ThreadList::onMsgStorageThreadDelete(const ThreadId &threadId)
 {
     MSG_LOG("");
     auto* thread = getItem(threadId);
-    if (thread) {
+    if (thread)
         ListView::deleteItem(*thread);
-        updateSelectAllItem();
-    }
 
     if (m_pListener)
         m_pListener->onThreadListChanged();