summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Kobec <s.kobec@samsung.com>2017-03-07 12:57:05 +0200
committerSergei Kobec <s.kobec@samsung.com>2017-03-10 10:06:00 +0200
commitf4948e9d67e8bb101a1e2d2d98e6d7a3de90c829 (patch)
treea14f9e72c54b5e9325752afa2cae3940af9ee4bc
parentb0c0f64cb4f9aa6afb31436478f92b078bad02b5 (diff)
downloadalarm-f4948e9d67e8bb101a1e2d2d98e6d7a3de90c829.tar.gz
alarm-f4948e9d67e8bb101a1e2d2d98e6d7a3de90c829.tar.bz2
alarm-f4948e9d67e8bb101a1e2d2d98e6d7a3de90c829.zip
TizenRefApp-8111 Refactor SelectView to make it suitable for Mobile and Wearable applications
Change-Id: I3525f7a772fc62ed993e986980d8f103e0a8b818 Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
-rw-r--r--alarm-app/inc/List/AlarmsView.h7
-rw-r--r--alarm-app/src/List/AlarmsView.cpp25
-rw-r--r--lib-apps-common/inc/Ui/Control.h23
-rw-r--r--lib-apps-common/inc/Ux/CircleSelector.h38
-rw-r--r--lib-apps-common/inc/Ux/MultiSelector.h64
-rw-r--r--lib-apps-common/inc/Ux/SelectView.h73
-rw-r--r--lib-apps-common/src/Ui/Control.cpp9
-rw-r--r--lib-apps-common/src/Ux/CircleSelector.cpp59
-rw-r--r--lib-apps-common/src/Ux/MultiSelector.cpp57
-rw-r--r--lib-apps-common/src/Ux/SelectView.cpp142
10 files changed, 331 insertions, 166 deletions
diff --git a/alarm-app/inc/List/AlarmsView.h b/alarm-app/inc/List/AlarmsView.h
index 9f80855..7fb30b6 100644
--- a/alarm-app/inc/List/AlarmsView.h
+++ b/alarm-app/inc/List/AlarmsView.h
@@ -26,11 +26,6 @@ namespace Ui
class Genlist;
}
-namespace Ux
-{
- class MultiSelector;
-}
-
namespace List
{
class AlarmItem;
@@ -61,6 +56,7 @@ namespace List
virtual void onSelectModeChanged(Ux::SelectMode selectMode) override;
virtual void onSelectCountChanged(size_t selectCount) override;
virtual Evas_Object *createDoneButton() override;
+ virtual Ux::MultiSelector *createMultiSelector() override;
void onUpdateFinished();
Evas_Object *createContentLayout(Evas_Object *parent);
@@ -83,7 +79,6 @@ namespace List
Evas_Object *m_ContentLayout;
Ui::Genlist *m_Genlist;
AddAlarmItem *m_AddAlarmItem;
- Ux::MultiSelector *m_MultiSelector;
Common::Model::AlarmProvider m_Provider;
AddCallback m_OnAlarmAdded;
diff --git a/alarm-app/src/List/AlarmsView.cpp b/alarm-app/src/List/AlarmsView.cpp
index 270d00b..10d2024 100644
--- a/alarm-app/src/List/AlarmsView.cpp
+++ b/alarm-app/src/List/AlarmsView.cpp
@@ -31,8 +31,7 @@
#include "Ui/Toast.h"
#include "Ui/Window.h"
#include "Utils/Callback.h"
-#include "Ux/MultiSelector.h"
-
+#include "Ux/CircleSelector.h"
#include "ListPath.h"
#include <app_i18n.h>
@@ -46,9 +45,11 @@ using namespace std::placeholders;
AlarmsView::AlarmsView()
: m_NoContents(nullptr), m_ContentLayout(nullptr), m_Genlist(nullptr),
- m_AddAlarmItem(nullptr), m_MultiSelector(nullptr)
+ m_AddAlarmItem(nullptr)
{
Strings strings{};
+ strings.selectAll = "WDS_MSG_OPT_SELECT_ALL_ABB";
+ strings.deselectAll = "WDS_MSG_OPT_DESELECT_ALL_ABB";
strings.buttonDone = "WDS_ALM_ACBUTTON_DELETE_ABB";
strings.titleMulti = "0";
strings.titleWithCount = "%d";
@@ -119,7 +120,9 @@ void AlarmsView::onSelectModeChanged(Ux::SelectMode selectMode)
void AlarmsView::onSelectCountChanged(size_t selectCount)
{
- m_MultiSelector->setCount(selectCount);
+ if (auto multiSelector = getPtr<Ux::CircleSelector>(getMultiSelector())) {
+ multiSelector->setCount(selectCount);
+ }
}
Evas_Object *AlarmsView::createDoneButton()
@@ -131,6 +134,15 @@ Evas_Object *AlarmsView::createDoneButton()
return button;
}
+Ux::MultiSelector *AlarmsView::createMultiSelector()
+{
+ auto multiSelector = new Ux::CircleSelector();
+ multiSelector->create(m_ContentLayout);
+ elm_object_part_content_set(m_ContentLayout, "elm.swallow.icon", multiSelector->getEvasObject());
+
+ return multiSelector;
+}
+
void AlarmsView::onUpdateFinished()
{
updateEmptyState();
@@ -154,11 +166,6 @@ Evas_Object *AlarmsView::createContentLayout(Evas_Object *parent)
m_Genlist->insert(new Ui::PaddingItem());
m_AddAlarmItem->setSelectCallback(std::bind(&AlarmsView::onAddPressed, this));
- m_MultiSelector = new Ux::MultiSelector(this);
- m_MultiSelector->create(layout);
- m_MultiSelector->setStrings({ "WDS_MSG_OPT_SELECT_ALL_ABB", "WDS_MSG_OPT_DESELECT_ALL_ABB" });
- elm_object_part_content_set(layout, "elm.swallow.icon", m_MultiSelector->getEvasObject());
-
return layout;
}
diff --git a/lib-apps-common/inc/Ui/Control.h b/lib-apps-common/inc/Ui/Control.h
index 24481a7..34d1616 100644
--- a/lib-apps-common/inc/Ui/Control.h
+++ b/lib-apps-common/inc/Ui/Control.h
@@ -18,6 +18,7 @@
#define UI_CONTROL_H
#include <Elementary.h>
+#include <memory>
#include <tizen.h>
#include <typeinfo>
@@ -34,6 +35,9 @@
namespace Ui
{
+ class Control;
+ typedef std::weak_ptr<Control> ControlPtr;
+
/**
* @brief Evas_Object wrapper.
* @details Ties the lifetime of this object to the underlying Evas_Object.
@@ -72,6 +76,18 @@ namespace Ui
*/
Evas_Object *getEvasObject() const;
+ /**
+ * @return Weak pointer to control.
+ */
+ ControlPtr getWeakPtr();
+
+ /**
+ * @brief Lock weak pointer and cast it to pointer to ControlType.
+ * @return Pointer to ControlType if success, otherwise nullptr.
+ */
+ template <typename ControlType>
+ static ControlType *getPtr(ControlPtr weakPtr);
+
/**@{*/
/**
* @brief Get Control object from Evas_Object by type.
@@ -140,9 +156,16 @@ namespace Ui
Evas_Object *m_Object;
Ecore_Timer *m_CreateTimer;
+ std::shared_ptr<Control> m_SelfPtr;
};
template <typename ControlType>
+ ControlType *Control::getPtr(ControlPtr weakPtr)
+ {
+ return static_cast<ControlType *>(weakPtr.lock().get());
+ }
+
+ template <typename ControlType>
ControlType *Control::getControl(Evas_Object *object)
{
return static_cast<ControlType *>(getControl(object, typeid(ControlType)));
diff --git a/lib-apps-common/inc/Ux/CircleSelector.h b/lib-apps-common/inc/Ux/CircleSelector.h
new file mode 100644
index 0000000..4b21c78
--- /dev/null
+++ b/lib-apps-common/inc/Ux/CircleSelector.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UX_CIRCLE_SELECTOR_H
+#define UX_CIRCLE_SELECTOR_H
+
+#include "Ux/MultiSelector.h"
+
+namespace Ux
+{
+ class EXPORT_API CircleSelector : public Ux::MultiSelector
+ {
+ public:
+ /**
+ * @brief Set count of selected items.
+ */
+ void setCount(size_t count);
+
+ private:
+ virtual Evas_Object *onCreate(Evas_Object *parent) override;
+ void onButtonClicked(Evas_Object *button, void *eventInfo);
+ };
+}
+
+#endif /* UX_CIRCLE_SELECTOR_H */
diff --git a/lib-apps-common/inc/Ux/MultiSelector.h b/lib-apps-common/inc/Ux/MultiSelector.h
index 7810b4c..feb2e66 100644
--- a/lib-apps-common/inc/Ux/MultiSelector.h
+++ b/lib-apps-common/inc/Ux/MultiSelector.h
@@ -21,10 +21,22 @@
namespace Ux
{
- class SelectView;
class EXPORT_API MultiSelector : public Ui::Control
{
public:
+ /**
+ * @brief MultiSelector state
+ */
+ enum State
+ {
+ SelectedAll,
+ SelectedNone,
+ SelectedPartially
+ };
+
+ /**
+ * @brief Translatable strings for selector menu items.
+ */
struct Strings
{
const char *selectAll; /**< "Select all" item text. */
@@ -32,15 +44,25 @@ namespace Ux
};
/**
- * @brief Create selector.
- * @param[in] selectView Select view.
+ * @brief Change callback.
+ * @param[in] Selector state.
+ * @return Whether contol's state should be changed.
+ */
+ typedef std::function<bool(State)> ChangeCallback;
+
+ MultiSelector();
+
+ /**
+ * @brief Set change callback.
+ * @param[in] callback Change callback.
*/
- explicit MultiSelector(SelectView *selectView);
+ void setChangeCallback(ChangeCallback callback);
/**
- * @brief Set count of selected items.
+ * @brief Set state.
+ * @param[in] state MultiSelector state.
*/
- void setCount(size_t count);
+ void setState(State state);
/**
* @brief Set translatable strings for menu.
@@ -48,12 +70,34 @@ namespace Ux
*/
void setStrings(const Strings &strings);
- private:
- virtual Evas_Object *onCreate(Evas_Object *parent) override;
- void onButtonClicked(Evas_Object *button, void *eventInfo);
+ protected:
+ /**
+ * @brief Called when inner state was changed by public @setState method.
+ * @param[in] state Selector state.
+ */
+ virtual void onStateChanged(State state) { }
+
+ /**
+ * @return Selector state.
+ */
+ State getState() const;
+
+ /**
+ * @return Translatable strings.
+ */
+ const Strings &getStrings() const;
+
+ /**
+ * @brief Called when MultiSelector state was changed.
+ * @remark MUST be called only when change was performed by user interaction.
+ * @param[in] state Selector state.
+ */
+ bool notifyChanged(State state);
+ private:
+ ChangeCallback m_OnChanged;
+ State m_State;
Strings m_Strings;
- SelectView *m_SelectView;
};
}
diff --git a/lib-apps-common/inc/Ux/SelectView.h b/lib-apps-common/inc/Ux/SelectView.h
index 220160c..ed0915f 100644
--- a/lib-apps-common/inc/Ux/SelectView.h
+++ b/lib-apps-common/inc/Ux/SelectView.h
@@ -18,7 +18,7 @@
#define UX_SELECT_VIEW_H
#include "Ui/View.h"
-#include "Ux/SelectAllItem.h"
+#include "Ux/MultiSelector.h"
#include "Ux/SelectTypes.h"
#include <vector>
@@ -43,7 +43,8 @@ namespace Ux
*/
struct Strings
{
- const char *selectAll; /**< "Select all" item text. */
+ const char *selectAll; /**< "Select all" text. */
+ const char *deselectAll; /**< "Deselect all" text. */
const char *buttonDone; /**< "Done" button text. */
const char *buttonCancel; /**< "Cancel" button text. */
const char *titleDefault; /**< Title for #SelectNone mode. */
@@ -154,26 +155,8 @@ namespace Ux
*/
void setLimitCallback(LimitCallback callback);
- /**
- * @brief Select/Deselect all items.
- * @param[in] isSelected Whether all items should be selected.
- */
- void setAllSelected(bool isSelected);
-
protected:
/**
- * @brief Add selectable item to be managed by the view.
- * @param[in] item Item to add
- */
- void addSelectItem(SelectItem *item);
-
- /**
- * @brief Remove selectable item.
- * @param[in] item Item to remove
- */
- void removeSelectItem(SelectItem *item);
-
- /**
* @brief Creates "Done" and "Cancel" buttons in #SelectMulti mode.
* @see View::onPageAttached()
*/
@@ -192,12 +175,6 @@ namespace Ux
virtual void onTitleChanged(const char *title);
/**
- * @brief Called when "Select All" item should be inserted.
- * @param[in] item "Select All" genlist item
- */
- virtual void onSelectAllInsert(Ui::GenItem *item) { }
-
- /**
* @brief Called when selection mode was changed.
* @param[in] selectMode New selection mode
*/
@@ -215,6 +192,38 @@ namespace Ux
*/
virtual void onSelectCountChanged(size_t selectCount) { }
+ /**
+ * @return Done button.
+ */
+ virtual Evas_Object *createDoneButton();
+
+ /**
+ * @return Cancel button.
+ */
+ virtual Evas_Object *createCancelButton();
+
+ /**
+ * @return MultiSelector control.
+ */
+ virtual Ux::MultiSelector *createMultiSelector() = 0;
+
+ /**
+ * @brief Add selectable item to be managed by the view.
+ * @param[in] item Item to add
+ */
+ void addSelectItem(SelectItem *item);
+
+ /**
+ * @brief Remove selectable item.
+ * @param[in] item Item to remove
+ */
+ void removeSelectItem(SelectItem *item);
+
+ /**
+ * @return MultiSelector
+ */
+ Ui::ControlPtr getMultiSelector();
+
private:
friend class SelectItem;
@@ -224,18 +233,14 @@ namespace Ux
CountDecrement
};
- virtual Evas_Object *createDoneButton();
- virtual Evas_Object *createCancelButton();
-
size_t getSelectMax() const;
bool isLimitReached() const;
void updatePageTitle();
void updatePageButtons();
- void updateSelectAllItem();
-
void updateDoneButtonState();
- void updateSelectAllState();
+ void updateMultiSelector();
+ void updateMultiSelectorState();
void updateTotalCount(CountChange change, SelectItem *item);
void updateTotalSelectCount(CountChange change, SelectItem *item);
@@ -250,13 +255,13 @@ namespace Ux
void onItemVisibilityChanged(SelectItem *item, bool isVisible);
void onItemSelected(SelectItem *item);
bool onItemChecked(SelectItem *item, bool isChecked);
- bool onSelectAllChecked(bool isChecked);
+ bool onMultiSelectorChanged(MultiSelector::State state);
void onDonePressed(Evas_Object *button, void *eventInfo);
void onCancelPressed(Evas_Object *button, void *eventInfo);
void onLimitReached();
- Ui::GenItemPtr m_SelectAllItem;
+ Ui::ControlPtr m_MultiSelector;
SelectItems m_Items;
Evas_Object *m_DoneButton;
diff --git a/lib-apps-common/src/Ui/Control.cpp b/lib-apps-common/src/Ui/Control.cpp
index 42bd4b9..9445173 100644
--- a/lib-apps-common/src/Ui/Control.cpp
+++ b/lib-apps-common/src/Ui/Control.cpp
@@ -90,6 +90,15 @@ Evas_Object *Control::getEvasObject() const
return m_Object;
}
+ControlPtr Control::getWeakPtr()
+{
+ if (!m_SelfPtr) {
+ m_SelfPtr.reset(this, [](Control *){ });
+ }
+
+ return m_SelfPtr;
+}
+
Control *Control::getControl(Evas_Object *object, const std::type_info &type)
{
TypeCheckInfo checkInfo = { type, nullptr };
diff --git a/lib-apps-common/src/Ux/CircleSelector.cpp b/lib-apps-common/src/Ux/CircleSelector.cpp
new file mode 100644
index 0000000..d3f9d29
--- /dev/null
+++ b/lib-apps-common/src/Ux/CircleSelector.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Ux/CircleSelector.h"
+#include "Ui/CircleMenu.h"
+#include "Utils/Callback.h"
+
+#define BUF_SIZE 8
+
+using namespace Ux;
+
+void CircleSelector::setCount(size_t count)
+{
+ char buf[BUF_SIZE];
+ snprintf(buf, sizeof(buf), "%zu", count);
+ elm_object_text_set(getEvasObject(), buf);
+}
+
+Evas_Object *CircleSelector::onCreate(Evas_Object *parent)
+{
+ auto button = elm_button_add(parent);
+ elm_object_style_set(button, "select_mode");
+ elm_object_text_set(button, "0");
+ evas_object_smart_callback_add(button, "clicked",
+ makeCallback(&CircleSelector::onButtonClicked), this);
+
+ return button;
+}
+
+void CircleSelector::onButtonClicked(Evas_Object *button, void *eventInfo)
+{
+ auto menu = new Ui::CircleMenu();
+ menu->create(button);
+
+ if (getState() != SelectedAll) {
+ menu->addItem(getStrings().selectAll, [this] {
+ notifyChanged(SelectedAll);
+ });
+ }
+ if (getState() != SelectedNone) {
+ menu->addItem(getStrings().deselectAll, [this] {
+ notifyChanged(SelectedNone);
+ });
+ }
+ menu->show();
+}
diff --git a/lib-apps-common/src/Ux/MultiSelector.cpp b/lib-apps-common/src/Ux/MultiSelector.cpp
index 91fba0e..ea64ce4 100644
--- a/lib-apps-common/src/Ux/MultiSelector.cpp
+++ b/lib-apps-common/src/Ux/MultiSelector.cpp
@@ -15,25 +15,24 @@
*/
#include "Ux/MultiSelector.h"
-#include "Ui/CircleMenu.h"
-#include "Utils/Callback.h"
-#include "Ux/SelectView.h"
-
-#define BUF_SIZE 8
using namespace Ux;
-MultiSelector::MultiSelector(SelectView *selectView)
- : m_Strings { },
- m_SelectView(selectView)
+MultiSelector::MultiSelector()
+ : m_State(SelectedNone),
+ m_Strings{ nullptr }
+{
+}
+
+void MultiSelector::setChangeCallback(ChangeCallback callback)
{
+ m_OnChanged = std::move(callback);
}
-void MultiSelector::setCount(size_t count)
+void MultiSelector::setState(State state)
{
- char buf[BUF_SIZE];
- snprintf(buf, sizeof(buf), "%zu", count);
- elm_object_text_set(getEvasObject(), buf);
+ m_State = state;
+ onStateChanged(m_State);
}
void MultiSelector::setStrings(const Strings &strings)
@@ -41,35 +40,17 @@ void MultiSelector::setStrings(const Strings &strings)
m_Strings = strings;
}
-Evas_Object *MultiSelector::onCreate(Evas_Object *parent)
+MultiSelector::State MultiSelector::getState() const
{
- auto button = elm_button_add(parent);
- elm_object_style_set(button, "select_mode");
- elm_object_text_set(button, "0");
- evas_object_smart_callback_add(button, "clicked",
- makeCallback(&MultiSelector::onButtonClicked), this);
-
- return button;
+ return m_State;
}
-void MultiSelector::onButtonClicked(Evas_Object *button, void *eventInfo)
+const MultiSelector::Strings &MultiSelector::getStrings() const
{
- if (!m_SelectView) {
- return;
- }
-
- auto menu = new Ui::CircleMenu();
- menu->create(button);
+ return m_Strings;
+}
- if (!m_SelectView->isMaxSelected()) {
- menu->addItem(m_Strings.selectAll, [this] {
- m_SelectView->setAllSelected(true);
- });
- }
- if (m_SelectView->getSelectCount() > 0) {
- menu->addItem(m_Strings.deselectAll, [this] {
- m_SelectView->setAllSelected(false);
- });
- }
- menu->show();
+bool MultiSelector::notifyChanged(State state)
+{
+ return !m_OnChanged || m_OnChanged(state);
}
diff --git a/lib-apps-common/src/Ux/SelectView.cpp b/lib-apps-common/src/Ux/SelectView.cpp
index b619e5c..2b52467 100644
--- a/lib-apps-common/src/Ux/SelectView.cpp
+++ b/lib-apps-common/src/Ux/SelectView.cpp
@@ -41,8 +41,8 @@ SelectView::SelectView()
SelectView::~SelectView()
{
- if (auto item = m_SelectAllItem.lock()) {
- delete item.get();
+ if (auto multiSelector = m_MultiSelector.lock()) {
+ delete multiSelector.get();
}
}
@@ -83,7 +83,7 @@ void SelectView::setSelectMode(SelectMode selectMode)
updatePageTitle();
updatePageButtons();
- updateSelectAllItem();
+ updateMultiSelector();
for (auto &&item : m_Items) {
item->setSelectMode(m_SelectMode);
@@ -109,7 +109,7 @@ void SelectView::setSelectLimit(size_t selectLimit)
m_IsMultiChecking = false;
}
- updateSelectAllState();
+ updateMultiSelectorState();
updateDoneButtonState();
updatePageTitle();
@@ -145,46 +145,6 @@ void SelectView::setLimitCallback(LimitCallback callback)
m_OnLimitReached = std::move(callback);
}
-void SelectView::setAllSelected(bool isSelected)
-{
- m_IsMultiChecking = true;
- for (auto &&item : m_Items) {
- if (!item->isExcluded() && item->isVisible()) {
- if (!item->setChecked(isSelected)) {
- break;
- }
- }
- }
-
- m_IsMultiChecking = false;
- updatePageTitle();
-}
-
-void SelectView::addSelectItem(SelectItem *item)
-{
- item->m_SelectView = this;
- item->setSelectMode(m_SelectMode);
- m_Items.push_back(item);
-
- if (!item->isExcluded()) {
- updateTotalCount(CountIncrement, item);
- }
-}
-
-void SelectView::removeSelectItem(SelectItem *item)
-{
- auto it = std::find(m_Items.begin(), m_Items.end(), item);
- if (it == m_Items.end()) {
- return;
- }
-
- m_Items.erase(it);
- if (!item->isExcluded()) {
- updateTotalCount(CountDecrement, item);
- }
- item->m_SelectView = nullptr;
-}
-
void SelectView::onPageAttached(Ui::NavigatorPage *page)
{
updatePageTitle();
@@ -232,6 +192,36 @@ Evas_Object *SelectView::createCancelButton()
return nullptr;
}
+void SelectView::addSelectItem(SelectItem *item)
+{
+ item->m_SelectView = this;
+ item->setSelectMode(m_SelectMode);
+ m_Items.push_back(item);
+
+ if (!item->isExcluded()) {
+ updateTotalCount(CountIncrement, item);
+ }
+}
+
+void SelectView::removeSelectItem(SelectItem *item)
+{
+ auto it = std::find(m_Items.begin(), m_Items.end(), item);
+ if (it == m_Items.end()) {
+ return;
+ }
+
+ m_Items.erase(it);
+ if (!item->isExcluded()) {
+ updateTotalCount(CountDecrement, item);
+ }
+ item->m_SelectView = nullptr;
+}
+
+Ui::ControlPtr SelectView::getMultiSelector()
+{
+ return m_MultiSelector;
+}
+
size_t SelectView::getSelectMax() const
{
if (m_SelectLimit && m_SelectLimit < m_VisibleCount) {
@@ -293,36 +283,42 @@ void SelectView::updatePageButtons()
}
}
-void SelectView::updateSelectAllItem()
+void SelectView::updateDoneButtonState()
+{
+ elm_object_disabled_set(m_DoneButton,
+ m_IsEmptyResultAllowed ? m_TotalCount == 0 : m_TotalSelectCount == 0);
+}
+
+void SelectView::updateMultiSelector()
{
if (m_SelectMode == SelectMulti && m_VisibleCount) {
- if (m_SelectAllItem.expired()) {
- SelectAllItem *item = new SelectAllItem(m_Strings.selectAll);
- item->setCheckCallback(std::bind(&SelectView::onSelectAllChecked, this, _1));
+ if (m_MultiSelector.expired()) {
+ auto multiSelector = createMultiSelector();
+ multiSelector->setStrings({ m_Strings.selectAll, m_Strings.deselectAll });
+ multiSelector->setChangeCallback(std::bind(&SelectView::onMultiSelectorChanged, this, _1));
- m_SelectAllItem = item->getWeakPtr();
- onSelectAllInsert(item);
+ m_MultiSelector = multiSelector->getWeakPtr();
}
- updateSelectAllState();
+ updateMultiSelectorState();
} else {
- if (auto item = m_SelectAllItem.lock()) {
- delete item.get();
+ if (auto multiSelector = m_MultiSelector.lock()) {
+ delete multiSelector.get();
}
}
}
-void SelectView::updateDoneButtonState()
+void SelectView::updateMultiSelectorState()
{
- elm_object_disabled_set(m_DoneButton,
- m_IsEmptyResultAllowed ? m_TotalCount == 0 : m_TotalSelectCount == 0);
-}
+ if (auto multiSelector = getPtr<MultiSelector>(m_MultiSelector)) {
+ auto state = MultiSelector::SelectedNone;
+ if (isMaxSelected()) {
+ state = MultiSelector::SelectedAll;
+ } else if (getSelectCount()) {
+ state = MultiSelector::SelectedPartially;
+ }
-void SelectView::updateSelectAllState()
-{
- if (auto item = m_SelectAllItem.lock()) {
- auto selectAllItem = static_cast<SelectAllItem *>(item.get());
- selectAllItem->setChecked(isMaxSelected());
+ multiSelector->setState(state);
}
}
@@ -364,13 +360,13 @@ void SelectView::updateVisibleCount(CountChange change, SelectItem *item)
updateVisibleSelectCount(change, item);
}
- updateSelectAllItem();
+ updateMultiSelector();
}
void SelectView::updateVisibleSelectCount(CountChange change, SelectItem *item)
{
(change == CountIncrement) ? ++m_VisibleSelectCount : --m_VisibleSelectCount;
- updateSelectAllState();
+ updateMultiSelectorState();
}
void SelectView::createPageButtons()
@@ -430,14 +426,22 @@ bool SelectView::onItemChecked(SelectItem *item, bool isChecked)
return true;
}
-bool SelectView::onSelectAllChecked(bool isChecked)
+bool SelectView::onMultiSelectorChanged(MultiSelector::State state)
{
- if (isChecked == isMaxSelected()) {
- return true;
+ bool isAllSelected = state == MultiSelector::SelectedAll;
+ m_IsMultiChecking = true;
+
+ for (auto &&item : m_Items) {
+ if (!item->isExcluded() && item->isVisible()) {
+ if (!item->setChecked(isAllSelected)) {
+ break;
+ }
+ }
}
- setAllSelected(isChecked);
- return isChecked == isMaxSelected();
+ m_IsMultiChecking = false;
+ updatePageTitle();
+ return isAllSelected == isMaxSelected();
}
void SelectView::onDonePressed(Evas_Object *button, void *eventInfo)