TSAM-12362 Set schedule works wrongly 65/109965/4
authorOleksander Kostenko <o.kostenko@samsung.com>
Wed, 11 Jan 2017 11:55:49 +0000 (13:55 +0200)
committerOleksander Kostenko <o.kostenko@samsung.com>
Thu, 12 Jan 2017 15:20:40 +0000 (17:20 +0200)
TSAM-12501 "Do not disturb will automatically turn off at end time" doesnot display

Change-Id: I1b7f61ea5c4be86a843faac344b511c227d4bf79
Signed-off-by: Oleksander Kostenko <o.kostenko@samsung.com>
src/allowed-calls.c
src/common-efl.c
src/main.c
src/notification-setting-info.c
src/set-schedule-info.c

index 8a7bbe6121ed55b749ff771dc81c81ce92aa6b0c..b8594fa07b8f8511119ba1e37bf6f1d4f985e839 100755 (executable)
@@ -99,7 +99,6 @@ const char *get_allowed_calls_string()
        NOTISET_TRACE_BEGIN;
        int value = 0;
        notification_system_setting_get_dnd_allow_exceptions(get_system_setting(), NOTIFICATION_DND_ALLOWED_CALLS, &value);
-       free_system_setting();
        return items[value];
 }
 
@@ -126,7 +125,6 @@ static void popup_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
        if (check_state) {
                int value = 0;
                notification_system_setting_get_dnd_allow_exceptions(get_system_setting(), NOTIFICATION_DND_ALLOWED_CALLS, &value);
-               free_system_setting();
                if (value == NOTIFICATION_DND_ALLOWED_CALLS_CONTACT)
                        set_do_not_show_contact_popup_again(false);
                else if (value == NOTIFICATION_DND_ALLOWED_CALLS_FAVORITE)
index 5aed1cf8da1da7846aece26f4735c28b6a334840..ab6e689b85d470b2fe904795fd1b37b0b9851f56 100755 (executable)
@@ -21,6 +21,7 @@
 #include "lock_screen_content.h"
 #include "app-details.h"
 #include "excepted-apps-efl.h"
+#include <notification.h>
 
 #define ICON_SIZE ELM_SCALE_SIZE(82)
 
@@ -200,6 +201,8 @@ static void _do_not_disturb_check_changed_cb(void *data, Evas_Object *obj, void
        set_do_not_disturb(state);
        update_system_settings();
        NOTISET_DBG("do_not_disturb check value = %s", state == false ? "FALSE" : "TRUE");
+       if(get_do_not_disturb() && get_schedule())
+               notification_status_message_post("Do not disturb will automatically turn off at end time."); // TODO: IDS
 }
 
 static Evas_Object *gl_content_get_cb(void *data, Evas_Object *obj, const char *part)
index e8c3c53bd0c24bfb099a66241dc62c74129a9566..971ed7b27f71d2d40356a83fdf315d4f89303439 100755 (executable)
@@ -159,6 +159,7 @@ static void _dnd_state_changed(void *user_data, int do_not_disturb)
        ug_data *ugd = (ug_data *)user_data;
        ret_if(!ugd);
 
+       free_system_setting();
        elm_genlist_item_update(ugd->dnd_check_item);
 }
 
index 6d74a3c54e593512996d554f79b4ba3c1af594cc..fb81f477841f08773747f7f9f0a64f5197e7162c 100755 (executable)
@@ -303,7 +303,6 @@ bool get_do_not_disturb()
        bool do_not_disturb = false;
 
        notification_system_setting_get_do_not_disturb(get_system_setting(), &do_not_disturb);
-       free_system_setting();
        NOTISET_DBG("do_not_disturb [%d]\n", do_not_disturb);
 
        return do_not_disturb;
index 08a83e1baab653f0ffbbf5a33d9367d5505bde9a..c10274c023cf8902e1c07eabcc56c0c56594dbf2 100755 (executable)
@@ -53,6 +53,9 @@ enum TimeFormat {
 #define DAYS_IN_WEEK 7
 #define NUMBER_OF_SPACES 6
 #define WEEK_MAX_STRING DAY_MAX_LENGTH * DAYS_IN_WEEK + NUMBER_OF_SPACES + 1
+#define MINUTES_IN_HOUR 60
+#define HOURS_IN_DAY 24
+
 
 #define GREEN_TEXT_COLOR "<font_size=80><color=#b3b3b3>%s</color></font_size>"
 #define GREY_TEXT_COLOR "<font_size=80><color=#97e57b>%s</color></font_size>"
@@ -106,6 +109,45 @@ static char *get_timezone();
 static char *get_formatted_date(const char *locale, const char *best_pattern, time_t time);
 static char *make_time_string(time_t curr_time);
 static void calc_label_size(Evas_Object *label);
+static void show_user_change_schedule_popup();
+
+static bool is_current_time_in_scheduled_time_range()
+{
+       time_t rawtime = time(NULL);
+       struct tm curtime = {};
+       localtime_r(&rawtime, &curtime);
+       int start_hour = 0;
+       int start_min = 0;
+       int end_hour = 0;
+       int end_min = 0;
+       int wday_map = DND_SCHEDULE_WEEK_FLAG_SUNDAY;
+       bool res = false;
+
+       notification_system_setting_dnd_schedule_get_day(get_system_setting(), &wday_map);
+       notification_system_setting_dnd_schedule_get_start_time(get_system_setting(), &start_hour, &start_min);
+       notification_system_setting_dnd_schedule_get_end_time(get_system_setting(), &end_hour, &end_min);
+
+       int start = MINUTES_IN_HOUR * start_hour + start_min;
+       int end = MINUTES_IN_HOUR * end_hour + end_min;
+       int cur = MINUTES_IN_HOUR * curtime.tm_hour + curtime.tm_min;
+       bool curr_day = wday_map & (1 << curtime.tm_wday);
+
+       if (is_next_day())
+       {
+               end += HOURS_IN_DAY * MINUTES_IN_HOUR;
+
+               int tm_prevwday = (curtime.tm_wday) ? curtime.tm_wday -1 : 6;
+               if (wday_map & (1 << tm_prevwday)) {
+                       cur += HOURS_IN_DAY * MINUTES_IN_HOUR;
+                       res = cur >= start && cur < end;
+               }
+       } else {
+               if (curr_day)
+                       res = cur >= start && cur < end;
+       }
+
+       return res;
+}
 
 static bool is_empty_str(const char *str)
 {
@@ -364,9 +406,27 @@ void set_schedule_check_changed_cb(void *data, Evas_Object *obj, void *event_inf
        ret_if(ug_main == NULL);
        bool check = elm_check_state_get(obj);
        enable_time_items(check);
+       elm_genlist_item_update(elm_genlist_item_next_get(elm_genlist_first_item_get(ug_main->list_main)));
+
        set_set_schedule(check);
+
+       if(check) {
+               if(get_do_not_disturb()) {
+                       notification_status_message_post("Do not disturb will automatically turn off at end time."); // TODO: IDS
+               } else {
+                       if(is_current_time_in_scheduled_time_range()) {
+                               set_do_not_disturb(true);
+                               notification_status_message_post("Do not disturb enabled. Current time is between start and end times."); // TODO: IDS
+                       }
+               }
+       } else {
+               if(is_current_time_in_scheduled_time_range()) {
+                       set_do_not_disturb(false);
+                       notification_status_message_post("Do not disturb disabled."); // TODO: IDS
+               }
+       }
+
        update_system_settings();
-       elm_genlist_item_update(elm_genlist_item_next_get(elm_genlist_first_item_get(ug_main->list_main)));
 }
 
 int get_time_format()
@@ -397,7 +457,6 @@ bool get_schedule()
        bool set_schedule = false;
 
        notification_system_setting_dnd_schedule_get_enabled(get_system_setting(), &set_schedule);
-       free_system_setting();
 
        NOTISET_DBG("get_schedule [%d]\n", set_schedule);
        return set_schedule;
@@ -434,14 +493,6 @@ static bool same_time(struct tm *timeA, struct tm *timeB)
        return difftime(t1, t2) == 0.0;
 }
 
-static void save_date_time(datetime_s *dt)
-{
-       if (dt->saved_time.tm_hour == start_time_p.saved_time.tm_hour && dt->saved_time.tm_min == start_time_p.saved_time.tm_min)
-               notification_system_setting_dnd_schedule_set_start_time(get_system_setting(), dt->saved_time.tm_hour, dt->saved_time.tm_min);
-       else
-               notification_system_setting_dnd_schedule_set_end_time(get_system_setting(), dt->saved_time.tm_hour, dt->saved_time.tm_min);
-}
-
 static void week_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
 {
        NOTISET_TRACE_BEGIN;
@@ -463,7 +514,9 @@ static void week_button_clicked_cb(void *data, Evas_Object *obj, void *event_inf
        calc_label_size(cc->label);
        cc->change_color = !cc->change_color;
        save_dnd_weekday(new_dnd_schedule_weekday);
-       ecore_main_loop_iterate(); /* update_system_settings work slow, so we use ui at first */
+
+       show_user_change_schedule_popup();
+
        update_system_settings();
 }
 
@@ -545,6 +598,17 @@ static void popup_cancel_btn_clicked_cb(void *data , Evas_Object *obj , void *ev
        evas_object_del(data);
 }
 
+static void show_user_change_schedule_popup()
+{
+       bool res = is_current_time_in_scheduled_time_range();
+       if(res)
+               notification_status_message_post("Do not Disturb enabled. Current time is between start and end times."); //TODO: IDS
+       else
+               notification_status_message_post("Do not Disturb disabled. Current time is not between start and end times."); //TODO: IDS
+
+       set_do_not_disturb(res);
+}
+
 static void popup_set_btn_clicked_cb(void *data , Evas_Object *obj , void *event_info)
 {
        NOTISET_TRACE_BEGIN;
@@ -571,6 +635,7 @@ static void popup_set_btn_clicked_cb(void *data , Evas_Object *obj , void *event
 
        evas_object_del(dt->popup);
 
+       show_user_change_schedule_popup();
        update_system_settings();
 }