[SM][Wifi] Added custom cycle interval popup 00/155000/3
authorRadek Kintop <r.kintop@samsung.com>
Wed, 11 Oct 2017 15:25:30 +0000 (17:25 +0200)
committerRadek Kintop <r.kintop@samsung.com>
Wed, 11 Oct 2017 15:48:16 +0000 (15:48 +0000)
Change-Id: I62818803d5e8177c3956e50af6c1ea4b40f102a2
Signed-off-by: Radek Kintop <r.kintop@samsung.com>
setting-smartmanager/smartmanager-data/src/smartmanager-data-usage-wifi-settings.c

index 06cd147bf459f18ba04c6a204ee4c9ba67829847..ee04e4a96f671f4c305a1319a331c119c78821e2 100755 (executable)
@@ -11,6 +11,10 @@ static int _update(void *data);
 static int _cleanup(void *data);
 
 /* Widget interaction callbacks: */
+static void _custom_cycle_dayes_popup_cancel_click_cb(void *data,
+                                                                       Evas_Object *button, void *event_info);
+static void _custom_cycle_dayes_popup_done_click_cb(void *data,
+                                                                       Evas_Object *button, void *event_info);
 static void _cycle_item_click_cb(void *data, Evas_Object *obj,
                                                                void *event_info);
 static void _cycle_popup_radio_changed_cb(void *data, Evas_Object *radio,
@@ -42,6 +46,8 @@ static Evas_Object *_start_day_popup_radio_item_content_get(void *ix,
                                                                                Evas_Object *genlist, const char *part);
 
 static void _generate_list(SmartMgrData *ad, Evas_Object *genlist);
+static Evas_Object *_create_popup(SmartMgrData *smd, char *title);
+static Evas_Object *_create_custom_cycle_days_popup(SmartMgrData *smd);
 
 static Elm_Genlist_Item_Class cycle_itc = {
        .item_style = "type2",
@@ -171,6 +177,99 @@ static Eina_Bool _pop_view_cb(void *data, Elm_Object_Item *it)
        return EINA_TRUE;
 }
 
+static void _custom_cycle_dayes_popup_cancel_click_cb(void *data,
+                                                                       Evas_Object *button, void *event_info)
+{
+       Evas_Object *popup = evas_object_data_get(button, "popup");
+       evas_object_del(popup);
+}
+
+static void _custom_cycle_dayes_popup_done_click_cb(void *data,
+                                                                       Evas_Object *button, void *event_info)
+{
+       SmartMgrData *smd = data;
+       Evas_Object *entry = evas_object_data_get(button, "entry");
+       Evas_Object *popup = evas_object_data_get(button, "popup");
+
+       if (!data)
+               return;
+
+       /* Validate: */
+       smd->wifi_limits.custom_mode_interval = atoi(elm_entry_entry_get(entry));
+       if (smd->wifi_limits.custom_mode_interval <= 0) {
+               smd->wifi_limits.custom_mode_interval = 1;
+               setting_create_toast_popup(
+                                                               _("Minimum value allowed is 1. Value set to 1"),
+                                                               smd->md.window);
+       }
+
+       if (smd->wifi_limits.custom_mode_interval > 90) {
+               smd->wifi_limits.custom_mode_interval = 90;
+               setting_create_toast_popup(
+                                                       _("Maximum value allowed is 90. Value set to 90"),
+                                                       smd->md.window);
+
+       }
+
+       smd->wifi_limits.cycle_mode = CYCLE_MODE_CUSTOM;
+       elm_radio_value_set(cycle_popup_radio_group, smd->wifi_limits.cycle_mode);
+       if (!write_wifi_cycle_mode(smd->wifi_limits.cycle_mode)) {
+               SETTING_TRACE_ERROR("Failed to write wifi cycle mode");
+       } else {
+               /* It is necessary to reset start cycle values: */
+               smd->wifi_limits.cycle_start = time(NULL);
+               if (!write_wifi_cycle_start(smd->wifi_limits.cycle_start))
+                       SETTING_TRACE_ERROR("Failed to write wifi cycle start");
+               if (!write_wifi_cycle_interval(smd->wifi_limits.custom_mode_interval))
+                       SETTING_TRACE_ERROR("Failed to write wifi cycle interval");
+       }
+
+       evas_object_del(popup);
+       evas_object_del(cycle_popup);
+       cycle_popup = NULL;
+       cycle_popup_radio_group = NULL;
+       elm_genlist_realized_items_update(smd->wifi_data_setting_genlist);
+}
+
+static Evas_Object *_create_custom_cycle_days_popup(SmartMgrData *smd)
+{
+       char buff[64] = {'\0'};
+       Evas_Object *entry = NULL;
+       Evas_Object *button = NULL;
+       Evas_Object *popup = NULL;
+
+       if (!smd)
+               return NULL;
+
+       popup = _create_popup(smd, _("Set data usage cycle"));
+       elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
+
+       snprintf(buff, sizeof(buff), "%d", smd->wifi_limits.custom_mode_interval);
+       entry = elm_entry_add(popup);
+       elm_entry_single_line_set(entry, EINA_TRUE);
+       elm_entry_entry_set(entry, buff);
+       elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
+       elm_entry_input_panel_show(entry);
+       elm_object_content_set(popup, entry);
+
+       button = elm_button_add(popup);
+       elm_object_text_set(button, _("Cancel"));
+       elm_object_part_content_set(popup, "button1", button);
+       evas_object_data_set(button, "popup", popup);
+       evas_object_smart_callback_add(button, "clicked",
+                                                               _custom_cycle_dayes_popup_cancel_click_cb, smd);
+
+       button = elm_button_add(popup);
+       evas_object_data_set(button, "entry", entry);
+       evas_object_data_set(button, "popup", popup);
+       elm_object_text_set(button, _("Done"));
+       elm_object_part_content_set(popup, "button2", button);
+       evas_object_smart_callback_add(button, "clicked",
+                                                               _custom_cycle_dayes_popup_done_click_cb, smd);
+
+       return popup;
+}
+
 static void _cycle_popup_item_selected_cb(void *ix, Evas_Object *genlist,
                                                                                        void *event_info)
 {
@@ -180,6 +279,12 @@ static void _cycle_popup_item_selected_cb(void *ix, Evas_Object *genlist,
                return;
 
        elm_genlist_item_selected_set(event_info, EINA_FALSE);
+
+       if (CYCLE_MODE_CUSTOM == (int)ix) {
+               _create_custom_cycle_days_popup(smd);
+               return;
+       }
+
        smd->wifi_limits.cycle_mode = (int)ix;
        elm_radio_value_set(cycle_popup_radio_group, smd->wifi_limits.cycle_mode);
        if (!write_wifi_cycle_mode(smd->wifi_limits.cycle_mode)) {
@@ -207,6 +312,12 @@ static void _cycle_popup_radio_changed_cb(void *data, Evas_Object *radio,
        SmartMgrData *smd = data;
 
        smd->wifi_limits.cycle_mode = elm_radio_state_value_get(radio);
+
+       if (CYCLE_MODE_CUSTOM == smd->wifi_limits.cycle_mode) {
+               _create_custom_cycle_days_popup(smd);
+               return;
+       }
+
        if (!write_wifi_cycle_mode(smd->wifi_limits.cycle_mode)) {
                SETTING_TRACE_ERROR("Failed to write wifi cycle mode");
        } else {