detail: add movie genre detail view 82/48582/2
authorJehun Lim <jehun.lim@samsung.com>
Wed, 23 Sep 2015 08:23:46 +0000 (17:23 +0900)
committerJehun Lim <jehun.lim@samsung.com>
Wed, 23 Sep 2015 08:26:59 +0000 (17:26 +0900)
Change-Id: Ie062309df4f13503543a536df60955e0e494f085
Signed-off-by: Jehun Lim <jehun.lim@samsung.com>
include/view.h
src/grid/grid_movie.c
src/view/detail.c

index d7dc582..c7e4d9f 100644 (file)
@@ -57,4 +57,9 @@ enum update_type {
        UPDATE_TOAST_HIDE,
 };
 
+enum detail_view_type {
+       E_DETAIL_MOVIE_GENRE = 0,
+       E_DETAIL_MAX
+};
+
 #endif /* __AIR_MEDIAHUB_VIEW_H__ */
index c420c81..6fb7708 100644 (file)
@@ -253,7 +253,7 @@ static void _key_down_cb(void *data, Elm_Object_Item *it,
        }
 }
 
-static void _selected_cb(void *data, Elm_Object_Item *it)
+static void _media_selected_cb(void *data, Elm_Object_Item *it)
 {
        Eina_List *list;
        struct view_update_data vdata;
@@ -279,6 +279,30 @@ static void _selected_cb(void *data, Elm_Object_Item *it)
        viewmgr_push_view(VIEW_VIEWER);
 }
 
+static void _genre_selected_cb(void *data, Elm_Object_Item *it)
+{
+       struct view_update_data vdata;
+       struct group_info *gi;
+
+       if (!it) {
+               _ERR("invalid argument");
+               return;
+       }
+
+       gi = elm_object_item_data_get(it);
+       if (!gi) {
+               _ERR("failed to get group info");
+               return;
+       }
+
+       vdata.list = gi->list;
+       vdata.index = E_DETAIL_MOVIE_GENRE;
+       vdata.id = gi->name;
+
+       viewmgr_update_view(VIEW_DETAIL, UPDATE_CONTENT, &vdata);
+       viewmgr_push_view(VIEW_DETAIL);
+}
+
 static struct grid_class _gclass[] = {
        [E_MOVIE_NAME] = {
                .item_style = STYLE_MOVIE_NAME,
@@ -308,7 +332,7 @@ static struct grid_data _gdata[] = {
                .get_item_list = _get_name_list,
                .free_item_list = _free_media_list,
                .key_down_cb = _key_down_cb,
-               .selected_cb = _selected_cb
+               .selected_cb = _media_selected_cb
        },
        [E_MOVIE_GENRE] = {
                .item_x = MOVIE_GENRE_ITEM_X,
@@ -317,7 +341,8 @@ static struct grid_data _gdata[] = {
                .grid_padding = MOVIE_GENRE_GRID_PADDING,
                .gclass = &_gclass[E_MOVIE_GENRE],
                .get_item_list = _get_genre_list,
-               .free_item_list = _free_group_list
+               .free_item_list = _free_group_list,
+               .selected_cb = _genre_selected_cb
        },
        [E_MOVIE_DATE] = {
                .item_x = MOVIE_NAME_ITEM_X,
index 543a9b0..1df4251 100644 (file)
  */
 
 #include <Elementary.h>
+#include <media_content.h>
 #include <app_debug.h>
+#include <app_contents.h>
+#include <app_media.h>
+#include <inputmgr.h>
 #include <viewmgr.h>
 
 #include "define.h"
+#include "view.h"
+#include "data/datamgr.h"
+#include "grid/grid.h"
+#include "util/util.h"
+
+static char *_grid_text_get(void *data, Evas_Object *obj, const char *part);
+static Evas_Object *_grid_content_get(void *data, Evas_Object *obj,
+                       const char *part);
+
+static void _get_movie_count(char *str, int size, Eina_List *list);
+
+struct _view_info {
+       const char *grid_style;
+       int grid_item_x;
+       int grid_item_y;
+       char *(*get_grid_text)(void *data, Evas_Object *obj, const char *part);
+       Evas_Object *(*get_grid_content)(void *data, Evas_Object *obj,
+                               const char *part);
+
+       void (*get_content_info)(char *str, int size, Eina_List *list);
+};
+
+static struct _view_info view_info[E_DETAIL_MAX] = {
+       [E_DETAIL_MOVIE_GENRE] = {
+               .grid_style = STYLE_MOVIE_NAME,
+               .grid_item_x = MOVIE_NAME_ITEM_X,
+               .grid_item_y = MOVIE_NAME_ITEM_Y,
+               .get_grid_text = _grid_text_get,
+               .get_grid_content = _grid_content_get,
+               .get_content_info = _get_movie_count,
+       },
+};
 
 struct _priv {
        Evas_Object *win;
        Evas_Object *base;
+       Evas_Object *grid;
+
+       Elm_Object_Item *focused_it;
+
+       Eina_List *media_list;
+
+       int view_type;
+
+       struct _view_info *vinfo;
 };
 
+static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
+                       Evas_Event_Key_Down *ev)
+{
+       if (!ev) {
+               _ERR("invalid argument");
+               return;
+       }
+
+       if (!strcmp(ev->keyname, KEY_BACK) ||
+               !strcmp(ev->keyname, KEY_ESC)) {
+               viewmgr_pop_view();
+       }
+}
+
+static void _focused_cb(int id, void *data, Evas_Object *obj,
+                       Elm_Object_Item *it)
+{
+       struct _priv *priv;
+
+       if (!data)
+               return;
+
+       priv = data;
+
+       if (it)
+               priv->focused_it = it;
+}
+
+static void _selected(void *data)
+{
+       struct _priv *priv;
+       struct view_update_data vdata;
+       app_media *am;
+
+       if (!data) {
+               _ERR("invalid argument");
+               return;
+       }
+
+       priv = data;
+
+       am = elm_object_item_data_get(priv->focused_it);
+       if (!am) {
+               _ERR("failed to get app media");
+               return;
+       }
+
+       vdata.list = priv->media_list;
+       vdata.index = util_get_media_index(vdata.list, am);
+
+       viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
+       viewmgr_push_view(VIEW_VIEWER);
+}
+
+static void _selected_cb(int id, void *data, Evas_Object *obj,
+                       Elm_Object_Item *it)
+{
+       struct _priv *priv;
+
+       if (!data || !it)
+               return;
+
+       priv = data;
+
+       ecore_job_add(_selected, priv);
+}
+
+static input_handler _handler = {
+       .key_down = _key_down_cb,
+       .focused = _focused_cb,
+       .selected = _selected_cb
+};
+
+static char *_grid_text_get(void *data, Evas_Object *obj, const char *part)
+{
+       app_media *am;
+       app_media_info *mi;
+       int duration;
+       char buf[32];
+
+       if (!data)
+               return NULL;
+
+       am = data;
+
+       mi = app_media_get_info(am);
+       if (!mi) {
+               _ERR("failed to get media info");
+               return NULL;
+       }
+
+       if (!strcmp(part, PART_ELM_TEXT_TITLE))
+               return strdup(mi->title);
+       else if (!strcmp(part, PART_ELM_TEXT_ALBUM))
+               return strdup(mi->audio->album);
+       else if (!strcmp(part, PART_ELM_TEXT_ARTIST))
+               return strdup(mi->audio->artist);
+       else if (!strcmp(part, PART_ELM_TEXT_PLAYTIME)) {
+               if (mi->media_type == MEDIA_CONTENT_TYPE_VIDEO)
+                       duration = mi->video->duration;
+               else if (mi->media_type == MEDIA_CONTENT_TYPE_MUSIC)
+                       duration = mi->audio->duration;
+               else
+                       return NULL;
+
+               util_time_string(buf, sizeof(buf), duration, false);
+
+               return strdup(buf);
+       }
+
+       return NULL;
+}
+
+static Evas_Object *_grid_content_get(void *data, Evas_Object *obj,
+                       const char *part)
+{
+       Evas_Object *eo;
+       app_media *am;
+       app_media_info *mi;
+       struct color_data bg;
+
+       if (!data)
+               return NULL;
+
+       am = data;
+
+       mi = app_media_get_info(am);
+       if (!mi) {
+               _ERR("failed to get media info");
+               return NULL;
+       }
+
+       eo = NULL;
+       if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
+               eo = util_add_image(obj, mi->thumbnail_path);
+               if (!eo) {
+                       _ERR("failed to create image object");
+                       return NULL;
+               }
+       } else if (!strcmp(part, PART_ELM_SWALLOW_FAVORITE)) {
+               if (!mi->favorite)
+                       return NULL;
+
+               eo = util_add_image(obj, IMAGE_THUMBNAIL_FAVORITE);
+               if (!eo) {
+                       _ERR("failed to create image object");
+                       return NULL;
+               }
+       } else if (!strcmp(part, PART_ELM_SWALLOW_TEXTBG)) {
+               eo = evas_object_rectangle_add(obj);
+               if (!eo) {
+                       _ERR("failed to create rectangle object");
+                       return NULL;
+               }
+
+               app_contents_get_color(mi->title, NULL, &bg);
+               evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
+       } else if (!strcmp(part, PART_ELM_SWALLOW_VIDEO)) {
+               if (mi->media_type != MEDIA_CONTENT_TYPE_VIDEO)
+                       return NULL;
+
+               eo = util_add_image(obj, IMAGE_THUMBNAIL_PLAY);
+               if (!eo) {
+                       _ERR("failed to create image object");
+                       return NULL;
+               }
+       }
+
+       if (eo)
+               evas_object_show(eo);
+
+       return eo;
+}
+
+static Elm_Gengrid_Item_Class *_get_grid_item_class(struct _view_info *vinfo)
+{
+       Elm_Gengrid_Item_Class *ic;
+
+       ic = elm_gengrid_item_class_new();
+       if (!ic) {
+               _ERR("failed to create gengrid item calss");
+               return NULL;
+       }
+
+       ic->item_style = vinfo->grid_style;
+       ic->func.text_get = vinfo->get_grid_text;
+       ic->func.content_get = vinfo->get_grid_content;
+
+       return ic;
+}
+
+static void _get_movie_count(char *str, int size, Eina_List *list)
+{
+       snprintf(str, size, "%d movies", eina_list_count(list));
+}
+
+static void _update_title_area(struct _priv *priv, const char *title)
+{
+       char buf[64];
+
+       elm_object_part_text_set(priv->base, PART_DETAIL_TITLE, title);
+
+       priv->vinfo->get_content_info(buf, sizeof(buf), priv->media_list);
+       elm_object_part_text_set(priv->base, PART_DETAIL_CONTENT_INFO, buf);
+}
+
+static bool _update_thumbnail_area(struct _priv *priv)
+{
+       Eina_List *l;
+       Elm_Gengrid_Item_Class *ic;
+       Elm_Object_Item *it;
+       void *data;
+
+       elm_gengrid_clear(priv->grid);
+
+       elm_gengrid_item_size_set(priv->grid,
+                       elm_config_scale_get() * priv->vinfo->grid_item_x,
+                       elm_config_scale_get() * priv->vinfo->grid_item_y);
+
+       ic = _get_grid_item_class(priv->vinfo);
+       if (!ic) {
+               _ERR("failed to get grid item class");
+               return false;
+       }
+
+       EINA_LIST_FOREACH(priv->media_list, l, data) {
+               it = elm_gengrid_item_append(priv->grid, ic, data, NULL, NULL);
+               elm_object_item_data_set(it, data);
+       }
+
+       elm_gengrid_item_class_free(ic);
+
+       evas_object_show(priv->grid);
+
+       return true;
+}
+
+static bool _draw_thumbnail_area(struct _priv *priv)
+{
+       Evas_Object *grid;
+
+       grid = util_add_gengrid(priv->base, 0, 0, EINA_TRUE);
+       if (!grid) {
+               _ERR("failed to add gengrid");
+               return false;
+       }
+
+       elm_object_part_content_set(priv->base,
+                               PART_DETAIL_THUMBNAIL_AREA, grid);
+
+       inputmgr_add_callback(grid, 0, &_handler, priv);
+
+       priv->grid = grid;
+
+       return true;
+}
+
 static Evas_Object *_create(Evas_Object *win, void *data)
 {
        struct _priv *priv;
@@ -57,6 +359,12 @@ static Evas_Object *_create(Evas_Object *win, void *data)
        priv->win = win;
        priv->base = base;
 
+       if (!_draw_thumbnail_area(priv)) {
+               _ERR("failed to draw items");
+               free(priv);
+               return NULL;
+       }
+
        viewmgr_set_view_data(VIEW_DETAIL, priv);
 
        return base;
@@ -89,6 +397,8 @@ static void _show(void *view_data)
 
        evas_object_show(priv->base);
 
+       elm_object_focus_set(priv->grid, EINA_TRUE);
+
        ecore_timer_add(SHOW_VIEW_INTERVAL, _show_view, priv);
 }
 
@@ -107,6 +417,40 @@ static void _hide(void *view_data)
        elm_object_signal_emit(priv->base, SIG_HIDE_VIEW, "");
 }
 
+static void _update(void *view_data, int update_type, void *data)
+{
+       struct _priv *priv;
+       struct view_update_data *vdata;
+
+       if (!view_data) {
+               _ERR("failed to get view data");
+               return;
+       }
+
+       if (!data) {
+               _ERR("invalid argument");
+               return;
+       }
+
+       priv = view_data;
+       vdata = data;
+
+       switch (update_type) {
+       case UPDATE_CONTENT:
+               priv->media_list = vdata->list;
+               priv->view_type = vdata->index;
+
+               priv->vinfo = &view_info[priv->view_type];
+
+               _update_title_area(priv, vdata->id);
+               _update_thumbnail_area(priv);
+
+               break;
+       default:
+               break;
+       }
+}
+
 static void _destroy(void *view_data)
 {
        struct _priv *priv;
@@ -128,6 +472,7 @@ static view_class _vclass = {
        .create = _create,
        .show = _show,
        .hide = _hide,
+       .update = _update,
        .destroy = _destroy,
 };