alarms: show "maximum alarms reached" popup 21/93521/3
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Mon, 24 Oct 2016 14:33:26 +0000 (16:33 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Wed, 26 Oct 2016 10:53:17 +0000 (12:53 +0200)
After clicking on "+" button in alarms view, inform user
if maximum number of alarms has been reached.

Change-Id: I32e628eab6a2cc7835b11938f83a82a9c36272db

clock/inc/Presenter/AlarmPresenter.h
clock/inc/View/AlarmView.h
clock/res/po/en_US.po
clock/src/Presenter/AlarmPresenter.cpp
clock/src/Presenter/EditAlarmPresenter.cpp
clock/src/View/AlarmView.cpp

index 775007c..129e6fe 100644 (file)
@@ -44,6 +44,7 @@ namespace presenter {
                        void UpdateBackgroundLabel();
                        std::map<int, std::reference_wrapper<model::Alarm>> alarms_;
                        std::vector<utils::Listener> listeners_;
+                       bool CheckModelSizeLimit();
        };
 } /* presenters */
 
index b3cb240..d4328a1 100644 (file)
@@ -48,6 +48,11 @@ namespace view {
 
                        void ShowNoAlarmsBackgroundLabel();
                        void HideNoAlarmsBackgroundLabel();
+
+                       /**
+                        * @brief Shows popup window with specified text
+                        */
+                       void ShowPopup(const std::string &text);
                private:
                        static Elm_Genlist_Item_Class alarm_itc;
                        static Evas_Object *ContentGet(void *data, Evas_Object *obj, const char *part);
index 8c0aff2..8350acd 100644 (file)
@@ -19,3 +19,5 @@ msgstr "%d h behind"
 msgid "IDS_CLOCK_MAX_RECORDS_REACHED_POPUP_ABB"
 msgstr "Maximum number of stopwatch records (%d) reached."
 
+msgid "IDS_CLOCK_TPOP_CANT_ADD_MORE_THEN_PD_ALARMS"
+msgstr "Can't add more then %d alarms."
index db1df4f..35f7843 100644 (file)
@@ -10,6 +10,8 @@ using namespace model;
 using namespace utils;
 using std::placeholders::_1;
 
+const int AVAILABLE_ALARMS_MAX = 20;
+
 AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view(v), model(m)
 {
        view->SetButtonClickedCallback(std::bind(&AlarmPresenter::OnAddButtonClicked, this));
@@ -64,6 +66,14 @@ void AlarmPresenter::OnItemSelected(int idx)
 void AlarmPresenter::OnAddButtonClicked()
 {
        AlarmCreateRequestEvent ev;
+       char buf[64];
+
+       if (!CheckModelSizeLimit()) {
+               snprintf(buf, sizeof(buf), _("IDS_CLOCK_TPOP_CANT_ADD_MORE_THEN_PD_ALARMS"),
+                               AVAILABLE_ALARMS_MAX);
+               view->ShowPopup(buf);
+               return;
+       }
        EventBus::FireEvent(ev);
 }
 
@@ -144,3 +154,12 @@ void AlarmPresenter::OnAlarmEditedEvent(utils::Event &e)
                }
        }
 }
+
+bool AlarmPresenter::CheckModelSizeLimit()
+{
+       if (AlarmProvider::GetInstance()->GetAlarms().size() >= AVAILABLE_ALARMS_MAX ) {
+               return false;
+       }
+       return true;
+}
+
index 114365d..392210a 100644 (file)
@@ -9,7 +9,6 @@ using namespace view;
 using namespace model;
 using namespace utils;
 
-
 EditAlarmPresenter::EditAlarmPresenter(model::Alarm *alarm, view::EditAlarmView& view) :
        alarm_(alarm), view_(view)
 {
index 76cee41..1b7812e 100644 (file)
@@ -23,6 +23,7 @@
 #include <efl_extension.h>
 
 #include "Utils/Log.h"
+#include "Utils/PopupManager.h"
 
 using namespace view;
 using namespace model;
@@ -318,3 +319,8 @@ void AlarmView::HideNoAlarmsBackgroundLabel()
                label_ = nullptr;
        }
 }
+
+void AlarmView::ShowPopup(const std::string &text)
+{
+       PopupManager::CreatePopup(*this, text);
+}