summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Kobec <s.kobec@samsung.com>2017-02-24 16:00:22 +0200
committerSergei Kobec <s.kobec@samsung.com>2017-02-27 15:36:42 +0200
commitabc146eea5d4ee11295f657ad5272811c15ce844 (patch)
tree5cc5d772fbbf538bd808c90ef36046ac5606559b
parent29ca340eefe29ab7dda2acd53c65c749d5bb1543 (diff)
downloadalarm-abc146eea5d4ee11295f657ad5272811c15ce844.tar.gz
alarm-abc146eea5d4ee11295f657ad5272811c15ce844.tar.bz2
alarm-abc146eea5d4ee11295f657ad5272811c15ce844.zip
TizenRefApp-8041 Implement Select/Deselect All functionality in the SelectView
Change-Id: Ia6f91fb6edaac5552aa751f025dcdba361dc33cd Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
-rw-r--r--alarm-app/inc/List/AlarmsView.h2
-rw-r--r--alarm-app/src/List/AlarmsView.cpp10
-rw-r--r--lib-apps-common/inc/Ux/MultiSelector.h8
-rw-r--r--lib-apps-common/inc/Ux/SelectView.h12
-rw-r--r--lib-apps-common/src/Ux/MultiSelector.cpp26
-rw-r--r--lib-apps-common/src/Ux/SelectView.cpp49
6 files changed, 69 insertions, 38 deletions
diff --git a/alarm-app/inc/List/AlarmsView.h b/alarm-app/inc/List/AlarmsView.h
index 42018a1..5a00ee1 100644
--- a/alarm-app/inc/List/AlarmsView.h
+++ b/alarm-app/inc/List/AlarmsView.h
@@ -65,7 +65,7 @@ namespace List
void onAlarmDeleted(AlarmItem *item);
void onAddPressed();
void onFormatChanged(system_settings_key_e key);
- void onItemLongpressed(Evas_Object *genlist, void *genItem);
+ void onItemLongpressed(Evas_Object *genlist, Elm_Object_Item *item);
bool onSelectFinished();
Evas_Object *m_NoContents;
diff --git a/alarm-app/src/List/AlarmsView.cpp b/alarm-app/src/List/AlarmsView.cpp
index 52c5637..dab13cd 100644
--- a/alarm-app/src/List/AlarmsView.cpp
+++ b/alarm-app/src/List/AlarmsView.cpp
@@ -143,11 +143,11 @@ Evas_Object *AlarmsView::createContentLayout(Evas_Object *parent)
m_Genlist = new Ui::Genlist();
m_Genlist->create(parent);
eext_circle_object_genlist_add(m_Genlist->getEvasObject(), surface);
- evas_object_smart_callback_add(m_Genlist->getEvasObject(),
- "longpressed", makeCallback(&AlarmsView::onItemLongpressed), this);
+ evas_object_smart_callback_add(m_Genlist->getEvasObject(), "longpressed",
+ (Evas_Smart_Cb)makeCallback(&AlarmsView::onItemLongpressed), this);
elm_object_content_set(layout, m_Genlist->getEvasObject());
- m_MultiSelector = new Ux::MultiSelector();
+ 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());
@@ -257,7 +257,7 @@ void AlarmsView::onFormatChanged(system_settings_key_e key)
m_Genlist->update("elm.text", ELM_GENLIST_ITEM_FIELD_TEXT);
}
-void AlarmsView::onItemLongpressed(Evas_Object *genlist, void *genItem)
+void AlarmsView::onItemLongpressed(Evas_Object *genlist, Elm_Object_Item *item)
{
if (getSelectMode() == Ux::SelectNone) {
setSelectMode(Ux::SelectMulti);
@@ -270,7 +270,7 @@ void AlarmsView::onItemLongpressed(Evas_Object *genlist, void *genItem)
return onSelectFinished();
});
- elm_genlist_item_selected_set((Elm_Object_Item *)genItem, EINA_TRUE);
+ elm_genlist_item_selected_set(item, EINA_TRUE);
}
}
diff --git a/lib-apps-common/inc/Ux/MultiSelector.h b/lib-apps-common/inc/Ux/MultiSelector.h
index efb9db2..7810b4c 100644
--- a/lib-apps-common/inc/Ux/MultiSelector.h
+++ b/lib-apps-common/inc/Ux/MultiSelector.h
@@ -21,6 +21,7 @@
namespace Ux
{
+ class SelectView;
class EXPORT_API MultiSelector : public Ui::Control
{
public:
@@ -30,7 +31,11 @@ namespace Ux
const char *deselectAll; /**< "Deselect all" item text. */
};
- MultiSelector();
+ /**
+ * @brief Create selector.
+ * @param[in] selectView Select view.
+ */
+ explicit MultiSelector(SelectView *selectView);
/**
* @brief Set count of selected items.
@@ -48,6 +53,7 @@ namespace Ux
void onButtonClicked(Evas_Object *button, void *eventInfo);
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 cf6fece..220160c 100644
--- a/lib-apps-common/inc/Ux/SelectView.h
+++ b/lib-apps-common/inc/Ux/SelectView.h
@@ -101,6 +101,11 @@ namespace Ux
const SelectItems &getSelectItems() const;
/**
+ * @return Whether all items are selected.
+ */
+ bool isMaxSelected() const;
+
+ /**
* @brief Set translatable strings for the view.
* @remark Should be called before create().
* @param[in] strings Translatable strings table
@@ -149,6 +154,12 @@ 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.
@@ -218,7 +229,6 @@ namespace Ux
size_t getSelectMax() const;
bool isLimitReached() const;
- bool isMaxSelected() const;
void updatePageTitle();
void updatePageButtons();
diff --git a/lib-apps-common/src/Ux/MultiSelector.cpp b/lib-apps-common/src/Ux/MultiSelector.cpp
index 11dc744..91fba0e 100644
--- a/lib-apps-common/src/Ux/MultiSelector.cpp
+++ b/lib-apps-common/src/Ux/MultiSelector.cpp
@@ -17,13 +17,15 @@
#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()
- : m_Strings { }
+MultiSelector::MultiSelector(SelectView *selectView)
+ : m_Strings { },
+ m_SelectView(selectView)
{
}
@@ -52,14 +54,22 @@ Evas_Object *MultiSelector::onCreate(Evas_Object *parent)
void MultiSelector::onButtonClicked(Evas_Object *button, void *eventInfo)
{
+ if (!m_SelectView) {
+ return;
+ }
+
auto menu = new Ui::CircleMenu();
menu->create(button);
- menu->addItem(m_Strings.selectAll, [] {
- //TODO React on select all event
- });
- menu->addItem(m_Strings.deselectAll, [] {
- //TODO React on deselect all event
- });
+ 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();
}
diff --git a/lib-apps-common/src/Ux/SelectView.cpp b/lib-apps-common/src/Ux/SelectView.cpp
index ad1783e..b619e5c 100644
--- a/lib-apps-common/src/Ux/SelectView.cpp
+++ b/lib-apps-common/src/Ux/SelectView.cpp
@@ -66,6 +66,11 @@ const SelectView::SelectItems &SelectView::getSelectItems() const
return m_Items;
}
+bool SelectView::isMaxSelected() const
+{
+ return m_VisibleSelectCount == getSelectMax();
+}
+
void SelectView::setStrings(const Strings &strings)
{
m_Strings = strings;
@@ -140,6 +145,21 @@ 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;
@@ -196,20 +216,20 @@ void SelectView::onTitleChanged(const char *title)
Evas_Object *SelectView::createDoneButton()
{
- if (!getPage()) {
- return nullptr;
+ if (auto page = getPage()) {
+ return page->addTitleButton(Ui::ButtonRight, m_Strings.buttonDone, nullptr, nullptr);
}
- return getPage()->addTitleButton(Ui::ButtonRight, m_Strings.buttonDone, nullptr, nullptr);
+ return nullptr;
}
Evas_Object *SelectView::createCancelButton()
{
- if (!getPage()) {
- return nullptr;
+ if (auto page = getPage()) {
+ return page->addTitleButton(Ui::ButtonLeft, m_Strings.buttonCancel, nullptr, nullptr);
}
- return getPage()->addTitleButton(Ui::ButtonLeft, m_Strings.buttonCancel, nullptr, nullptr);
+ return nullptr;
}
size_t SelectView::getSelectMax() const
@@ -226,11 +246,6 @@ bool SelectView::isLimitReached() const
return m_SelectLimit && m_TotalSelectCount == m_SelectLimit;
}
-bool SelectView::isMaxSelected() const
-{
- return m_VisibleSelectCount == getSelectMax();
-}
-
void SelectView::updatePageTitle()
{
char buffer[TITLE_BUFFER_SIZE];
@@ -421,17 +436,7 @@ bool SelectView::onSelectAllChecked(bool isChecked)
return true;
}
- m_IsMultiChecking = true;
- for (auto &&item : m_Items) {
- if (!item->isExcluded() && item->isVisible()) {
- if (!item->setChecked(isChecked)) {
- break;
- }
- }
- }
-
- m_IsMultiChecking = false;
- updatePageTitle();
+ setAllSelected(isChecked);
return isChecked == isMaxSelected();
}