AlarmView: restrict showing of delete menu. 46/103746/1
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 9 Dec 2016 09:23:46 +0000 (10:23 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 9 Dec 2016 09:23:46 +0000 (10:23 +0100)
When there is no alarms available to not show popup
after clicking on "menu" hardware button.

Change-Id: I17643f2f213fc10f9d8d445573a95e0f6420b664

clock/inc/Presenter/AlarmPresenter.h
clock/inc/View/AlarmView.h
clock/src/Presenter/AlarmPresenter.cpp
clock/src/View/AlarmView.cpp

index 3eae811..540ce84 100644 (file)
@@ -45,6 +45,7 @@ namespace presenter {
                        std::map<int, std::reference_wrapper<model::Alarm>> alarms_;
                        std::vector<utils::Listener> listeners_;
                        bool CheckModelSizeLimit();
+                       void OnMenuButtonClicked();
        };
 } /* presenters */
 
index b824ac1..13b4bfa 100644 (file)
@@ -29,6 +29,7 @@ namespace view {
                        typedef std::function<void(int)> SelectCallback;
                        typedef std::function<void(int)> ToggleCallback;
                        typedef std::function<void(void)> ButtonClickedCallback;
+                       typedef std::function<void(void)> MenuButtonClickedCallback;
 
                        AlarmView(ui::IView &main);
                        void Clear();
@@ -44,6 +45,7 @@ namespace view {
                        void SetItemSelectCallback(SelectCallback func);;
                        void SetButtonClickedCallback(ButtonClickedCallback func);
                        void SetDeleteItemClickedCallback(ButtonClickedCallback func) { onDeleteClicked_ = func;}
+                       void SetMenuButtonClickedCallback(MenuButtonClickedCallback func) { onMenuClicked_ = func;}
                        Evas_Object *GetEvasObject();
 
                        void ShowNoAlarmsBackgroundLabel();
@@ -53,6 +55,12 @@ namespace view {
                         * @brief Shows popup window with specified text
                         */
                        void ShowPopup(const std::string &text);
+
+                       /**
+                        * @brief Shows delete popup
+                        */
+                       void ShowDeletePopup();
+
                private:
                        static Elm_Genlist_Item_Class alarm_itc;
                        static Evas_Object *ContentGet(void *data, Evas_Object *obj, const char *part);
@@ -74,7 +82,7 @@ namespace view {
                        ToggleCallback onToggled_;
                        ButtonClickedCallback onClicked_;
                        ButtonClickedCallback onDeleteClicked_;
-                       void ShowDeletePopup();
+                       MenuButtonClickedCallback onMenuClicked_;
        };
 }
 
index d53039d..423e4f0 100644 (file)
@@ -34,6 +34,7 @@ AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view(v), model(
        view->SetDeleteItemClickedCallback(std::bind(&AlarmPresenter::OnDeleteItemClicked, this));
        view->SetItemToggleCallback(std::bind(&AlarmPresenter::OnItemActiveStatusChanged, this, _1));
        view->SetItemSelectCallback(std::bind(&AlarmPresenter::OnItemSelected, this, _1));
+       view->SetMenuButtonClickedCallback(std::bind(&AlarmPresenter::OnMenuButtonClicked, this));
 
        listeners_.push_back(EventBus::AddListener<AlarmAddedEvent>(
                        std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1)));
@@ -134,6 +135,12 @@ void AlarmPresenter::OnDeleteItemClicked()
        EventBus::FireEvent(ev);
 }
 
+void AlarmPresenter::OnMenuButtonClicked()
+{
+       if (alarms_.size() > 0)
+               view->ShowDeletePopup();
+}
+
 void AlarmPresenter::OnAlarmRemovedEvent(Event &e)
 {
        AlarmRemovedEvent &ev = dynamic_cast<AlarmRemovedEvent&>(e);
index d97c380..1f88a8b 100644 (file)
@@ -183,7 +183,7 @@ AlarmView::AlarmView(ui::IView &main)
 void AlarmView::MoreButtonClicked(void *data, Evas_Object *obj, void *info)
 {
        AlarmView *view = static_cast<AlarmView*>(data);
-       view->ShowDeletePopup();
+       if (view->onMenuClicked_) view->onMenuClicked_();
 }
 
 void AlarmView::Clear()
@@ -271,10 +271,13 @@ void AlarmView::PopupDeleteItemCallback(void *data, Evas_Object *obj, void *even
        AlarmView *view = static_cast<AlarmView*>(data);
        if (view->onDeleteClicked_) view->onDeleteClicked_();
        evas_object_del(view->popup_);
+       view->popup_ = nullptr;
 }
 
 void AlarmView::ShowDeletePopup()
 {
+       if (popup_) return;
+
        popup_ = elm_popup_add(elm_object_top_widget_get(content_));
        elm_popup_align_set(popup_, ELM_NOTIFY_ALIGN_FILL, 1.0);
        evas_object_size_hint_weight_set(popup_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);