[TimerView] Disable menu buttons while ringing 79/158279/2
authorKamil Lipiszko <k.lipiszko@samsung.com>
Mon, 30 Oct 2017 15:37:51 +0000 (16:37 +0100)
committerKamil Lipiszko <k.lipiszko@samsung.com>
Tue, 31 Oct 2017 09:53:05 +0000 (10:53 +0100)
Disables menu buttons when ring view is visible to prevent setting
another timer's alarm while current is still ringing.

Change-Id: I976625b05a25f35a23a4cfcf297002279a56105d

clock/inc/Model/RingEvent.h
clock/inc/Presenter/TimerPresenter.h
clock/inc/View/TimerView.h
clock/src/Model/RingEvent.cpp [deleted file]
clock/src/Presenter/TimerPresenter.cpp
clock/src/View/TimerView.cpp

index 91e2ac94149777a12010302914db422fe6264275..9fff2995c2909a52a81685401a50f169bca82da7 100644 (file)
@@ -51,7 +51,7 @@ namespace model {
                         *
                         * @param[in] alarm The alarm passed with event
                         */
-                       RingNewAlarmEvent(Alarm &alarm);
+                       RingNewAlarmEvent(Alarm &alarm) : alarm_(&alarm) {};
 
                        /**
                         * @brief Gets event's alarm
index e7829c499e1ee9a18e8fc4ef94632722c4bae682..51f5ef4abfafc35e9a1ce3a8199ef8ec0716b6ff 100644 (file)
@@ -22,6 +22,7 @@
 #include "Model/Timer.h"
 #include "Common/CounterAnimator.h"
 #include "Utils/Signal.h"
+#include "Utils/EventBus.h"
 
 namespace presenter {
 
@@ -54,8 +55,9 @@ namespace presenter {
                void CancelButtonClicked();
 
                void TimeIsUp();
-
                void TimeUpdateRequest();
+               void RingDismissHandle(utils::Event &e);
+
                std::vector<utils::Connection> connections_;
        };
 
index 8b50f4d8d68145e1228e070c21f39f88072c545b..82d965e832dcd53c70eebe706022b74222d49cb6 100644 (file)
@@ -105,15 +105,21 @@ namespace view {
                utils::Signal<void(void)> OnCounterUnfocused;
 
                /**
-                * @brief Enables Start button
+                * @brief Sets all menu buttons enabled
                 *
-                * When time selector's time is set to 00:00:00 which is default value,
-                * the Start button is disabled. This might be changed whenever this
-                * value changes.
+                * Enables all timer's menu buttons.
                 *
                 * @param[in] enable The enable flag
                 */
-               void SetEnabledStartButton(bool enable);
+               void SetAllButtonsEnabled(bool enable);
+
+               /**
+                * @brief Enables button
+                *
+                * @param[in] name Name of the button
+                * @param[in] enable The enable flag
+                */
+               void SetButtonEnabled(const char *name, bool enable);
 
                /**
                 * @brief Displays time in counter's view
@@ -202,6 +208,7 @@ namespace view {
                void CreateMenuButtons();
                Evas_Object *CreateEntry(Evas_Object *parent, const char *part, const char *description);
                void CreateEntries(Evas_Object *parent);
+               void SetStartButtonEnabled(bool enable);
 
                void UpdateView();
                void UpdateTime();
diff --git a/clock/src/Model/RingEvent.cpp b/clock/src/Model/RingEvent.cpp
deleted file mode 100644 (file)
index 681c921..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-* Copyright 2016  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 "Model/RingEvent.h"
-
-namespace model {
-
-RingNewAlarmEvent::RingNewAlarmEvent(Alarm &alarm) :
-       alarm_(&alarm)
-{
-}
-
-} //namespace model
index 26fa3da5b20a4d4c76b3e4ea784e38421ce32c45..fbe46e15fed3060b7ce9057f96e0bc108c5fa3de 100644 (file)
@@ -15,7 +15,9 @@
 */
 
 #include "Presenter/TimerPresenter.h"
+#include "Utils/EventBus.h"
 #include "Utils/Log.h"
+#include "Model/RingEvent.h"
 
 namespace presenter {
 
@@ -36,6 +38,10 @@ TimerPresenter::TimerPresenter(view::TimerView *view, model::Timer *model)
                                std::bind(&TimerPresenter::ResetButtonClicked, this)));
        connections_.push_back(animator_.OnTick.Connect(
                                std::bind(&TimerPresenter::TimeUpdateRequest, this)));
+
+       connections_.push_back(utils::EventBus::AddListener<model::RingDismissEvent>(
+                               std::bind(&TimerPresenter::RingDismissHandle,
+                               this, std::placeholders::_1)));
 }
 
 TimerPresenter::~TimerPresenter()
@@ -109,8 +115,15 @@ void TimerPresenter::TimeIsUp()
 {
        model_->Stop();
        model_->Reset();
+       view_->SetAllButtonsEnabled(false);
        animator_.Stop();
        view_->ShowEditingMenu();
 }
 
+void TimerPresenter::RingDismissHandle(utils::Event &e)
+{
+       if (view_)
+               view_->SetAllButtonsEnabled(true);
+}
+
 } //namespace presenter
index 4ba652909bd96f05c322c91f1787f1b2f4be9679..a9b4d332bb2635e864259b347ad7ed3ae76a779e 100644 (file)
@@ -334,10 +334,10 @@ void TimerView::EntryChangedCb(void *data, Evas_Object *obj, void *event_info)
        object->UpdateTime();
 
        if (object->set_time_.Hour || object->set_time_.Min || object->set_time_.Sec) {
-               object->SetEnabledStartButton(true);
+               object->SetStartButtonEnabled(true);
                object->ShowEditingMenu();
        } else {
-               object->SetEnabledStartButton(false);
+               object->SetStartButtonEnabled(false);
                object->ShowStartupMenu();
        }
 
@@ -452,21 +452,29 @@ void TimerView::CreateMenuButtons()
        CreateButton(layout_, "IDS_COM_SK_CANCEL", "sw.btn.cancel", CancelButtonClicked);
        CreateButton(layout_, "IDS_SWT_BUTTON_RESUME", "sw.btn.resume", ResumeButtonClicked);
 
-       SetEnabledStartButton(false);
+       SetStartButtonEnabled(false);
 }
 
-void TimerView::SetEnabledStartButton(bool enable)
-{
-       Evas_Object *startButton = elm_object_part_content_get(layout_, "sw.btn.start");
-       if (!startButton)
+void TimerView::SetButtonEnabled(const char *name, bool enable){
+       Evas_Object *button = elm_object_part_content_get(layout_, name);
+       if (!button)
                return;
 
-       Eina_Bool isDisabled = elm_object_disabled_get(startButton);
+       elm_object_disabled_set(button, !enable);
+}
+
+void TimerView::SetAllButtonsEnabled(bool enable)
+{
+       SetButtonEnabled("sw.btn.start", enable);
+       SetButtonEnabled("sw.btn.reset", enable);
+       SetButtonEnabled("sw.btn.pause", enable);
+       SetButtonEnabled("sw.btn.cancel", enable);
+       SetButtonEnabled("sw.btn.resume", enable);
+}
 
-       if (isDisabled && enable)
-               elm_object_disabled_set(startButton, EINA_FALSE);
-       else if (!isDisabled && !enable)
-               elm_object_disabled_set(startButton, EINA_TRUE);
+void TimerView::SetStartButtonEnabled(bool enable)
+{
+       SetButtonEnabled("sw.btn.start", enable);
 }
 
 void TimerView::CreateButton(Evas_Object *parent, const char *name,