Do not show clock main UI on alarm trigger 87/158387/2
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 31 Oct 2017 12:02:33 +0000 (13:02 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 31 Oct 2017 14:09:14 +0000 (15:09 +0100)
When alarm was triggered clock shows RingView and additionaly
creates MainView that was displayed under RingView.

This patch removes creation of MainView in situations other then
clicking on Clock icon on homescreen.

Change-Id: Ib75e569c0920a8b860042ff9cc5f950ea0542d33

clock/inc/Controller/MainController.h
clock/inc/Presenter/EditAlarmPresenter.h
clock/src/Controller/MainController.cpp
clock/src/Presenter/EditAlarmPresenter.cpp

index d23b9c6..58edc38 100644 (file)
@@ -80,7 +80,7 @@ namespace controller {
                        /**
                         * @brief Initializes application.
                         */
-                       int Init();
+                       void Init();
 
                        /**
                         * @brief Denitializes application.
@@ -138,21 +138,21 @@ namespace controller {
                        model::StopWatch *stop_watch_model_;
                        model::Timer *timer_model_;
 
-                       presenter::AlarmListPresenter *alarm_presenter_;
-                       presenter::WorldClockPresenter *world_clock_presenter_;
-                       presenter::StopWatchPresenter *stop_watch_presenter_;
-                       presenter::TimerPresenter *timer_presenter_;
-                       presenter::EditAlarmPresenter *edit_presenter_;
-                       presenter::DeleteAlarmPresenter *delete_presenter_;
-                       presenter::WorldClockDeletePresenter *world_clock_delete_presenter_;
-                       presenter::WorldClockReorderPresenter *world_clock_reorder_presenter_;
+                       presenter::AlarmListPresenter *alarm_presenter_ = nullptr;
+                       presenter::WorldClockPresenter *world_clock_presenter_ = nullptr;
+                       presenter::StopWatchPresenter *stop_watch_presenter_ = nullptr;
+                       presenter::TimerPresenter *timer_presenter_ = nullptr;
+                       presenter::EditAlarmPresenter *edit_presenter_ = nullptr;
+                       presenter::DeleteAlarmPresenter *delete_presenter_ = nullptr;
+                       presenter::WorldClockDeletePresenter *world_clock_delete_presenter_ = nullptr;
+                       presenter::WorldClockReorderPresenter *world_clock_reorder_presenter_ = nullptr;
 
-                       view::MainView main_view_;
+                       view::MainView *main_view_ = nullptr;
 
-                       view::EditAlarmView edit_page_;
-                       view::DeleteAlarmView delete_page_;
-                       view::WorldClockDeleteItemsView world_clock_delete_page_;
-                       view::WorldClockReorderView world_clock_reorder_page_;
+                       view::EditAlarmView *edit_page_ = nullptr;
+                       view::DeleteAlarmView *delete_page_ = nullptr;
+                       view::WorldClockDeleteItemsView *world_clock_delete_page_ = nullptr;
+                       view::WorldClockReorderView *world_clock_reorder_page_ = nullptr;
 
                        /**
                         * @brief Creates new "Edit" alarm page.
@@ -167,7 +167,7 @@ namespace controller {
                        /**
                         * @brief intiialized flag
                         */
-                       bool initialized_;
+                       bool initialized_ = false;
 
                        Ecore_Idler *idler_ = nullptr;
                        static Eina_Bool IdlerCb(void *data);
index efa4c5a..19e5f58 100644 (file)
@@ -38,7 +38,7 @@ namespace presenter {
                         * @param it the iterator to element in model to be edited.
                         * @param view instance which presenter will be managing
                         */
-                       EditAlarmPresenter(model::AlarmList &model, model::AlarmList::Iterator it, view::EditAlarmView &view);
+                       EditAlarmPresenter(model::AlarmList &model, model::AlarmList::Iterator it, view::EditAlarmView *view);
 
                        /**
                         * @brief Construct new presenter for new alarm creation.
@@ -46,13 +46,13 @@ namespace presenter {
                         * @param model AlarmList instance which presenter will be managing
                         * @param view instance which presenter will be managing
                         */
-                       EditAlarmPresenter(model::AlarmList &model, view::EditAlarmView &view);
+                       EditAlarmPresenter(model::AlarmList &model, view::EditAlarmView *view);
 
                        ~EditAlarmPresenter();
                private:
                        model::AlarmList &model_;
                        model::AlarmList::Iterator iterator_;
-                       view::EditAlarmView &view_;
+                       view::EditAlarmView *view_ = nullptr;
                        view::EditAlarmView::AlarmViewInfo info_;
                        void OnEditDone();
                        void OnEditCancel();
index ed576a0..9ce0523 100644 (file)
@@ -39,17 +39,7 @@ using namespace model;
 using std::placeholders::_1;
 
 MainController::MainController(model::AlarmProvider *provider) :
-       provider_(provider),
-       world_clock_model_(nullptr), stop_watch_model_(nullptr), timer_model_(nullptr),
-
-       alarm_presenter_(nullptr), world_clock_presenter_(nullptr), stop_watch_presenter_(nullptr),
-       timer_presenter_(nullptr), edit_presenter_(nullptr), delete_presenter_(nullptr),
-       world_clock_delete_presenter_(nullptr), world_clock_reorder_presenter_(nullptr),
-
-       edit_page_(main_view_), delete_page_(main_view_),
-       world_clock_delete_page_(main_view_), world_clock_reorder_page_(main_view_),
-
-       initialized_(false)
+       provider_(provider)
 {
 }
 
@@ -68,7 +58,7 @@ void MainController::Resume()
 Eina_Bool MainController::IdlerCb(void *data)
 {
        MainController *controller = static_cast<MainController *>(data);
-       MainView *mainView = &(controller->main_view_);
+       MainView *mainView = controller->main_view_;
 
        controller->world_clock_model_ = new model::WorldClock();
        controller->world_clock_presenter_ = new WorldClockPresenter(
@@ -89,11 +79,17 @@ Eina_Bool MainController::IdlerCb(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
-int MainController::Init()
+void MainController::Init()
 {
-       if (initialized_) return 0;
+       if (initialized_) return;
 
-       alarm_presenter_ = new AlarmListPresenter((AlarmListView *)main_view_.GetView(ALARM), provider_->GetAlarms());
+       main_view_ = new MainView();
+       edit_page_ = new EditAlarmView(*main_view_);
+       delete_page_ = new DeleteAlarmView(*main_view_);
+       world_clock_delete_page_ = new WorldClockDeleteItemsView(*main_view_);
+       world_clock_reorder_page_ = new WorldClockReorderView(*main_view_);
+
+       alarm_presenter_ = new AlarmListPresenter((AlarmListView *)main_view_->GetView(ALARM), provider_->GetAlarms());
 
        idler_ = ecore_idler_add(IdlerCb, this);
 
@@ -111,8 +107,6 @@ int MainController::Init()
                        std::bind(&MainController::CreateNewWorldClockReorderPage, this, _1)));
 
        initialized_ = true;
-
-       return 0;
 }
 
 void MainController::Deinit()
@@ -135,6 +129,12 @@ void MainController::Deinit()
        delete timer_presenter_;
        delete timer_model_;
 
+       delete edit_page_;
+       delete delete_page_;
+       delete world_clock_delete_page_;
+       delete world_clock_reorder_page_;
+       delete main_view_;
+
        connections_.clear();
        initialized_ = false;
 }
@@ -159,19 +159,19 @@ void MainController::CreateNewDeleteAlarmsPage(Event &e)
 {
        delete delete_presenter_;
 
-       delete_presenter_ = new DeleteAlarmPresenter(&delete_page_, provider_->GetAlarms());
+       delete_presenter_ = new DeleteAlarmPresenter(delete_page_, provider_->GetAlarms());
 }
 
 void MainController::CreateNewWorldClockDeletePage(utils::Event &e)
 {
        delete world_clock_delete_presenter_;
 
-       world_clock_delete_presenter_ = new WorldClockDeletePresenter(&world_clock_delete_page_, world_clock_model_);
+       world_clock_delete_presenter_ = new WorldClockDeletePresenter(world_clock_delete_page_, world_clock_model_);
 }
 
 void MainController::CreateNewWorldClockReorderPage(Event &e)
 {
        delete world_clock_reorder_presenter_;
 
-       world_clock_reorder_presenter_ = new WorldClockReorderPresenter(&world_clock_reorder_page_, world_clock_model_);
+       world_clock_reorder_presenter_ = new WorldClockReorderPresenter(world_clock_reorder_page_, world_clock_model_);
 }
index dacd77e..c85d5bc 100644 (file)
@@ -31,17 +31,17 @@ using std::placeholders::_1;
 
 const double time_truncate_factor = 60 * 1000; // 60 seconds
 
-EditAlarmPresenter::EditAlarmPresenter(AlarmList &model, AlarmList::Iterator it, view::EditAlarmViewview) :
+EditAlarmPresenter::EditAlarmPresenter(AlarmList &model, AlarmList::Iterator it, view::EditAlarmView *view) :
        model_(model), iterator_(it), view_(view)
 {
        connections_.push_back(
-               view_.OnEditDone.Connect(std::bind(&EditAlarmPresenter::OnEditDone, this)));
+               view_->OnEditDone.Connect(std::bind(&EditAlarmPresenter::OnEditDone, this)));
        connections_.push_back(
-                       view_.OnEditCancel.Connect(std::bind(&EditAlarmPresenter::OnEditCancel, this)));
+               view_->OnEditCancel.Connect(std::bind(&EditAlarmPresenter::OnEditCancel, this)));
        connections_.push_back(
-                       view_.OnBackButtonClicked.Connect(std::bind(&EditAlarmPresenter::OnBackButton, this)));
+               view_->OnBackButtonClicked.Connect(std::bind(&EditAlarmPresenter::OnBackButton, this)));
        connections_.push_back(
-               view_.OnDiscardPopupOptionSelected.Connect(std::bind(&EditAlarmPresenter::OnDiscardPopupOptionClicked, this, _1)))
+               view_->OnDiscardPopupOptionSelected.Connect(std::bind(&EditAlarmPresenter::OnDiscardPopupOptionClicked, this, _1)))
                ;
 
        if (iterator_ == model_.End()) {
@@ -52,19 +52,19 @@ EditAlarmPresenter::EditAlarmPresenter(AlarmList &model, AlarmList::Iterator it,
                mode_ = EditAlarmView::Mode::Edit;
        }
 
-       view_.SetData(info_);
-       view_.SetMode(mode_);
-       view_.PushPage();
+       view_->SetData(info_);
+       view_->SetMode(mode_);
+       view_->PushPage();
 }
 
-EditAlarmPresenter::EditAlarmPresenter(AlarmList &model, view::EditAlarmViewview) :
+EditAlarmPresenter::EditAlarmPresenter(AlarmList &model, view::EditAlarmView  *view) :
        EditAlarmPresenter(model, model.End(), view)
 {
 }
 
 EditAlarmPresenter::~EditAlarmPresenter()
 {
-       view_.PopPage();
+       view_->PopPage();
 }
 
 view::EditAlarmView::AlarmViewInfo EditAlarmPresenter::GetDefaultInfo() const
@@ -106,7 +106,7 @@ AlarmList::Iterator EditAlarmPresenter::GetMatchingAlarm(const std::string &name
        for (auto it = model_.Begin(); it != end; ++it)
        {
                if ((it->GetTime().Truncate(time_truncate_factor) == truncated_time) &&
-                       (it->GetName() == view_.GetData().name))
+                       (it->GetName() == view_->GetData().name))
                        return it;
        }
        return model_.End();
@@ -119,7 +119,7 @@ void EditAlarmPresenter::UpdateAlarm(AlarmList::Iterator it)
 {
        auto alarm = *it;
 
-       SetAlarmProperties(alarm, view_.GetData());
+       SetAlarmProperties(alarm, view_->GetData());
 
        if (alarm.GetWeekFlags().Empty() && alarm.GetTime() < Time::Now())
                alarm.Deactivate();
@@ -134,11 +134,11 @@ void EditAlarmPresenter::CreateNewAlarm()
        if (model_.Size() == model_.MaxSize()) {
                std::string text = Translate::Sprintf("IDS_ALM_BODY_MAXIMUM_NUMBER_OF_ALARMS_HPD_REACHED",
                                model_.MaxSize());
-               view_.ShowPopup(text);
+               view_->ShowPopup(text);
                return;
        }
 
-       SetAlarmProperties(new_alarm, view_.GetData());
+       SetAlarmProperties(new_alarm, view_->GetData());
 
        if (!new_alarm.GetWeekFlags().Empty() || new_alarm.GetTime() > Time::Now())
                new_alarm.Activate();
@@ -151,7 +151,7 @@ void EditAlarmPresenter::ShowAlarmUpdatedPopup(const Time &time)
        std::string text = Translate::Sprintf(
                        "IDS_CLOCK_TPOP_ALARM_ALREADY_SET_FOR_PS_EXISTING_ALARM_UPDATED",
                        time.Format("hh:mm a").c_str());
-       view_.ShowPopup(text);
+       view_->ShowPopup(text);
 }
 
 /**
@@ -168,7 +168,7 @@ void EditAlarmPresenter::ShowAlarmUpdatedPopup(const Time &time)
 void EditAlarmPresenter::OnEditDone()
 {
        // get alarm matching time & name entered in view
-       auto update_target = GetMatchingAlarm(view_.GetData().name, view_.GetData().time);
+       auto update_target = GetMatchingAlarm(view_->GetData().name, view_->GetData().time);
 
        if (mode_ == EditAlarmView::Mode::Edit) {
                // if matching alarm exists and different then edited one
@@ -188,7 +188,7 @@ void EditAlarmPresenter::OnEditDone()
                }
        }
 
-       view_.PopPage();
+       view_->PopPage();
 }
 
 void EditAlarmPresenter::SetAlarmProperties(Alarm &alarm, const EditAlarmView::AlarmViewInfo &data)
@@ -208,7 +208,7 @@ void EditAlarmPresenter::SetAlarmProperties(Alarm &alarm, const EditAlarmView::A
 
 void EditAlarmPresenter::OnEditCancel()
 {
-       view_.PopPage();
+       view_->PopPage();
 }
 
 void EditAlarmPresenter::OnDiscardPopupOptionClicked(EditAlarmView::DiscardPopupOption option)
@@ -216,11 +216,11 @@ void EditAlarmPresenter::OnDiscardPopupOptionClicked(EditAlarmView::DiscardPopup
        switch (option)
        {
                case EditAlarmView::DiscardPopupOption::CANCEL:
-                       view_.HideDiscardPopup();
+                       view_->HideDiscardPopup();
                        break;
                case EditAlarmView::DiscardPopupOption::CONFIRM:
-                       view_.HideDiscardPopup();
-                       view_.PopPage();
+                       view_->HideDiscardPopup();
+                       view_->PopPage();
                        break;
        }
 }
@@ -238,13 +238,13 @@ static bool CompareAlarmInfoStructures(const EditAlarmView::AlarmViewInfo &info1
 
 void EditAlarmPresenter::OnBackButton()
 {
-       if (view_.IsDiscardPopupVisible())
+       if (view_->IsDiscardPopupVisible())
                return;
 
-       if (!CompareAlarmInfoStructures(info_, view_.GetData()))
+       if (!CompareAlarmInfoStructures(info_, view_->GetData()))
        {
-               view_.ShowDiscardPopup();
+               view_->ShowDiscardPopup();
        } else {
-               view_.PopPage();
+               view_->PopPage();
        }
 }