+void _create_header_items(void *user_data)
+{
+ 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;
+
+ Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
+ if (g_input_type_data.input_type_array_len == 2) {
+ itc1->item_style = "2button_flat";
+ itc1->func.text_get = NULL;
+ itc1->func.content_get = __ise_gl_2button_content_get;
+ itc1->func.state_get = NULL;
+ itc1->func.del = NULL;
+ } else {
+ itc1->item_style = "3button_flat";
+ itc1->func.text_get = NULL;
+ itc1->func.content_get = __ise_gl_3button_content_get;
+ itc1->func.state_get = NULL;
+ itc1->func.del = NULL;
+ }
+
+ // dummy title for empty space
+ it_empty = elm_genlist_item_append(app_data->genlist, itc0,
+ NULL, NULL,
+ ELM_GENLIST_ITEM_NONE,
+ NULL, NULL);
+
+ // 3 Buttons
+ it_title = elm_genlist_item_append(app_data->genlist, itc1,
+ NULL, NULL,
+ ELM_GENLIST_ITEM_NONE,
+ NULL, NULL);
+
+ elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
+
+ elm_genlist_item_class_free(itc0);
+ elm_genlist_item_class_free(itc1);
+}
+
+void _update_genlist_items(void *user_data)
+{
+ elm_genlist_clear(app_data->genlist);
+
+ _create_header_items(user_data);
+
+ if (input_smartreply_is_enabled())
+ g_smartreply_item_size = _update_smartreply_items(user_data);
+ else
+ g_smartreply_item_size = 0;
+
+ g_template_item_size = _update_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);
+}
+
+unsigned int _update_smartreply_items(void *user_data)
+{
+ App_Data* app_data;
+
+ Elm_Object_Item *first;
+
+ unsigned int i = 0;
+ unsigned int len = 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;
+ }
+
+ /* Move to smartreply */
+ first = elm_genlist_first_item_get(app_data->genlist);
+ elm_genlist_item_next_get(first);
+
+ if (input_smartreply_is_enabled() == false)
+ return item_size;
+
+ /* Append newly added smartreply list */
+ len = input_smartreply_get_reply_num();
+
+ if (len > 0) {
+ const std::vector<TemplateData> template_list = input_template_get_list();
+
+ Elm_Genlist_Item_Class *itc;
+
+ itc = elm_genlist_item_class_new();
+ itc->item_style = "1text";
+ itc->func.text_get = __ise_smartreply_gl_text_get;
+ itc->func.content_get = NULL;
+ itc->func.state_get = NULL;
+ itc->func.del = NULL;
+
+ for (i = 0; i < len; i++) {
+ char *reply = (char *)"hello";
+ unsigned int j;
+ bool matched;
+
+ matched = false;
+
+ int type;
+ reply = input_smartreply_get_nth_item(i, &type);
+ if (reply == NULL)
+ continue;
+ SECURE_LOGD("SmartReply = [%d]%s", i, reply);
+
+ for (j = 0; j < template_list.size(); j++) {
+ const char *template_str;
+
+ if (template_list[j].use_gettext)
+ template_str = gettext(template_list[j].text.c_str());
+ else
+ template_str = template_list[j].text.c_str();
+
+ if (!__compare_string(reply, template_str)) {
+ matched = true;
+ break;
+ }
+ }
+
+ if (matched == true)
+ continue;
+
+ elm_genlist_item_append(app_data->genlist,
+ itc,
+ (void *)(uintptr_t)i,
+ NULL,
+ ELM_GENLIST_ITEM_NONE,
+ __ise_smartreply_gl_sel,
+ app_data);
+
+ item_size++;
+ if (item_size >= 3)
+ break;
+ }
+ elm_genlist_item_class_free(itc);
+ }
+ return item_size;
+}
+
+
+unsigned int _update_template_items(void *user_data)
+{
+ App_Data* app_data;
+
+ Elm_Object_Item *first;
+ Elm_Object_Item *menu;
+ Elm_Object_Item *pos;
+
+ 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;
+ menu = elm_genlist_item_next_get(first);
+
+ pos = menu;
+ /* move to smartreply next if it need */
+ if (input_smartreply_is_enabled()) {
+ unsigned int j = 0;
+
+ for (j = 0; j < g_smartreply_item_size; j++) {
+ if (pos == NULL)
+ break;
+
+ pos = elm_genlist_item_next_get(pos);
+ }
+ }
+
+ /* Append New Template list */
+ const std::vector<TemplateData> template_list = input_template_get_list();
+
+ if (template_list.size() > 0) {
+ Elm_Genlist_Item_Class *itc;
+
+ itc = elm_genlist_item_class_new();
+
+ itc->item_style = "1text";
+ itc->func.text_get = __ise_template_gl_text_get;
+ itc->func.content_get = NULL;
+ itc->func.state_get = NULL;
+ itc->func.del = NULL;
+
+ for (i = 0; i < template_list.size(); i++) {
+ pos = elm_genlist_item_append(app_data->genlist,
+ itc,
+ (void *)(uintptr_t)i,
+ NULL,
+ ELM_GENLIST_ITEM_NONE,
+ __ise_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,
+ NULL, NULL);
+ elm_genlist_item_class_free(itc0);
+ }
+
+ return item_size;
+}
+
+bool __compare_string(const char * smart_str, const char * template_str)
+{
+ int src_len = 0;
+ int dst_len = 0;
+ bool ret = true;
+
+ if(!smart_str||!template_str)
+ return ret;
+
+ src_len = strlen(smart_str);
+ dst_len = strlen(template_str);
+
+ if(smart_str[src_len-1] == '.')
+ src_len--;
+
+ while(template_str[dst_len-1] == ' ')
+ dst_len--;
+ if(template_str[dst_len-1] == '.')
+ dst_len--;
+
+ dst_len = (dst_len > src_len)? dst_len : src_len;
+
+ if(!strncmp(smart_str, template_str, (size_t)dst_len))
+ ret = false;
+
+ return (ret);
+}
+