AlarmView,WeekFlagsView: use locale settings for ordering 24/141024/3
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 27 Jul 2017 14:52:28 +0000 (16:52 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 28 Jul 2017 08:58:02 +0000 (08:58 +0000)
Use SystemSettings::GetFirstDayOfWeek to implement proper order
of WeekFlags which depends on platforms locale settings.

Change-Id: I9b20c1f687419e52c9ef3dac18f200f2d384cf9a

clock/inc/Model/WeekFlags.h
clock/inc/View/AlarmListView.h
clock/inc/View/WeekFlagsView.h
clock/src/Model/WeekFlags.cpp
clock/src/View/AlarmListView.cpp
clock/src/View/WeekFlagsView.cpp

index 7704249..a4e1a8f 100644 (file)
@@ -111,6 +111,7 @@ namespace model {
                         */
                        inline bool operator==(const WeekFlags &a) const { return a.raw_flags == raw_flags; }
 
+                       static WeekDay GetNextWeekDay(WeekDay day);
                private:
                        unsigned int raw_flags;
        };
index 0fc16c5..af25b26 100644 (file)
@@ -145,7 +145,8 @@ namespace view {
                        Evas_Object *popup_;
                        Evas_Object *nocontent_layout_;
                        utils::Connection time_format_change_listener_;
-                       void TimeFormatChanged();
+                       utils::Connection language_change_listener_;
+                       void UpdateList();
                        void CreateNoContentLayout(Evas_Object *parent);
                        static void SetItemCheckboxStatus(Elm_Object_Item *item, bool is_snoozed);
                        static void SetItemActiveStatus(Elm_Object_Item *it, bool active);
index 6d57cf2..5b18345 100644 (file)
@@ -48,11 +48,15 @@ namespace view {
                        };
                        Evas_Object *list_;
                        model::WeekFlags &flags_;
-                       void AppendCheckableListItem(const char *, model::WeekDay);
+                       void AppendCheckableListItem(model::WeekDay);
                        void CheckBoxStatusUpdate();
                        void Toggle(model::WeekDay);
+                       void CreateList();
                        static void ItemSelectedCallback(void *, Evas_Object *, void *);
                        std::list<CheckBoxDesc*> check_boxes_;
+                       static const char *GetLabelForWeekDay(model::WeekDay day);
+                       void UpdateList();
+                       utils::Connection language_change_listener_;
        };
 } /* view */
 
index 0fdec6a..bd57a87 100644 (file)
@@ -15,6 +15,7 @@
 */
 
 #include <Model/WeekFlags.h>
+#include <Utils/Log.h>
 
 using namespace model;
 
@@ -62,3 +63,27 @@ bool WeekFlags::Empty() const
 {
        return raw_flags == 0;
 }
+
+WeekDay WeekFlags::GetNextWeekDay(WeekDay day)
+{
+       switch (day)
+       {
+               case model::WeekDay::SUNDAY:
+                       return model::WeekDay::MONDAY;
+               case model::WeekDay::MONDAY:
+                       return model::WeekDay::TUESDAY;
+               case model::WeekDay::TUESDAY:
+                       return model::WeekDay::WEDNESDAY;
+               case model::WeekDay::WEDNESDAY:
+                       return model::WeekDay::THURSDAY;
+               case model::WeekDay::THURSDAY:
+                       return model::WeekDay::FRIDAY;
+               case model::WeekDay::FRIDAY:
+                       return model::WeekDay::SATURDAY;
+               case model::WeekDay::SATURDAY:
+                       return model::WeekDay::SUNDAY;
+               default:
+                       FAT("Invalid WeekDay");
+                       return model::WeekDay::MONDAY;
+       }
+}
index d439d4a..a3dae54 100644 (file)
@@ -188,14 +188,16 @@ static std::string GetFormattedWeekDayAcronym(WeekDay day, bool on)
 static char *WeekFlag2FormattedString(WeekFlags flags)
 {
        std::stringstream weekflags;
+       WeekDay day, first_day;
 
-       weekflags << GetFormattedWeekDayAcronym(WeekDay::MONDAY, flags.IsOn(WeekDay::MONDAY));
-       weekflags << GetFormattedWeekDayAcronym(WeekDay::TUESDAY, flags.IsOn(WeekDay::TUESDAY));
-       weekflags << GetFormattedWeekDayAcronym(WeekDay::WEDNESDAY, flags.IsOn(WeekDay::WEDNESDAY));
-       weekflags << GetFormattedWeekDayAcronym(WeekDay::THURSDAY, flags.IsOn(WeekDay::THURSDAY));
-       weekflags << GetFormattedWeekDayAcronym(WeekDay::FRIDAY, flags.IsOn(WeekDay::FRIDAY));
-       weekflags << GetFormattedWeekDayAcronym(WeekDay::SATURDAY, flags.IsOn(WeekDay::SATURDAY));
-       weekflags << GetFormattedWeekDayAcronym(WeekDay::SUNDAY, flags.IsOn(WeekDay::SUNDAY));
+       day = first_day = SystemSettings::GetFirstDayOfWeek();
+
+       do
+       {
+               weekflags << GetFormattedWeekDayAcronym(day, flags.IsOn(day));
+               day = WeekFlags::GetNextWeekDay(day);
+       }
+       while (day != first_day);
 
        return strdup(weekflags.str().c_str());
 }
@@ -289,12 +291,14 @@ AlarmListView::AlarmListView(ui::IView &main) : popup_(nullptr), nocontent_layou
                         AlarmListView::MoreButtonClicked, this);
 
        time_format_change_listener_ = EventBus::AddListener<SystemSettings::TimeFormatChanged>(
-                       std::bind(&AlarmListView::TimeFormatChanged, this));
+                       std::bind(&AlarmListView::UpdateList, this));
+       language_change_listener_ = EventBus::AddListener<SystemSettings::LanguageChanged>(
+                       std::bind(&AlarmListView::UpdateList, this));
 
        CreateNoContentLayout(content_);
 }
 
-void AlarmListView::TimeFormatChanged()
+void AlarmListView::UpdateList()
 {
        elm_genlist_realized_items_update(genlist_);
 }
index 1fdbc12..d355769 100644 (file)
@@ -21,6 +21,7 @@
 #include <Elementary.h>
 
 #include "Utils/Log.h"
+#include "Utils/SystemSettings.h"
 
 using namespace view;
 using namespace utils;
@@ -30,6 +31,8 @@ using namespace model;
 WeekFlagsView::WeekFlagsView(view::MainView &main, WeekFlags &flags)
        : PageView(main), flags_(flags)
 {
+       language_change_listener_ = EventBus::AddListener<SystemSettings::LanguageChanged>(
+                       std::bind(&WeekFlagsView::UpdateList, this));
 }
 
 Evas_Object *WeekFlagsView::GetEvasObject()
@@ -65,7 +68,7 @@ void WeekFlagsView::ItemSelectedCallback(void *data, Evas_Object *obj, void *eve
        desc->context->CheckBoxStatusUpdate();
 }
 
-void WeekFlagsView::AppendCheckableListItem(const char *msgid, WeekDay val)
+void WeekFlagsView::AppendCheckableListItem(WeekDay val)
 {
        CheckBoxDesc *desc = new CheckBoxDesc;
        Elm_Object_Item *it;
@@ -77,7 +80,7 @@ void WeekFlagsView::AppendCheckableListItem(const char *msgid, WeekDay val)
        elm_check_state_set(desc->check, flags_.IsOn(val));
        it = elm_list_item_append(list_, NULL, NULL, desc->check,
                        WeekFlagsView::ItemSelectedCallback, desc);
-       elm_object_item_translatable_text_set(it, msgid);
+       elm_object_item_translatable_text_set(it, GetLabelForWeekDay(val));
        elm_atspi_accessible_relationship_append(desc->check, ELM_ATSPI_RELATION_CONTROLLED_BY, it);
        elm_atspi_accessible_relationship_append(desc->check, ELM_ATSPI_RELATION_DESCRIPTION_FOR, it);
        elm_atspi_accessible_relationship_append(it, ELM_ATSPI_RELATION_DESCRIBED_BY, desc->check);
@@ -85,6 +88,47 @@ void WeekFlagsView::AppendCheckableListItem(const char *msgid, WeekDay val)
 
 }
 
+const char *WeekFlagsView::GetLabelForWeekDay(WeekDay day)
+{
+       switch (day)
+       {
+               case WeekDay::ALL_WEEK:
+                       return "IDS_ALM_BODY_EVERYDAY";
+               case WeekDay::MONDAY:
+                       return "IDS_CLOCK_OPT_EVERY_MONDAY";
+               case WeekDay::TUESDAY:
+                       return "IDS_CLOCK_OPT_EVERY_TUESDAY";
+               case WeekDay::WEDNESDAY:
+                       return "IDS_CLOCK_OPT_EVERY_WEDNESDAY";
+               case WeekDay::THURSDAY:
+                       return "IDS_CLOCK_OPT_EVERY_THURSDAY";
+               case WeekDay::FRIDAY:
+                       return "IDS_CLOCK_OPT_EVERY_FRIDAY";
+               case WeekDay::SATURDAY:
+                       return "IDS_CLOCK_OPT_EVERY_SATURDAY_ABB";
+               case WeekDay::SUNDAY:
+                       return "IDS_CLOCK_OPT_EVERY_SUNDAY";
+               default:
+                       ERR("Not handled WeekDay flag");
+                       return "";
+       }
+}
+
+void WeekFlagsView::CreateList()
+{
+       WeekDay day, first_day;
+       day = first_day = SystemSettings::GetFirstDayOfWeek();
+
+       AppendCheckableListItem(WeekDay::ALL_WEEK);
+
+       do
+       {
+               AppendCheckableListItem(day);
+               day = WeekFlags::GetNextWeekDay(day);
+       }
+       while (day != first_day);
+}
+
 void WeekFlagsView::CreateContent(Evas_Object *parent)
 {
        list_ = elm_list_add(parent);
@@ -92,14 +136,7 @@ void WeekFlagsView::CreateContent(Evas_Object *parent)
        evas_object_size_hint_align_set(list_, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_show(list_);
 
-       AppendCheckableListItem("IDS_ALM_BODY_EVERYDAY", WeekDay::ALL_WEEK);
-       AppendCheckableListItem("IDS_CLOCK_OPT_EVERY_MONDAY", WeekDay::MONDAY);
-       AppendCheckableListItem("IDS_CLOCK_OPT_EVERY_TUESDAY", WeekDay::TUESDAY);
-       AppendCheckableListItem("IDS_CLOCK_OPT_EVERY_WEDNESDAY", WeekDay::WEDNESDAY);
-       AppendCheckableListItem("IDS_CLOCK_OPT_EVERY_THURSDAY", WeekDay::THURSDAY);
-       AppendCheckableListItem("IDS_CLOCK_OPT_EVERY_FRIDAY", WeekDay::FRIDAY);
-       AppendCheckableListItem("IDS_CLOCK_OPT_EVERY_SATURDAY_ABB", WeekDay::SATURDAY);
-       AppendCheckableListItem("IDS_CLOCK_OPT_EVERY_SUNDAY", WeekDay::SUNDAY);
+       CreateList();
 
        elm_object_item_translatable_text_set(navi_item_, "IDS_CLOCK_OPT_REPEAT_WEEKLY_ABB2");
        elm_object_item_content_set(navi_item_, list_);
@@ -112,3 +149,9 @@ void WeekFlagsView::DestroyContent()
        }
        check_boxes_.clear();
 }
+
+void WeekFlagsView::UpdateList()
+{
+       elm_list_clear(list_);
+       CreateList();
+}