World Clock: Time updating implemented 52/93952/4
authorRadoslaw Czerski <r.czerski@samsung.com>
Thu, 27 Oct 2016 10:48:08 +0000 (12:48 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Wed, 2 Nov 2016 08:24:34 +0000 (01:24 -0700)
Change-Id: I0b34ba3d1b9106ab7da69e405eadddab22d8f9b2
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
clock/inc/Utils/WorldClock.h
clock/inc/View/WorldClockDeleteItemsView.h
clock/inc/View/WorldClockReorderView.h
clock/inc/View/WorldClockView.h
clock/src/Presenter/WorldClockPresenter.cpp
clock/src/Utils/WorldClock.cpp
clock/src/View/WorldClockDeleteItemsView.cpp
clock/src/View/WorldClockReorderView.cpp
clock/src/View/WorldClockView.cpp

index 0280d0dd028807914c657ed7b3eacca5786f8165..f1d1c50cefd57e73ae6e99d490e9a13dfa270a48 100644 (file)
@@ -32,6 +32,12 @@ namespace utils {
  */
 std::string GetTimezoneDiffDescription(int local_timezone_offset, int timezone_offset);
 
+/**
+ * @brief Retrieves seconds to the next exact minute(e.g. for 15:33:44:200 the returned is 15,800)
+ *
+ * @return seconds to round minute
+ */
+double GetSecondsToNextExactMinute();
 }
 #endif /* _CLOCK_UTILS_WORLDCLOCK_H_ */
 
index 767b0c576f212bc98cd760cce9186088485dbc6c..984ff0e7ac0c8ea38837644ef9b61594e25b294e 100644 (file)
@@ -131,6 +131,11 @@ namespace view {
                         */
                        Evas_Object *select_all_checkbox_;
 
+                       /**
+                        * @brief Timer for time and date updating
+                        */
+                       Ecore_Timer *timer_;
+
                        /**
                         * @brief Item class for the main content genlist
                         */
@@ -235,6 +240,13 @@ namespace view {
                         * @brief Emits LIST_ITEM_CLICKED signal and toggle checkbox state.
                         */
                        static void ItemSelectToggle(void *data, Evas_Object *obj, void *event_info);
+
+                       /**
+                        * @brief Timer callback for time updates.
+                        * @param data user data
+                        * @return EINA_BOOL to allow next invocation of callback, EINA_FALSE otherwise
+                        */
+                       static Eina_Bool TimeUpdateCb(void *data);
        };
 
 } /* view */
index fe1c61ee1d97443521597be9646896a7c0522319..6670a0ae876a07ae51348b956f75c82eb559d5f7 100644 (file)
@@ -101,6 +101,11 @@ namespace view {
                         */
                        static Elm_Genlist_Item_Class world_clock_reorder_items_view_itc_;
 
+                       /**
+                        * @brief Timer for time and date updating
+                        */
+                       Ecore_Timer *timer_;
+
                        /**
                         * @brief list of signals
                         */
@@ -171,6 +176,13 @@ namespace view {
                         * @remarks Invoked by clicking BACK naviframe button or back hardware key
                         */
                        static void OnBackButtonClicked(void *data, Evas_Object *obj, void *event_info);
+
+                       /**
+                        * @brief Timer callback for time updates.
+                        * @param data user data
+                        * @return EINA_BOOL to allow next invocation of callback, EINA_FALSE otherwise
+                        */
+                       static Eina_Bool TimeUpdateCb(void *data);
        };
 
 } /* view */
index b9eb067a83efbdf80dc0ac54c461882e9154972f..260cab546b8dea6d61abf5b7d21f253e97943201 100644 (file)
@@ -36,6 +36,7 @@ namespace view {
 
                CUSTOM_LIST_ITEM_CLICKED,
                CUSTOM_LIST_ITEM_ADD,
+               CUSTOM_LIST_UPDATE_REQUEST,
 
                MAX
        };
@@ -54,6 +55,7 @@ namespace view {
                        };
 
                        WorldClockView(ui::IView &main);
+                       ~WorldClockView();
 
                        Evas_Object *GetEvasObject(){return world_clock_main_;};
 
@@ -124,6 +126,13 @@ namespace view {
 
                        static void AddLocationReplayCb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data);
 
+                       /**
+                        * @brief Timer callback for time updates.
+                        * @param data user data
+                        * @return EINA_BOOL to allow next invocation of callback, EINA_FALSE otherwise
+                        */
+                       static Eina_Bool TimeUpdateCb(void *data);
+
                        void SetItemLastClicked(const model::Location *location);
                        void SetItemToAdd(model::Location *l);
                        void EmitSignal(view::WorldClockSignals signal);
@@ -142,6 +151,11 @@ namespace view {
                        const model::Location *item_last_clicked_;
                        const model::Location *item_to_add_;
 
+                       /**
+                        * @brief Timer for time and date updating
+                        */
+                       Ecore_Timer *timer_;
+
                        std::vector<std::function<void(void)>> signals
                                                = std::vector<std::function<void(void)>>((int)WorldClockSignals::MAX, nullptr);
        };
index c7ca4817327b42f28cff7498ee4fb6707b61290f..461d6071160af0d13667026caac7a8430d3d9a15 100644 (file)
@@ -40,12 +40,14 @@ WorldClockPresenter::WorldClockPresenter(WorldClockView *view, WorldClock *model
                        WorldClockSignals::CUSTOM_LIST_ITEM_CLICKED);
        view_->RegisterSignal(std::bind(&WorldClockPresenter::OnItemAdded, this),
                        WorldClockSignals::CUSTOM_LIST_ITEM_ADD);
+       view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMapViewUpdateRequest, this),
+                       WorldClockSignals::CUSTOM_LIST_UPDATE_REQUEST);
        view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMoreButtonClicked, this),
                        WorldClockSignals::BUTTON_MORE_CLICKED);
        view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMoreDeleteButtonClicked, this),
                        WorldClockSignals::BUTTON_MORE_DELETE_CLICKED);
        view_->RegisterSignal(std::bind(&WorldClockPresenter::OnMoreReorderButtonClicked, this),
-                               WorldClockSignals::BUTTON_MORE_REORDER_CLICKED);
+                       WorldClockSignals::BUTTON_MORE_REORDER_CLICKED);
 
        model_->RegisterSignalHandler(WorldClock::ParameterSignalType::USER_LOCATION_REMOVED,
                        std::bind(&WorldClockPresenter::OnItemDeleted, this, _1));
@@ -53,7 +55,7 @@ WorldClockPresenter::WorldClockPresenter(WorldClockView *view, WorldClock *model
        model_->RegisterSignalHandler(WorldClock::SignalType::CUSTOM_LIST_CHANGED,
                        std::bind(&WorldClockPresenter::OnCustomListChanged, this));
 
-       view_->UpdateMapAndTimezoneDetails(model_->GetCurrentTimezone());
+       OnMapViewUpdateRequest();
 
        for (auto it = model_->user_locations_.begin(); it != model_->user_locations_.end(); it++)
                view_->AppendItemToCustomList(*it);
@@ -76,13 +78,13 @@ void WorldClockPresenter::UpdateEmptyListBackground()
 void WorldClockPresenter::OnLeftArrowButtonClicked()
 {
        model_->MoveCurrentTimezone(model::WorldClock::LEFT);
-       view_->UpdateMapAndTimezoneDetails(model_->GetCurrentTimezone());
+       OnMapViewUpdateRequest();
 }
 
 void WorldClockPresenter::OnRightArrowButtonClicked()
 {
        model_->MoveCurrentTimezone(model::WorldClock::RIGHT);
-       view_->UpdateMapAndTimezoneDetails(model_->GetCurrentTimezone());
+       OnMapViewUpdateRequest();
 }
 
 void WorldClockPresenter::OnCustomListItemClicked()
@@ -90,7 +92,7 @@ void WorldClockPresenter::OnCustomListItemClicked()
        const model::Location *location = view_->GetLastClickedItem();
 
        model_->SetCurrentTimezone(model_->GetTimezoneByOffset(location->gmt_offset_));
-       view_->UpdateMapAndTimezoneDetails(model_->GetCurrentTimezone());
+       OnMapViewUpdateRequest();
 
 }
 
@@ -123,7 +125,7 @@ void WorldClockPresenter::OnItemAdded()
                }
 
                model_->SetCurrentTimezone(t);
-               view_->UpdateMapAndTimezoneDetails(model_->GetCurrentTimezone());
+               OnMapViewUpdateRequest();
                view_->AppendItemToCustomList(l);
        } else {
                view_->PostItemExistMessage();
index a72297d9d6f6d4d7306e0a9bf8661fa4d6600f14..59a87502789d77a512cfffd26d51ed4297b87d60 100644 (file)
@@ -16,6 +16,7 @@
 #include <app_i18n.h>
 
 #include "Utils/WorldClock.h"
+#include "Utils/Time.h"
 
 namespace utils {
 // local_timezone_offset and timezone_offset should be relative to GMT
@@ -51,4 +52,14 @@ std::string GetTimezoneDiffDescription(int local_timezone_offset, int timezone_o
        return relative;
 }
 
+
+double GetSecondsToNextExactMinute()
+{
+       Time t = Time::Now();
+       double s = t.GetSecond();
+       double ms = t.GetMilliSec();
+       double diff = 60 - s - (ms / 1000);
+       return diff;
+}
+
 } /* utils */
index 2b869a17c7a368a0ea1dde9ac0bf381a8455df20..5f258390a8b75c41e7ed84aea0399a34c79f9bb5 100644 (file)
@@ -17,6 +17,8 @@
 #include <efl_extension.h>
 #include <vector>
 #include <sstream>
+#include <tuple>
+
 #include "View/WorldClockDeleteItemsView.h"
 #include "Internal/WorldClockDefs.h"
 #include "Model/Location.h"
@@ -230,8 +232,20 @@ Evas_Object *WorldClockDeleteItemsView::GetEvasObject()
        return content_;
 }
 
+Eina_Bool WorldClockDeleteItemsView::TimeUpdateCb(void *data)
+{
+       WorldClockDeleteItemsView *view = static_cast<WorldClockDeleteItemsView *>(data);
+       elm_genlist_realized_items_update(view->content_);
+
+       ecore_timer_interval_set(view->timer_, utils::GetSecondsToNextExactMinute());
+
+       return EINA_TRUE;
+}
+
 void WorldClockDeleteItemsView::CreateContent(Evas_Object *parent)
 {
+       double time_delta;
+
        elm_object_item_style_set(navi_item_, "basic");
 
        static bool extension_init = false;
@@ -268,6 +282,11 @@ void WorldClockDeleteItemsView::CreateContent(Evas_Object *parent)
        elm_object_item_part_content_set(navi_item_, "title_right_btn", right_button_);
        elm_object_item_content_set(navi_item_, content_);
 
+       time_delta = utils::GetSecondsToNextExactMinute();
+
+       timer_ = ecore_timer_add(time_delta, WorldClockDeleteItemsView::TimeUpdateCb, this);
+       if (!timer_)
+               FAT("Unable to create timer!");
        CreateSelectAll();
 }
 
@@ -308,6 +327,7 @@ void WorldClockDeleteItemsView::CreateSelectAll()
 
 void WorldClockDeleteItemsView::DestroyContent()
 {
+       ecore_timer_del(timer_);
        evas_object_del(content_);
        evas_object_del(left_button_);
        evas_object_del(right_button_);
index d3d8710bf11a6a0b699a5b009f7af93bf93228c0..5d13d4b1234697013dfc71e3f94ea3acb247d7c3 100644 (file)
@@ -104,9 +104,20 @@ void WorldClockReorderView::AppendItems(
        }
 }
 
+Eina_Bool WorldClockReorderView::TimeUpdateCb(void *data)
+{
+       WorldClockReorderView *view = static_cast<WorldClockReorderView *>(data);
+       elm_genlist_realized_items_update(view->content_);
+
+       ecore_timer_interval_set(view->timer_, utils::GetSecondsToNextExactMinute());
+
+       return EINA_TRUE;
+}
 
 void WorldClockReorderView::CreateContent(Evas_Object *parent)
 {
+       double time_delta;
+
        elm_object_item_style_set(navi_item_, "basic");
 
        static bool extension_init = false;
@@ -137,10 +148,17 @@ void WorldClockReorderView::CreateContent(Evas_Object *parent)
        elm_object_item_content_set(navi_item_, content_);
 
        evas_object_smart_callback_add(content_, "moved" , OnListReordered, this);
+
+       time_delta = utils::GetSecondsToNextExactMinute();
+
+       timer_ = ecore_timer_add(time_delta, WorldClockReorderView::TimeUpdateCb, this);
+       if (!timer_)
+               FAT("Unable to create timer!");
 }
 
 void WorldClockReorderView::DestroyContent()
 {
+       ecore_timer_del(timer_);
        evas_object_del(content_);
        evas_object_del(left_button_);
 }
index 3b795071fe3376fc51ab7d50640ef082ae4a7b4e..3f29455da796e371446567c111c55a3dfe9f25f8 100644 (file)
@@ -226,8 +226,21 @@ void message_cb(void *data, Evas_Object *obj, Edje_Message_Type type, int id, vo
        }
 }
 
+Eina_Bool WorldClockView::TimeUpdateCb(void *data)
+{
+       WorldClockView *view = static_cast<WorldClockView *>(data);
+       elm_genlist_realized_items_update(view->custom_locations_list_);
+       view->EmitSignal(view::WorldClockSignals::CUSTOM_LIST_UPDATE_REQUEST);
+
+       ecore_timer_interval_set(view->timer_, utils::GetSecondsToNextExactMinute());
+
+       return EINA_TRUE;
+}
+
 WorldClockView::WorldClockView(ui::IView &main)
 {
+       double time_delta;
+
        world_clock_main_ = elm_layout_add(main.GetEvasObject());
        evas_object_size_hint_align_set(world_clock_main_, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_size_hint_weight_set(world_clock_main_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -264,8 +277,18 @@ WorldClockView::WorldClockView(ui::IView &main)
        elm_layout_signal_callback_add(world_clock_, "timezone,go,right",
                "main.world.map:arrow.right", ChangeTimezoneCb,
                static_cast<void *>(this));
+
+       time_delta = utils::GetSecondsToNextExactMinute();
+
+       timer_ = ecore_timer_add(time_delta, WorldClockView::TimeUpdateCb, this);
+       if (!timer_)
+               FAT("Unable to create timer!");
 }
 
+WorldClockView::~WorldClockView()
+{
+       ecore_timer_del(timer_);
+}
 
 void WorldClockView::MoreButtonClicked(void *data, Evas_Object *obj, void *info)
 {