world clock: Enabling "More" menu options. 67/93467/6
authorRadoslaw Czerski <r.czerski@samsung.com>
Thu, 27 Oct 2016 11:11:43 +0000 (13:11 +0200)
committerRadoslaw Czerski <r.czerski@samsung.com>
Thu, 27 Oct 2016 11:11:43 +0000 (13:11 +0200)
Change-Id: Ib740bab926b694c19bcad5aa1a0c488bfe6a05af
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
clock/inc/View/WorldClockView.h
clock/src/Presenter/WorldClockPresenter.cpp
clock/src/View/WorldClockView.cpp

index 91dfea2..d96ed43 100644 (file)
@@ -42,6 +42,16 @@ namespace view {
 
        class WorldClockView: public ui::IView {
                public:
+
+                       /**
+                        * @brief Enumeration for "More" options menu
+                        */
+                       enum class MoreMenuOptions {
+                               ALL_OPTIONS_DISABLED,
+                               DELETE_OPTION_ENABLED = 0x1,
+                               REORDER_OPTION_ENABLED = 0x2
+                       };
+
                        WorldClockView(ui::IView &main);
 
                        Evas_Object *GetEvasObject(){return world_clock_main_;};
@@ -58,14 +68,18 @@ namespace view {
                        void ShowEmptyListLabel();
                        void HideEmptyListLabel();
                        void PostItemExistMessage();
-                       void ShowMorePopup();
+                       /**
+                        * @brief Shows more popup.
+                        * @param options options mask (see MoreMenuOptions enum)
+                        */
+                       void ShowMorePopup(MoreMenuOptions options);
 
                        /**
                         * @brief Checks if user locations list is empty or not
                         *
                         * @return true if empty, false otherwise
                         */
-                       bool IsListEmpty();
+                       int GetItemsCount();
 
                private:
                        void CreateTimezoneDetails();
@@ -124,6 +138,23 @@ namespace view {
                        std::vector<std::function<void(void)>> signals
                                                = std::vector<std::function<void(void)>>((int)WorldClockSignals::MAX, nullptr);
        };
+
+       /**
+        * @brief operator  & for WorldClockView::MoreMenuOptions enum class.
+        */
+       inline constexpr int operator &(WorldClockView::MoreMenuOptions a,
+                       WorldClockView::MoreMenuOptions b){
+               return static_cast<int>(a) & static_cast<int>(b);
+       }
+
+       /**
+        * @brief operator | for WorldClockView::MoreMenuOptions enum class.
+        */
+       inline constexpr WorldClockView::MoreMenuOptions operator |(WorldClockView::MoreMenuOptions a,
+                       WorldClockView::MoreMenuOptions b){
+               return static_cast<WorldClockView::MoreMenuOptions>(static_cast<int>(a) |
+                               static_cast<int>(b));
+       }
 }
 
 #endif /* _CLOCK_VIEW_WORLDCLOCK_H_ */
index 7bf2255..5a59a17 100644 (file)
@@ -62,7 +62,7 @@ WorldClockPresenter::~WorldClockPresenter()
 
 void WorldClockPresenter::UpdateEmptyListBackground()
 {
-       if (view_->IsListEmpty())
+       if (view_->GetItemsCount() == 0)
                view_->ShowEmptyListLabel();
        else
                view_->HideEmptyListLabel();
@@ -136,7 +136,21 @@ void WorldClockPresenter::OnItemDeleted(const model::Location &location)
 
 void WorldClockPresenter::OnMoreButtonClicked()
 {
-       view_->ShowMorePopup();
+       int cnt = view_->GetItemsCount();
+
+       if (cnt == 0) {
+               INF("the list is empty");
+               view_->ShowMorePopup(WorldClockView::MoreMenuOptions::ALL_OPTIONS_DISABLED);
+       } else if (cnt == 1) {
+               INF("Only one Location in the list. DELETE option allowed only.");
+               view_->ShowMorePopup(WorldClockView::MoreMenuOptions::DELETE_OPTION_ENABLED);
+       } else if (cnt > 1) {
+               INF("DELETE and REORDER options enabled");
+               view_->ShowMorePopup(WorldClockView::MoreMenuOptions::DELETE_OPTION_ENABLED |
+                                                       WorldClockView::MoreMenuOptions::REORDER_OPTION_ENABLED);
+       } else {
+               FAT("User locations list size is a negative number!");
+       }
 }
 
 void WorldClockPresenter::OnMoreDeleteButtonClicked()
index cce5899..223a0cb 100644 (file)
@@ -268,8 +268,13 @@ void WorldClockView::MoreButtonClicked(void *data, Evas_Object *obj, void *info)
        view->EmitSignal(view::WorldClockSignals::BUTTON_MORE_CLICKED);
 }
 
-void WorldClockView::ShowMorePopup()
+void WorldClockView::ShowMorePopup(MoreMenuOptions options)
 {
+       if (!(int)(options | MoreMenuOptions::ALL_OPTIONS_DISABLED)) {
+               INF("Locations list is empty. Options are disabled.");
+               return;
+       }
+
        more_popup_ = elm_popup_add(elm_object_top_widget_get(world_clock_main_));
        elm_popup_align_set(more_popup_, ELM_NOTIFY_ALIGN_FILL, 1.0);
        evas_object_size_hint_weight_set(more_popup_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -282,8 +287,10 @@ void WorldClockView::ShowMorePopup()
        elm_list_mode_set(list, ELM_LIST_EXPAND);
        evas_object_show(list);
 
-       elm_list_item_append(list, "Delete", NULL, NULL, MorePopupDeleteItemCallback, this);
-       elm_list_item_append(list, "Reorder", NULL, NULL, MorePopupReorderItemCallback, this);
+       if (options & MoreMenuOptions::DELETE_OPTION_ENABLED)
+               elm_list_item_append(list, "Delete", NULL, NULL, MorePopupDeleteItemCallback, this);
+       if (options & MoreMenuOptions::REORDER_OPTION_ENABLED)
+               elm_list_item_append(list, "Reorder", NULL, NULL, MorePopupReorderItemCallback, this);
        elm_object_content_set(more_popup_, list);
        evas_object_show(more_popup_);
 }
@@ -677,10 +684,7 @@ void WorldClockView::PostItemExistMessage()
        utils::PopupManager::CreatePopup(*this, "Location already exists in the list", 3);
 }
 
-bool WorldClockView::IsListEmpty()
+int WorldClockView::GetItemsCount()
 {
-       if (elm_genlist_items_count(custom_locations_list_) > 0)
-               return false;
-       else
-               return true;
+       return elm_genlist_items_count(custom_locations_list_);
 }