draw user list 30/42130/2
authorSoohye Shin <soohye.shin@samsung.com>
Tue, 23 Jun 2015 13:29:44 +0000 (22:29 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Wed, 24 Jun 2015 04:23:16 +0000 (13:23 +0900)
Change-Id: Ibf8112d5565c6bcfffd30dbe75af7f8d9e721396
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
src/view/view_user.c

index b37a454..abf5d98 100644 (file)
 struct _priv {
        Evas_Object *win;
        Evas_Object *base;
+       Evas_Object *scr;
+       Evas_Object *box;
+       Eina_List *list;
 
        struct datamgr *dm;
+       struct _bar_item *foc;
+};
+
+struct _bar_item {
+       Evas_Object *eo;
+
+       struct datamgr_item *di;
+       struct _priv *priv;
+};
+
+static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       struct _priv *priv;
+
+       if (!data) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       priv = data;
+
+       if (!strcmp(ev->keyname, KEY_ENTER) ||
+                       !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
+               datamgr_select_item(priv->dm, priv->foc->di);
+       } else if (!strcmp(ev->keyname, KEY_BACK) ||
+                       !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
+               viewmgr_pop_view();
+       }
+}
+
+static input_handler base_handler = {
+       .key_down = _key_down
 };
 
 static Evas_Object *_create(Evas_Object *win, void *data)
@@ -65,7 +101,8 @@ static Evas_Object *_create(Evas_Object *win, void *data)
                free(priv);
                return NULL;
        }
-       evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
+                       EVAS_HINT_EXPAND);
        elm_win_resize_object_add(win, base);
 
        priv->win = win;
@@ -74,10 +111,151 @@ static Evas_Object *_create(Evas_Object *win, void *data)
 
        viewmgr_set_view_data(VIEW_USER, priv);
        viewmgr_add_view(view_user_edit_get_vclass(), dm);
+       inputmgr_add_callback(base, 0, &base_handler, priv);
 
        return base;
 }
 
+static void _focused(int id, void *data, Evas_Object *obj,
+               Elm_Object_Item *item)
+{
+       struct _priv *priv;
+       struct _bar_item *bi;
+
+       if (!data) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       bi = data;
+       priv = bi->priv;
+       priv->foc = bi;
+
+       elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
+}
+
+static void _unfocused(int id, void *data, Evas_Object *obj,
+               Elm_Object_Item *item)
+{
+       elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
+}
+
+static input_handler eo_handler = {
+       .focused = _focused,
+       .unfocused = _unfocused
+};
+
+static struct _bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
+               struct datamgr_item *di)
+{
+       struct _bar_item *bi;
+       Evas_Object *eo, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
+
+       bi = calloc(1, sizeof(*bi));
+       if (!bi) {
+               _ERR("failed to calloc bar item");
+               return NULL;
+       }
+
+       if (di->title) {
+               eo = utils_add_layout(box, GRP_USER_ITEM, true, NULL);
+               if (!eo) {
+                       _ERR("failed to add layout");
+                       free(bi);
+                       return NULL;
+               }
+               lbl = utils_add_label(eo, di->title, STYLE_LABEL_TITLE,
+                               PART_BAR_ITEM_TITLE);
+               if (!lbl)
+                       goto err;
+
+               focus_lbl = utils_add_label(eo, di->title,
+                               STYLE_LABEL_TITLE_FOCUS,
+                               PART_BAR_ITEM_TITLE_FOCUS);
+               if (!focus_lbl)
+                       goto err;
+       } else {
+               eo = utils_add_layout(box, GRP_BAR_ITEM, true, NULL);
+               if (!eo) {
+                       _ERR("failed to add layout");
+                       free(bi);
+                       return NULL;
+               }
+       }
+
+       ic = utils_add_icon(eo, di->icon, PART_BAR_ITEM_ICON);
+       if (!ic)
+               goto err;
+
+       focus_ic = utils_add_icon(eo, di->focus_icon, PART_BAR_ITEM_ICON_FOCUS);
+       if (!focus_ic)
+               goto err;
+
+       bg = utils_add_bg(eo, COLOR_DEFAULT_R, COLOR_DEFAULT_G, COLOR_DEFAULT_B,
+                       COLOR_DEFAULT_A, PART_BAR_ITEM_BG);
+       if (!bg)
+               goto err;
+
+       inputmgr_add_callback(eo, 0, &eo_handler, bi);
+       elm_box_pack_end(box, eo);
+       evas_object_show(eo);
+
+       bi->priv = priv;
+       bi->eo = eo;
+       bi->di = di;
+
+       return bi;
+err:
+       _ERR("failed to add home item");
+       evas_object_del(eo);
+       free(bi);
+
+       return NULL;
+}
+
+static void _add_user(struct _priv *priv)
+{
+       Eina_List *list, *l;
+       Evas_Object *scr, *box;
+       struct _bar_item *bi;
+       struct datamgr_item *di;
+
+       scr = utils_add_scroller(priv->base);
+       if (!scr) {
+               _ERR("failed to add scroller");
+               return;
+       }
+
+       box = utils_add_box(scr, true);
+       if (!box) {
+               _ERR("failed to add box");
+               evas_object_del(scr);
+               return;
+       }
+       elm_object_content_set(scr, box);
+       elm_object_part_content_set(priv->base, PART_USER_BAR, scr);
+       evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
+                       EVAS_HINT_EXPAND);
+
+       list = datamgr_get_items(priv->dm);
+       if (!list) {
+               _ERR("failed to load list");
+               evas_object_del(scr);
+               return;
+       }
+
+       EINA_LIST_FOREACH(list, l, di) {
+               bi = _pack_bar_item(priv, box, di);
+               if (!bi)
+                       continue;
+
+               priv->list = eina_list_append(priv->list, bi);
+       }
+
+       priv->scr = scr;
+       priv->box = box;
+}
+
 static void _show(void *data)
 {
        struct _priv *priv;
@@ -90,6 +268,31 @@ static void _show(void *data)
        priv = data;
 
        evas_object_show(priv->base);
+
+       _add_user(priv);
+
+       if (!priv->foc)
+               priv->foc = eina_list_data_get(priv->list);
+
+       elm_object_focus_set(priv->foc->eo, EINA_TRUE);
+}
+
+static void _unload_user(struct _priv *priv)
+{
+       struct _bar_item *bi;
+
+       EINA_LIST_FREE(priv->list, bi) {
+               inputmgr_remove_callback(bi->eo, &eo_handler);
+               evas_object_del(bi->eo);
+               free(bi);
+       }
+
+       elm_box_clear(priv->box);
+       evas_object_del(priv->scr);
+       priv->box = NULL;
+       priv->scr = NULL;
+       priv->list = NULL;
+       priv->foc = NULL;
 }
 
 static void _hide(void *data)
@@ -103,6 +306,8 @@ static void _hide(void *data)
 
        priv = data;
 
+       _unload_user(priv);
+
        evas_object_hide(priv->base);
 }
 
@@ -117,8 +322,11 @@ static void _destroy(void *data)
 
        priv = data;
 
+       _unload_user(priv);
+
        viewmgr_remove_view(VIEW_USER_EDIT);
        datamgr_fini(priv->dm);
+       inputmgr_remove_callback(priv->base, &base_handler);
        evas_object_del(priv->base);
        free(priv);
 }