Implemented mode switch for "Delete" feature in LogsView instead of creating new... 03/80703/1
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 19 Jul 2016 14:48:43 +0000 (17:48 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 19 Jul 2016 14:49:39 +0000 (17:49 +0300)
Change-Id: I39941cb17f91401effe25ec5577ddcf478a6938d
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-logs/inc/Logs/List/LogsView.h
lib-logs/src/Logs/List/LogsView.cpp

index ac3b896..2fa30c0 100644 (file)
@@ -74,12 +74,19 @@ namespace Logs
                        virtual void onCreated() override;
                        virtual void onNavigation(bool isCurrentView) override;
                        virtual void onMenuPressed() override;
+
+                       void onFilterBySelected();
+                       void onDeleteSelected();
+                       bool onSelectFinished();
+
                        virtual void onSelectAllInsert(Ui::GenItem *item) override;
+                       virtual void onSelectModeChanged(Ux::SelectMode selectMode) override;
 
                        void fillLayout();
                        void updateLayout(bool isEmpty);
                        Evas_Object *createNoContentsLayout(Evas_Object *parent);
-                       void fillGenlist();
+                       void fillList();
+                       void clearList();
 
                        bool shouldDisplayLogs(const Model::LogGroup *logGroup) const;
                        LogItem *createLogItem(Model::LogGroup *logGroup);
@@ -90,7 +97,6 @@ namespace Logs
                        void setLastGroupItem(LogGroupItem *groupItem);
 
                        void onSettingsChanged(system_settings_key_e key);
-                       void onSelectViewBy();
                        void onLogInserted(Model::LogGroup *group);
                        void onLogItemDelete(LogItem *item);
 
index 069309d..57a16c2 100644 (file)
@@ -45,7 +45,9 @@ LogsView::LogsView(FilterType filterType)
          m_Genlist(nullptr), m_LastGroupItem(nullptr)
 {
        auto strings = Common::getSelectViewStrings();
+       strings.buttonDone = "IDS_TPLATFORM_ACBUTTON_DELETE_ABB";
        strings.titleDefault = "IDS_LOGS_ITAB3_LOGS";
+       strings.titleMulti = "IDS_CLOG_HEADER_SELECT_LOGS";
        setStrings(strings);
 
        Settings::addCallback(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR,
@@ -102,30 +104,11 @@ void LogsView::onMenuPressed()
        menu->create(getEvasObject());
 
        if (!m_LogProvider.getLogGroupList().empty()) {
-               menu->addItem("IDS_LOGS_OPT_FILTER_BY_ABB", [this] {
-                       onSelectViewBy();
-               });
+               menu->addItem("IDS_LOGS_OPT_FILTER_BY_ABB", std::bind(&LogsView::onFilterBySelected, this));
        }
 
        if (m_Genlist && elm_genlist_items_count(m_Genlist->getEvasObject())) {
-               menu->addItem("IDS_LOGS_OPT_DELETE", [this] {
-                       auto strings = Common::getSelectViewStrings();
-                       strings.buttonDone = "IDS_TPLATFORM_ACBUTTON_DELETE_ABB";
-                       strings.titleMulti = "IDS_CLOG_HEADER_SELECT_LOGS";
-
-                       LogsView *view = new LogsView(m_FilterType);
-                       view->setStrings(strings);
-                       view->setSelectMode(SelectMulti);
-                       view->setSelectCallback([](SelectResults results) {
-                                               for (auto &&result : results) {
-                                                       LogGroup *group = (LogGroup *) result.value.data;
-                                                       group->remove();
-                                               }
-
-                                               return true;
-                                       });
-                       getNavigator()->navigateTo(view);
-               });
+               menu->addItem("IDS_LOGS_OPT_DELETE", std::bind(&LogsView::onDeleteSelected, this));
        }
 
        menu->addItem("IDS_KPD_OPT_CALL_SETTINGS_ABB", [this] {
@@ -136,11 +119,57 @@ void LogsView::onMenuPressed()
        menu->show();
 }
 
+void LogsView::onFilterBySelected()
+{
+       Ui::RadioPopup *popup = new Ui::RadioPopup();
+       popup->create(getEvasObject());
+       popup->setTitle("IDS_LOGS_HEADER_FILTER_BY");
+       popup->addItem("IDS_LOGS_OPT_ALL_CALLS_ABB", (void *) FilterAll);
+       popup->addItem("IDS_LOGS_OPT_MISSED_CALLS", (void *) FilterMissed);
+       popup->setSelectedItem(m_FilterType);
+       popup->setSelectedCallback([this](void *data) {
+               auto filter = (FilterType)(long)data;
+               if (m_FilterType != filter) {
+                       m_FilterType = filter;
+                       fillLayout();
+               }
+       });
+}
+
+void LogsView::onDeleteSelected()
+{
+       setSelectMode(SelectMulti);
+       setCancelCallback(std::bind(&LogsView::onSelectFinished, this));
+       setSelectCallback([this](SelectResults results) {
+               for (auto &&result : results) {
+                       LogGroup *group = (LogGroup *) result.value.data;
+                       group->remove();
+               }
+
+               return onSelectFinished();
+       });
+}
+
+bool LogsView::onSelectFinished()
+{
+       setSelectMode(SelectNone);
+       setCancelCallback(nullptr);
+       setSelectCallback(nullptr);
+       return false;
+}
+
 void LogsView::onSelectAllInsert(Ui::GenItem *item)
 {
        m_Genlist->insert(item, nullptr, nullptr, Ui::Genlist::After);
 }
 
+void LogsView::onSelectModeChanged(Ux::SelectMode selectMode)
+{
+       if (Ui::NavigatorPage *page = getPage()) {
+               page->setExpanded(selectMode != SelectNone);
+       }
+}
+
 void LogsView::resetMissedCalls()
 {
        unsigned count = 0;
@@ -156,12 +185,12 @@ void LogsView::resetMissedCalls()
 void LogsView::fillLayout()
 {
        if (m_Genlist) {
-               elm_genlist_clear(m_Genlist->getEvasObject());
+               clearList();
        } else {
                updateLayout(false);
        }
 
-       fillGenlist();
+       fillList();
 
        if (!elm_genlist_items_count(m_Genlist->getEvasObject())) {
                updateLayout(true);
@@ -195,7 +224,7 @@ Evas_Object *LogsView::createNoContentsLayout(Evas_Object *parent)
        return layout;
 }
 
-void LogsView::fillGenlist()
+void LogsView::fillList()
 {
        for (auto &&group : m_LogProvider.getLogGroupList()) {
                if (shouldDisplayLogs(group.get())) {
@@ -209,6 +238,14 @@ void LogsView::fillGenlist()
        }
 }
 
+void LogsView::clearList()
+{
+       for (auto &&item : *m_Genlist) {
+               removeSelectItem(static_cast<Ux::SelectItem *>(item));
+       }
+       elm_genlist_clear(m_Genlist->getEvasObject());
+}
+
 bool LogsView::shouldDisplayLogs(const LogGroup *group) const
 {
        switch (m_FilterType) {
@@ -289,34 +326,14 @@ void LogsView::onSettingsChanged(system_settings_key_e key)
 
        if (key == SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY ||
                        key == SYSTEM_SETTINGS_KEY_TIME_CHANGED) {
-               for (auto &&item : *m_Genlist) {
-                       removeSelectItem(static_cast<Ux::SelectItem *>(item));
-               }
-               elm_genlist_clear(m_Genlist->getEvasObject());
+               clearList();
                m_LogProvider.resetLogGroups();
-               fillGenlist();
+               fillList();
        } else {
                m_Genlist->update(PART_LOG_TIME, ELM_GENLIST_ITEM_FIELD_TEXT);
        }
 }
 
-void LogsView::onSelectViewBy()
-{
-       Ui::RadioPopup *popup = new Ui::RadioPopup();
-       popup->create(getEvasObject());
-       popup->setTitle("IDS_LOGS_HEADER_FILTER_BY");
-       popup->addItem("IDS_LOGS_OPT_ALL_CALLS_ABB", (void *) FilterAll);
-       popup->addItem("IDS_LOGS_OPT_MISSED_CALLS", (void *) FilterMissed);
-       popup->setSelectedItem(m_FilterType);
-       popup->setSelectedCallback([this](void *data) {
-               auto filter = (FilterType)(long)data;
-               if (m_FilterType != filter) {
-                       m_FilterType = filter;
-                       fillLayout();
-               }
-       });
-}
-
 void LogsView::onLogInserted(LogGroup *group)
 {
        if (shouldDisplayLogs(group)) {