[SM][Mob]Code cleanup 2 92/154892/3
authorPawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
Wed, 11 Oct 2017 10:43:08 +0000 (12:43 +0200)
committerPawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
Wed, 11 Oct 2017 16:05:02 +0000 (18:05 +0200)
Change-Id: I9710514278682b2d022a8bd3403d4aaa2ddb7dde
Signed-off-by: Pawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
setting-smartmanager/smartmanager-data/src/smartmanager-data-usage-mobile-settings.c

index 8b0aa94353aca512aa2e4292379903bdb0c9c95c..33bf882f809274d1f70a920102747effc236068a 100755 (executable)
@@ -433,7 +433,8 @@ void write_cycle_interval(SmartMgrData *smd)
 {
        if (smd->selected_sim_subscriber_id == smd->subscriber_id_1) {
                write_sim_1_cycle_interval(smd->selected_sim_limits->custom_mode_interval);
-       } else if (smd->selected_sim_subscriber_id == smd->subscriber_id_2) {
+       }
+       if (smd->selected_sim_subscriber_id == smd->subscriber_id_2) {
                write_sim_2_cycle_interval(smd->selected_sim_limits->custom_mode_interval);
        }
 }
@@ -448,17 +449,19 @@ static void _custom_cycle_popup_ok_cb(void *data, Evas_Object *obj,
 
        if (value_str) {
                value = atoi(value_str);
-               if (value < 0) {
+               if (value < 1) {
                        create_toast_popup(popup_info.popup,
                                        "Minimum value allowed is 1. Value changed to 1");
                        smd->selected_sim_limits->custom_mode_interval = 1;
-                       elm_object_text_set(popup_info.content, "0");
-               } else if (value > 90) {
+                       elm_object_text_set(popup_info.content, "1");
+               }
+               if (value > 90) {
                        create_toast_popup(popup_info.popup,
                                        "Maximum value allowed is 90. Value changed to 90");
                        smd->selected_sim_limits->custom_mode_interval = 90;
                        elm_object_text_set(popup_info.content, "90");
-               } else {
+               }
+               if (value >= 1 && value <= 90) {
                        smd->selected_sim_limits->custom_mode_interval = value;
                        complement_data_usage_mobile_genlist(
                                                        mobile_data_setting_genlist,
@@ -516,7 +519,8 @@ void write_cycle_mode(SmartMgrData *smd)
 {
        if (smd->selected_sim_subscriber_id == smd->subscriber_id_1)  {
                write_sim_1_cycle_mode(smd->selected_sim_limits->cycle_mode);
-       } else if (smd->selected_sim_subscriber_id == smd->subscriber_id_2) {
+       }
+       if (smd->selected_sim_subscriber_id == smd->subscriber_id_2) {
                write_sim_2_cycle_mode(smd->selected_sim_limits->cycle_mode);
        }
 }
@@ -525,7 +529,8 @@ void write_cycle_start(SmartMgrData *smd)
 {
        if (smd->selected_sim_subscriber_id == smd->subscriber_id_1)  {
                write_sim_1_cycle_start(smd->selected_sim_limits->cycle_start);
-       } else if (smd->selected_sim_subscriber_id == smd->subscriber_id_2)  {
+       }
+       if (smd->selected_sim_subscriber_id == smd->subscriber_id_2)  {
                write_sim_2_cycle_start(smd->selected_sim_limits->cycle_start);
        }
 }
@@ -539,26 +544,32 @@ static void _custom_start_date_popup_ok_cb(void *data, Evas_Object *obj,
        struct tm set_date_tm = {0};
        struct tm min_date = {0};
        struct tm max_date = {0};
+       time_t min_date_time_t = 0;
+       time_t max_date_time_t = 0;
        SmartMgrData *smd = (SmartMgrData *)data;
 
        elm_datetime_value_get(popup_info.content, (Elm_Datetime_Time *)&set_date_tm);
        set_date = mktime(&set_date_tm);
        min_date = _get_margin_date(DATE_MIN);
+       min_date_time_t = mktime(&min_date);
        max_date = _get_margin_date(DATE_MAX);
+       max_date_time_t = mktime(&max_date);
 
-       if (set_date < mktime(&min_date)) {
+       if (set_date < min_date_time_t) {
                strftime(margin_date_buf, sizeof(margin_date_buf), date_format, &min_date);
                snprintf(buf, sizeof(buf), "Start date can't be before %s. Start date changed to %s.", margin_date_buf, margin_date_buf);
                create_toast_popup(popup_info.popup, buf);
                smd->selected_sim_limits->cycle_start = mktime(&min_date);
                elm_datetime_value_set(popup_info.content, (Elm_Datetime_Time *)&min_date);
-       } else if (set_date > mktime(&max_date)) {
+       }
+       if (set_date > max_date_time_t) {
                strftime(margin_date_buf, sizeof(margin_date_buf), date_format, &max_date);
                snprintf(buf, sizeof(buf), "Start date can't be after %s. Start date changed to current date.", margin_date_buf);
                create_toast_popup(popup_info.popup, buf);
                smd->selected_sim_limits->cycle_start = mktime(&max_date);
                elm_datetime_value_set(popup_info.content, (Elm_Datetime_Time *)&max_date);
-       } else {
+       }
+       if (set_date >= min_date_time_t && set_date <= max_date_time_t) {
                smd->selected_sim_limits->cycle_start = set_date;
                complement_data_usage_mobile_genlist(mobile_data_setting_genlist, smd);
 
@@ -569,6 +580,26 @@ static void _custom_start_date_popup_ok_cb(void *data, Evas_Object *obj,
        }
 }
 
+static void handle_limit_warning_set_result(restrictions_result result,
+               int64_t *limit_to_set, int64_t value)
+{
+       switch (result) {
+       case RESTRICTIONS_VALUE_HIGHTER_THAN_MAX:
+               create_toast_popup(popup_info.popup,
+                       "Maximum value allowed is 100GB. Value changed to 100GB");
+               *limit_to_set = MAX_LIMIT_IN_BYTES;
+               break;
+       case RESTRICTIONS_VALUE_HIGHER_THAN_LIMIT:
+               create_toast_popup(popup_info.popup,
+                       "Value must be lower than limit value");
+               break;
+       default:
+               *limit_to_set = (int64_t)value;
+               evas_object_del(popup_info.popup);
+               break;
+       }
+}
+
 static void _warning_popup_done_cb(void *data, Evas_Object *obj, void *event_info)
 {
        SmartMgrData *smd = (SmartMgrData *)data;
@@ -593,17 +624,7 @@ static void _warning_popup_done_cb(void *data, Evas_Object *obj, void *event_inf
                                        (int64_t)value);
        }
 
-       if (RESTRICTIONS_VALUE_HIGHTER_THAN_MAX == res) {
-               create_toast_popup(popup_info.popup,
-                               "Maximum value allowed is 100GB. Value changed to 100GB");
-               smd->selected_sim_limits->warning = MAX_LIMIT_IN_BYTES;
-       } else if (RESTRICTIONS_VALUE_HIGHER_THAN_LIMIT == res) {
-               create_toast_popup(popup_info.popup,
-                               "Value must be lower than limit value");
-       } else {
-               smd->selected_sim_limits->warning = (int64_t)value;
-               evas_object_del(popup_info.popup);
-       }
+       handle_limit_warning_set_result(res, &smd->selected_sim_limits->warning, value);
 
        _update_genlist_warning_item(smd);
 }
@@ -659,17 +680,7 @@ static void _limit_popup_done_cb(void *data, Evas_Object *obj, void *event_info)
                                        smd->selected_sim_limits->warning);
        }
 
-       if (RESTRICTIONS_VALUE_HIGHTER_THAN_MAX == res) {
-               create_toast_popup(popup_info.popup,
-                               "Maximum value allowed is 100GB. Value changed to 100GB");
-               smd->selected_sim_limits->limit = MAX_LIMIT_IN_BYTES;
-       } else if (RESTRICTIONS_VALUE_HIGHER_THAN_LIMIT == res) {
-               create_toast_popup(popup_info.popup,
-                               "Value must be lower than limit value");
-       } else {
-               smd->selected_sim_limits->limit = (int64_t)value;
-               evas_object_del(popup_info.popup);
-       }
+       handle_limit_warning_set_result(res, &smd->selected_sim_limits->limit, value);
 
        _update_genlist_limit_item(smd);
 }
@@ -1151,7 +1162,7 @@ static char *_item_label_get(void *data, Evas_Object *obj, const char *part)
 
        if (!strcmp(part, "elm.text"))
                return strdup(element->value);
-       else if (!strcmp(part, "elm.text.sub"))
+       if (!strcmp(part, "elm.text.sub"))
                return strdup(element->name);
        return NULL;
 }