Support App-provided templates 35/166235/5
authorsungwook79.park <sungwook79.park@samsung.com>
Tue, 9 Jan 2018 02:29:57 +0000 (11:29 +0900)
committersungwook park <sungwook79.park@samsung.com>
Tue, 9 Jan 2018 02:43:53 +0000 (02:43 +0000)
Change-Id: I4d8889f1dff1fd91783d371bc6c47e41bdcac061
Signed-off-by: sungwook79.park <sungwook79.park@samsung.com>
inc/w-input-selector.h
src/w-input-selector.cpp

index cedcf17..7d730a7 100755 (executable)
@@ -132,6 +132,13 @@ struct _InputTypeData
 };
 typedef struct _InputTypeData InputTypeData;
 
+struct _InputTemplateData
+{
+       char **input_template_array;
+       int input_template_array_len;
+};
+typedef struct _InputTemplateData InputTemplateData;
+
 void _app_terminate(void* user_data);
 void reply_to_sender_by_callback_for_back();
 void reply_to_sender_by_callback(const char *value, const char *type, const char *path[], const char *cursor_pos);
index f23a596..077136f 100755 (executable)
@@ -41,6 +41,8 @@ App_Data* app_data = NULL;
 
 InputKeyboardData g_input_keyboard_data;
 InputTypeData g_input_type_data;
+InputTemplateData g_input_template_data;
+
 
 static Elm_Object_Item *it_empty;
 static Elm_Object_Item *it_title;
@@ -93,6 +95,7 @@ void _create_header_items(void *user_data);
 void _update_genlist_items(void *user_data);
 unsigned int _update_smartreply_items(void *user_data);
 unsigned int _update_template_items(void *user_data);
+unsigned int _update_user_template_items(void *user_data);
 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info);
 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info);
 static void input_type_deinit(void);
@@ -246,6 +249,23 @@ static void __ise_template_gl_sel(void *data, Evas_Object *obj, void *event_info
        }
 }
 
+static void __ise_user_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
+{
+       Elm_Object_Item *item = (Elm_Object_Item *) event_info;
+       int index = 0;
+
+       if (item) {
+               elm_genlist_item_selected_set(item, EINA_FALSE);
+
+               index = (uintptr_t) elm_object_item_data_get(item);
+
+               if (index < (int)g_input_template_data.input_template_array_len) {
+                       reply_to_sender_by_callback(g_input_template_data.input_template_array[index], "user_template", NULL, NULL);
+                       ui_app_exit();
+               }
+       }
+}
+
 static char * __ise_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
 {
        if (!strcmp(part, "elm.text")) {
@@ -280,6 +300,19 @@ static char * __ise_template_gl_text_get(void *data, Evas_Object *obj, const cha
        return NULL;
 }
 
+static char * __ise_user_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
+{
+       if (!strcmp(part, "elm.text")) {
+               unsigned int index = (uintptr_t)data;
+               if (index < (unsigned int)g_input_template_data.input_template_array_len) {
+                       if (g_input_template_data.input_template_array[index] != NULL) {
+                               return strdup(g_input_template_data.input_template_array[index]);
+                       }
+               }
+       }
+       return NULL;
+}
+
 static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj, const char *part)
 {
        char *first_input_type = *(g_input_type_data.input_type_array + 0);
@@ -835,6 +868,7 @@ void _create_genlist_items(void* user_data)
                                ELM_GENLIST_ITEM_NONE,
                                NULL, NULL);
        }
+
        elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
 
        g_template_item_size = _update_template_items(app_data);
@@ -903,6 +937,10 @@ void _update_genlist_items(void *user_data)
 
        g_template_item_size = _update_template_items(user_data);
 
+       if (g_input_template_data.input_template_array_len > 0) {
+               _update_user_template_items(user_data);
+       }
+
        /* Update genlist item position */
        Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
        elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
@@ -1108,6 +1146,75 @@ unsigned int _update_template_items(void *user_data)
                itc0->func.state_get = NULL;
                itc0->func.del = NULL;
 
+               if (g_input_template_data.input_template_array_len < 1) {
+                       it_empty = elm_genlist_item_append(app_data->genlist, itc0,
+                               NULL, NULL,
+                               ELM_GENLIST_ITEM_NONE,
+                               NULL, NULL);
+               }
+               elm_genlist_item_class_free(itc0);
+       }
+
+       return item_size;
+}
+
+unsigned int _update_user_template_items(void *user_data)
+{
+       App_Data* app_data;
+
+       Elm_Object_Item *first;
+
+       unsigned int i = 0;
+       unsigned int item_size = 0;
+
+       app_data = (App_Data *)user_data;
+
+       if (app_data == NULL) {
+               PRINTFUNC(DLOG_ERROR, "Can not get app_data");
+               return item_size;
+       }
+
+       if (app_data->genlist == NULL) {
+               /* smartreply will update when genlist is exist only */
+               PRINTFUNC(DLOG_ERROR, "Can not get getlist");
+               return item_size;
+       }
+
+       first = elm_genlist_first_item_get(app_data->genlist);
+       if (first == NULL)
+               return 0;
+
+       if (g_input_template_data.input_template_array_len > 0) {
+               Elm_Genlist_Item_Class *itc;
+
+               itc = elm_genlist_item_class_new();
+
+               itc->item_style = "1text";
+               itc->func.text_get = __ise_user_template_gl_text_get;
+               itc->func.content_get = NULL;
+               itc->func.state_get = NULL;
+               itc->func.del = NULL;
+
+               for (i = 0; i < (unsigned int)g_input_template_data.input_template_array_len; i++) {
+                       elm_genlist_item_append(app_data->genlist,
+                                       itc,
+                                       (void *)(uintptr_t)i,
+                                       NULL,
+                                       ELM_GENLIST_ITEM_NONE,
+                                       __ise_user_template_gl_sel,
+                                       app_data);
+                       item_size++;
+               }
+               elm_genlist_item_class_free(itc);
+
+               // dummy item for empty space
+               Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
+               itc0->item_style = "title";
+               itc0->func.text_get = NULL;
+               itc0->func.content_get = NULL;
+               itc0->func.state_get = NULL;
+               itc0->func.del = NULL;
+
                it_empty = elm_genlist_item_append(app_data->genlist, itc0,
                                NULL, NULL,
                                ELM_GENLIST_ITEM_NONE,
@@ -1226,11 +1333,17 @@ void _app_service(app_control_h service, void* user_data)
        int input_type_array_len = -1;
        bool is_extra_data_array = false;
        char *mime_type = NULL;
+       char **user_template_array = NULL;
+       int user_template_array_len = -1;
 
        app_control_clone(&(app_data->source_app_control), service);
        app_data->reply_type = REPLY_APP_NORMAL;
        app_data->mime_type = MIME_TYPE_ALL;
 
+       ret = app_control_get_extra_data_array(service, "user_template", &user_template_array, &user_template_array_len);
+       g_input_template_data.input_template_array = user_template_array;
+       g_input_template_data.input_template_array_len = user_template_array_len;
+
        ret = app_control_get_mime(service, &mime_type);
        if (ret != APP_CONTROL_ERROR_NONE) {
                LOGD("Fail to get mime type : %d", ret);