-#include <Elementary.h>\r
-#include "main.h"\r
-#include "log.h"\r
-#include "scroller"\r
-\r
-const char *const MAIN_VIEW_EDJE = "main_view.edj";\r
-\r
-static void _change_entry_cb(void *data, Evas_Object *obj, void *event_info)\r
-{\r
- moment_info_s *moment_info = data;\r
-\r
- ret_if(!moment_info);\r
-}\r
-\r
-static Evas_Object *_create_search_entry(Evas_Object *parent, moment_info_s *moment_info)\r
-{\r
- Evas_Object *entry = NULL;\r
-\r
- retv_if(!parent, NULL);\r
-\r
- entry = elm_entry_add(parent);\r
- retv_if(!entry, NULL);\r
-\r
- elm_entry_single_line_set(entry, EINA_TRUE);\r
- elm_entry_scrollable_set(entry, EINA_TRUE);\r
- elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);\r
- elm_object_part_text_set(entry, "elm.guide", "City");\r
-\r
- evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
- evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
-\r
- evas_object_smart_callback_add(entry, "changed", _change_entry_cb, moment_info);\r
- evas_object_smart_callback_add(entry, "focused", _focus_entry_cb, moment_info);\r
- evas_object_smart_callback_add(entry, "unfocused", _focus_entry_cb, moment_info);\r
-\r
- evas_object_show(entry);\r
-\r
- return entry;\r
-}\r
-\r
-void _destroy_search_entry(Evas_Object *entry)\r
-{\r
- ret_if(!entry);\r
- evas_object_del(entry);\r
-}\r
-\r
-static _clicked_cb(void *data, Evas_Object *obj, void *event_info)\r
-{\r
- moment_info_s *moment_info = data;\r
-\r
- _D("Add button is clicked");\r
-\r
- ret_if(!moment_info);\r
-\r
- elm_object_signal_emit(moment_info->main_view\r
-\r
- moment_info->scroller = scroller_create(moment_info->ui_manager);\r
- ret_if(!moment_info->scroller);\r
-}\r
-\r
-Evas_Object *main_view_create(Evas_Object *parent, moment_info_s *moment_info)\r
-{\r
- Evas_Object *main_view = NULL;\r
- Evas_Object *button = NULL;\r
- char *path = NULL;\r
- char full_path[] = {0, };\r
-\r
- retv_if(!parent, NULL);\r
-\r
- path = app_get_resource_path();\r
- retv_if(!path, NULL);\r
-\r
- snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, MAIN_VIEW_EDJE);\r
- free(path);\r
-\r
- main_view = elm_layout_add(parent);\r
- retv_if(!main_view, NULL);\r
- elm_layout_file_set(main_view, full_path, "main");\r
- evas_object_size_hint_weight_set(main_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
- evas_object_size_hint_align_set(main_view, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
- evas_object_show(main_view);\r
-\r
- elm_object_part_text_set(main_view, "title", "No cities");\r
- elm_object_part_text_set(main_view, "description", "After you add cities, they will be shown here.");\r
-\r
- button = elm_button_add(parent);\r
- if (button) {\r
- elm_object_text_set(button, "+ Add");\r
- elm_object_part_content_set(main_view, "button", button);\r
- evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
- evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
- evas_object_smart_callback_add(button, "clicked", _clicked_cb, moment_info);\r
- }\r
-\r
- return main_view;\r
-}\r
-\r
-void main_view_destroy(Evas_Object *main_view)\r
-{\r
- Evas_Object *button = NULL;\r
-\r
- ret_if(!main_view);\r
-\r
- button = elm_object_part_content_unset(main_view, "button");\r
- if (button) {\r
- evas_object_del(button);\r
- }\r
-\r
- evas_object_del(main_view);\r
-}\r
+#include <Elementary.h>
+#include "main.h"
+#include "log.h"
+#include "scroller.h"
+#include "city.h"
+
+const char *const MAIN_VIEW_EDJE = "main_view.edj";
+const char *const PREDICT_ITEM_EDJE = "predict_item.edj";
+
+static void _change_entry_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ main_view_s *main_view_info = data;
+ Evas_Object *entry = obj;
+ const char *str = NULL;
+
+ ret_if(!moment_info);
+
+ str = elm_entry_entry_get(obj);
+ if (!str)
+ return;
+
+ _update_predict_scroller(main_view_info->predict_scroller, str);
+}
+
+static void _focus_entry_cb(void *data, Evas_Object *obj, void *event_info)
+{
+}
+
+static void _unfocus_entry_cb(void *data, Evas_Object *obj, void *event_info)
+{
+}
+
+static Evas_Object *_create_search_entry(Evas_Object *parent, moment_info_s *moment_info)
+{
+ Evas_Object *entry = NULL;
+
+ retv_if(!parent, NULL);
+
+ entry = elm_entry_add(parent);
+ retv_if(!entry, NULL);
+
+ elm_entry_single_line_set(entry, EINA_TRUE);
+ elm_entry_scrollable_set(entry, EINA_TRUE);
+ elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
+ elm_object_part_text_set(entry, "elm.guide", "Search");
+
+ evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ evas_object_smart_callback_add(entry, "changed", _change_entry_cb, main_view_info);
+ evas_object_smart_callback_add(entry, "focused", _focus_entry_cb, main_view_info);
+ evas_object_smart_callback_add(entry, "unfocused", _unfocus_entry_cb, main_view_info);
+
+ evas_object_show(entry);
+
+ return entry;
+}
+
+static void _destroy_search_entry(Evas_Object *entry)
+{
+ ret_if(!entry);
+ evas_object_del(entry);
+}
+
+static Evas_Object *_create_map(Evas_Object *parent)
+{
+ Evas_Object *map = NULL;
+ Evas *e = NULL;
+
+ retv_if(!parent, NULL);
+
+ e = evas_object_evas_get(parent);
+ retv_if(!e, NULL);
+
+ map = evas_object_rectangle_add(e);
+ retv_if(!map, NULL);
+
+ evas_object_color_set(map, 200, 200, 0, 255);
+ evas_object_size_hint_min_set(map, 480, 400);
+ evas_object_show(map);
+
+ return map;
+}
+
+static void _destroy_map(Evas_Object *map)
+{
+ ret_if(!map);
+
+ evas_object_del(map);
+}
+
+static _click_result_button_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ moment_info_s *moment_info = data;
+
+ _D("Add button is clicked");
+
+ ret_if(!moment_info);
+
+ moment_info->result_view = result_view_create(moment_info->ui_manager);
+ ret_if(!moment_info->result_view);
+}
+
+static Evas_Object *_create_result_button(Evas_Object *parent, main_view_s *main_view_info)
+{
+ Evas_Object *result_button = NULL;
+
+ result_button = elm_button_add(parent);
+ retv_if(!result_button, NULL);
+
+ elm_object_part_text_set(result_button, "Result");
+ evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_smart_callback_add(button, "clicked", _click_result_button_cb, moment_info);
+
+ return result_button;
+}
+
+static void _destroy_result_button(Evas_Object *result_button)
+{
+ ret_if(!result_button);
+ evas_object_del(result_button);
+}
+
+static Evas_Object *_create_selected_scroller(Evas_Object *parent)
+{
+ Evas_Object *selected_scroller = NULL;
+
+ retv_if(!parent, NULL);
+
+ selected_scroller = scroller_create(parent);
+ retv_if(!selected_scroller, NULL);
+
+ return selected_scroller;
+}
+
+static void _destroy_selected_scroller(Evas_Object *selected_scroller)
+{
+ ret_if(!selected_scroller);
+
+ evas_object_del(selected_scroller);
+}
+
+static _click_plus_button_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ moment_info_s *moment_info = data;
+
+ _D("Add button is clicked");
+
+ ret_if(!moment_info);
+
+ /* Show the entry */
+}
+
+static Evas_Object *_create_plus_button(Evas_Object *parent, main_view_s *main_view_info)
+{
+ Evas_Object *plus_button = NULL;
+
+ retv_if(!parent, NULL);
+
+ plus_button = elm_button_add(parent);
+ retv_if(!plus_button, NULL);
+
+ elm_object_part_text_set(plus_button, "+Add");
+ evas_object_size_hint_weight_set(plus_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(plus_button, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_smart_callback_add(plus_button, "clicked", _click_plus_button_cb, main_view_info);
+
+ return plus_button;
+}
+
+static void _destroy_plus_button(Evas_Object *plus_button)
+{
+ ret_if(!plus_button);
+ evas_object_del(plus_button);
+}
+
+static Evas_Object *_create_predict_item(Evas_Object *parent, const char *city, const char *nation)
+{
+ Evas_Object *predict_item = NULL;
+
+ char *path = NULL;
+ char full_path[PATH_LEN] = {0, };
+ char city_name[PATH_LEN] = {0, };
+
+ retv_if(!parent, NULL);
+
+ path = app_get_resource_path();
+ retv_if(!path, NULL);
+
+ snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, PREDICT_ITEM_EDJE);
+ free(path);
+
+ predict_item = elm_layout_add(parent);
+ retv_if(!predict_item, NULL);
+
+ elm_layout_file_set(predict_item, full_path, "main");
+ evas_object_size_hint_weight_set(predict_item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(predict_item, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(predict_item);
+
+ snprintf(city_name, sizeof(city_name), "%s, %s", city, nation);
+ elm_object_part_text_set(predict_item, "city", city_name);
+
+ return predict_item;
+}
+
+static void _destroy_predict_item(Evas_Object *predict_item)
+{
+ ret_if(!predict_item);
+ evas_object_del(predict_item);
+}
+
+static Evas_Object *_create_predict_scroller(Evas_Object *parent)
+{
+ Evas_Object *predict_scroller = NULL;
+
+ retv_if(!parent, NULL);
+
+ predict_scroller = scroller_create(parent);
+ retv_if(!predict_scroller, NULL);
+
+ return predict_scroller;
+}
+
+static void _destroy_predict_scroller(Evas_Object *predict_scroller)
+{
+ ret_if(!predict_scroller);
+
+ evas_object_del(predict_scroller);
+}
+
+static void _clean_predict_scroller(Evas_Object *predict_scroller)
+{
+ Evas_Object *box = NULL;
+ Evas_Object *predict_item = NULL;
+ Eina_List *list = NULL;
+
+ ret_if(!predict_scroller);
+
+ box = elm_object_content_get(predict_scroller);
+ ret_if(!box);
+
+ list = elm_box_children_get(box);
+ ret_if(!list);
+
+ EINA_LIST_FREE(list, predict_item) {
+ _destroy_predict_item(predict_item);
+ }
+}
+
+static void _append_item_to_predict_scroller(Evas_Object *predict_scroller, Evas_Object *item)
+{
+ Evas_Object *box = NULL;
+
+ ret_if(!predict_scroller);
+ ret_if(!item);
+
+ box = elm_object_content_get(predict_scroller);
+ ret_if(!box);
+
+ elm_box_pack_end(box, item);
+}
+
+static void _remove_item_in_predict_scroller(Evas_Object *predict_scroller, Evas_Object *item)
+{
+ Evas_Object *box = NULL;
+ Evas_Object *item = NULL;
+
+ ret_if(!predict_scroller);
+ ret_if(!item);
+
+ box = elm_object_content_get(predict_scroller);
+ ret_if(!box);
+
+ elm_box_unpack(box, item);
+}
+
+static void _update_predict_scroller(Evas_Object *predict_scroller, const char *str)
+{
+ city_s *city_info = NULL;
+ register int i = 0;
+
+ ret_if(!predict_scroller);
+
+ if (!str)
+ _clean_predict_scroller(predict_scroller);
+
+ city_info = city_get();
+ ret_if(!city_info);
+
+ for (; i < CITY_MAX; i++) {
+ int matched = 0;
+ if (city_info[i]->name && strstr(city_info[i]->name, str))
+ matched = 1;
+ else if (city_info[i]->nation && strstr(city_info[i]->nation, str))
+ matched = 1;
+
+ if (matched) {
+ Evas_Object *predict_item = NULL;
+ predict_item = _create_predict_item(predict_scroller, city_info[i]->name, city_info[i]->nation);
+ if (predict_item)
+ _append_item_to_predict_scroller(predict_scroller);
+ }
+ }
+}
+
+Evas_Object *main_view_create(Evas_Object *parent, moment_info_s *moment_info)
+{
+ Evas_Object *button = NULL;
+ main_view_s *main_view_info = NULL;
+ char *path = NULL;
+ char full_path[] = {0, };
+
+ retv_if(!parent, NULL);
+
+ path = app_get_resource_path();
+ retv_if(!path, NULL);
+
+ snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, MAIN_VIEW_EDJE);
+ free(path);
+
+ main_view_info = calloc(1, sizeof(main_view_s));
+ retv_if(!main_view_info, NULL);
+
+ main_view_info->main_view = elm_layout_add(parent);
+ if (!main_view_info->main_view) {
+ free(main_view_info);
+ return NULL;
+ }
+
+ elm_layout_file_set(main_view_info->main_view, full_path, "main");
+ evas_object_size_hint_weight_set(main_view_info->main_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(main_view_info->main_view, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(main_view);
+ evas_object_data_set(main_view_info->main_view, DATA_KEY_INFO, main_view_info);
+
+ elm_object_part_text_set(main_view_info->main_view, "title", "No cities");
+ elm_object_part_text_set(main_view_info->main_view, "description", "After you add cities, they will be shown here.");
+
+ main_view_info->entry = _create_search_entry(main_view_info->main_view, moment_info);
+ if (main_view_info->entry)
+ elm_object_part_content_set(main_view_info->main_view, "entry", main_view_info->entry);
+
+ main_view_info->map = _create_map(main_view_info->main_view);
+ if (main_view_info->map)
+ elm_object_part_content_set(main_view_info->main_view, "map", main_view_info->map);
+
+ main_view_info->result_button = _create_result_button(main_view_info->main_view, main_view_info);
+ if (main_view_info->result_button)
+ elm_object_part_content_set(main_view_info->main_view, "result_button", main_view_info->result_button);
+
+ main_view_info->selected_scroller = _create_selected_scroller(main_view_info->main_view);
+ if (main_view_info->selected_scroller)
+ elm_object_part_content_set(main_view_info->main_view, "selected_scroller", main_view_info->selected_scroller);
+
+ main_view_info->plus_button = _create_plus_button(main_view_info->main_view, main_view_info);
+ if (main_view_info->plus_button)
+ elm_object_part_content_set(main_view_info->main_view, "plus_button", main_view_info->plus_button);
+
+ main_view_info->predict_scroller = _create_predict_scroller(main_view_info->main_view);
+ if (main_view_info->predict_scroller)
+ elm_object_part_content_set(main_view_info->main_view, "predict_scroller", main_view_info->predict_scroller);
+
+ return main_view;
+}
+
+void main_view_destroy(Evas_Object *main_view)
+{
+ Evas_Object *button = NULL;
+ main_view_s *main_view_info = NULL;
+
+ ret_if(!main_view);
+
+ main_view_info = evas_object_data_del(main_view_info->main_view, DATA_KEY_INFO);
+ ret_if(!main_view_info);
+
+ if (main_view_info->predict_scroller)
+ _destroy_predict_scroller(main_view_info->predict_scroller);
+
+ if (main_view_info->plus_button)
+ _destroy_plus_button(main_view_info->plus_button);
+
+ if (main_view_info->selected_scroller)
+ _destroy_selected_scroller(main_view_info->selected_scroller);
+
+ if (main_view_info->result_button)
+ _destroy_result_button(button);
+
+ if (main_view_info->map)
+ _destroy_map(main_view_info->map);
+
+ if (main_view_info->entry)
+ _destroy_search_entry(main_view_info->entry);
+
+ free(main_view_info);
+
+ evas_object_del(main_view);
+}
-#include <Elementary.h>\r
-#include "main.h"\r
-#include "log.h"\r
-#include "scroller"\r
-\r
-const char *const MAIN_VIEW_EDJE = "result_view.edj";\r
-\r
-static _clicked_cb(void *data, Evas_Object *obj, void *event_info)\r
-{\r
- moment_info_s *moment_info = data;\r
-\r
- _D("Add button is clicked");\r
-\r
- ret_if(!moment_info);\r
-\r
- elm_object_signal_emit(moment_info->result_view\r
-\r
- moment_info->scroller = scroller_create(moment_info->ui_manager);\r
- ret_if(!moment_info->scroller);\r
-}\r
-\r
-Evas_Object *result_view_create(Evas_Object *parent, moment_info_s *moment_info)\r
-{\r
- Evas_Object *result_view = NULL;\r
- Evas_Object *button = NULL;\r
- char *path = NULL;\r
- char full_path[] = {0, };\r
-\r
- retv_if(!parent, NULL);\r
-\r
- path = app_get_resource_path();\r
- retv_if(!path, NULL);\r
-\r
- snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, MAIN_VIEW_EDJE);\r
- free(path);\r
-\r
- result_view = elm_layout_add(parent);\r
- retv_if(!result_view, NULL);\r
- elm_layout_file_set(result_view, full_path, "main");\r
- evas_object_size_hint_weight_set(result_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
- evas_object_size_hint_align_set(result_view, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
- evas_object_show(result_view);\r
-\r
- elm_object_part_text_set(result_view, "title", "No cities");\r
- elm_object_part_text_set(result_view, "description", "After you add cities, they will be shown here.");\r
-\r
- button = elm_button_add(parent);\r
- if (button) {\r
- elm_object_text_set(button, "+ Add");\r
- elm_object_part_content_set(result_view, "button", button);\r
- evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
- evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
- evas_object_smart_callback_add(button, "clicked", _clicked_cb, moment_info);\r
- }\r
-\r
- return result_view;\r
-}\r
-\r
-void result_view_destroy(Evas_Object *result_view)\r
-{\r
- Evas_Object *button = NULL;\r
-\r
- ret_if(!result_view);\r
-\r
- button = elm_object_part_content_unset(result_view, "button");\r
- if (button) {\r
- evas_object_del(button);\r
- }\r
-\r
- evas_object_del(result_view);\r
-}\r
+#include <Elementary.h>
+#include "main.h"
+#include "log.h"
+#include "scroller.h"
+
+const char *const MAIN_VIEW_EDJE = "result_view.edj";
+
+static _clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ moment_info_s *moment_info = data;
+
+ _D("Add button is clicked");
+
+ ret_if(!moment_info);
+
+ moment_info->scroller = scroller_create(moment_info->ui_manager);
+ ret_if(!moment_info->scroller);
+}
+
+Evas_Object *result_view_create(Evas_Object *parent, moment_info_s *moment_info)
+{
+ Evas_Object *result_view = NULL;
+ Evas_Object *button = NULL;
+ char *path = NULL;
+ char full_path[] = {0, };
+
+ retv_if(!parent, NULL);
+
+ path = app_get_resource_path();
+ retv_if(!path, NULL);
+
+ snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, MAIN_VIEW_EDJE);
+ free(path);
+
+ result_view = elm_layout_add(parent);
+ retv_if(!result_view, NULL);
+ elm_layout_file_set(result_view, full_path, "main");
+ evas_object_size_hint_weight_set(result_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(result_view, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(result_view);
+
+ elm_object_part_text_set(result_view, "title", "No cities");
+ elm_object_part_text_set(result_view, "description", "After you add cities, they will be shown here.");
+
+ button = elm_button_add(parent);
+ if (button) {
+ elm_object_part_text_set(button, "+ Add");
+ elm_object_part_content_set(result_view, "button", button);
+ evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_smart_callback_add(button, "clicked", _clicked_cb, moment_info);
+ }
+
+ return result_view;
+}
+
+void result_view_destroy(Evas_Object *result_view)
+{
+ Evas_Object *button = NULL;
+
+ ret_if(!result_view);
+
+ button = elm_object_part_content_unset(result_view, "button");
+ if (button) {
+ evas_object_del(button);
+ }
+
+ evas_object_del(result_view);
+}