music: add now playing item 68/44368/2
authorJehun Lim <jehun.lim@samsung.com>
Tue, 21 Jul 2015 06:40:52 +0000 (15:40 +0900)
committerJehun Lim <jehun.lim@samsung.com>
Tue, 21 Jul 2015 07:04:49 +0000 (16:04 +0900)
Change-Id: Ibb5b45a506bd299cc4b5c12739450b662060e3e1
Signed-off-by: Jehun Lim <jehun.lim@samsung.com>
src/layout/music.c

index b5e42da..856f96b 100644 (file)
  * limitations under the License.
  */
 
+#include <glib.h>
 #include <Elementary.h>
 #include <media_content.h>
 #include <app_debug.h>
+#include <app_contents.h>
 #include <app_media.h>
 #include <gridmgr.h>
 #include <layoutmgr.h>
@@ -31,6 +33,7 @@
 #define LIST_MEDIA_COND "media_type=3"
 
 #define TEXT_NOCONTENT "No Music"
+#define TEXT_NOW_PLAYING "Now Playing"
 
 #define GRID_PADDING 26
 #define GRID_ITEM_X (488 + GRID_PADDING)
@@ -50,9 +53,11 @@ struct _priv {
        struct listmgr_data *ldata;
 
        struct mediadata *md;
-       int cur_index;
 
        Eina_List *media_list;
+       int cur_index;
+
+       app_media *playing_info;
 };
 
 static char *_grid_text_get(void *data, Evas_Object *obj, const char *part)
@@ -117,10 +122,142 @@ static struct grid_class _gclass = {
        .content_get = _grid_content_get
 };
 
+static bool _update_playing_info(void *data, Evas_Object *base)
+{
+       Evas_Object *content, *image;
+       app_media_info *info;
+       struct _priv *priv;
+
+       if (!data || !base) {
+               _ERR("invalid argument");
+               return false;
+       }
+
+       priv = data;
+
+       content = elm_object_part_content_get(base, PART_ITEM_CONTENT);
+       if (!content) {
+               _ERR("failed to get content part");
+               return false;
+       }
+
+       image = elm_object_part_content_get(content,
+                               PART_PLAYING_CONTENT_THUMBNAIL);
+       if (!image) {
+               _ERR("failed to get image object");
+               return false;
+       }
+
+       info = app_media_get_info(priv->playing_info);
+       if (!info) {
+               _ERR("failed to get app media info");
+               return false;
+       }
+
+       elm_image_file_set(image, info->thumbnail_path, NULL);
+       elm_image_aspect_fixed_set(image, EINA_FALSE);
+
+       elm_object_part_text_set(content, PART_PLAYING_CONTENT_TITLE,
+                               info->title);
+
+       elm_object_part_text_set(content, PART_PLAYING_CONTENT_ARTIST,
+                               info->audio->artist);
+       elm_object_part_text_set(content, PART_PLAYING_CONTENT_ALBUM,
+                               info->audio->album);
+
+       return true;
+}
+
+static bool _draw_playing_title(Evas_Object *base)
+{
+       Evas_Object *btn;
+
+       btn = elm_button_add(base);
+       if (!btn) {
+               _ERR("failed to create button object");
+               return false;
+       }
+
+       elm_object_style_set(btn, STYLE_BTN_INDEX);
+       elm_object_text_set(btn, TEXT_NOW_PLAYING);
+
+       elm_object_part_content_set(base, PART_ITEM_TITLE, btn);
+
+       return true;
+}
+
+static bool _draw_playing_content(Evas_Object *base)
+{
+       Evas_Object *btn, *image;
+
+       btn = elm_button_add(base);
+       if (!btn) {
+               _ERR("failed to create button object");
+               return false;
+       }
+
+       elm_object_style_set(btn, STYLE_BTN_PLAYING_CONTENT);
+
+       image = elm_image_add(btn);
+       if (!image) {
+               _ERR("failed to create image object");
+               return false;
+       }
+
+       elm_object_part_content_set(btn, PART_PLAYING_CONTENT_THUMBNAIL, image);
+
+       elm_object_part_content_set(base, PART_ITEM_CONTENT, btn);
+
+       return true;
+}
+
+static bool _draw_playing_info(void *data, Evas_Object *base)
+{
+       if (!base) {
+               _ERR("invalid argument");
+               return false;
+       }
+
+       if (!_draw_playing_title(base)) {
+               _ERR("failed to draw playing title");
+               return false;
+       }
+
+       if (!_draw_playing_content(base)) {
+               _ERR("failed to draw playing content");
+               return false;
+       }
+
+       return true;
+}
+
+static void _item_selected_cb(struct _priv *priv, app_media *am)
+{
+       struct view_update_data vdata;
+
+       vdata.list = mediadata_get_medialist(priv->md);
+       vdata.index = util_get_media_index(vdata.list, am);
+       priv->cur_index = vdata.index;
+
+       viewmgr_update_view(VIEW_MPLAYER, UPDATE_CONTENT, &vdata);
+       viewmgr_push_view(VIEW_MPLAYER);
+}
+
+static void _playing_selected_cb(void *data, Evas_Object *obj)
+{
+       struct _priv *priv;
+
+       if (!data || !obj)
+               return;
+
+       priv = data;
+
+       _item_selected_cb(priv, priv->playing_info);
+}
+
 static void _grid_selected_cb(void *data, Elm_Object_Item *it)
 {
        app_media *am;
-       struct view_update_data vdata;
        struct _priv *priv;
 
        if (!data || !it) {
@@ -136,17 +273,13 @@ static void _grid_selected_cb(void *data, Elm_Object_Item *it)
                return;
        }
 
-       vdata.list = mediadata_get_medialist(priv->md);
-       vdata.index = util_get_media_index(vdata.list, am);
-       priv->cur_index = vdata.index;
-
-       viewmgr_update_view(VIEW_MPLAYER, UPDATE_CONTENT, &vdata);
-       viewmgr_push_view(VIEW_MPLAYER);
+       _item_selected_cb(priv, am);
 }
 
 static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
 {
        struct listmgr_data *data;
+       struct play_info_ops *pops;
        struct grid_ops *gops;
 
        data = calloc(1, sizeof(*data));
@@ -160,6 +293,15 @@ static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
        data->grid_num_item = GRID_NUM_ITEM;
        data->box_padding = BOX_PADDING;
 
+       pops = calloc(1, sizeof(*pops));
+       if (!pops)
+               goto err;
+
+       pops->draw = _draw_playing_info;
+       pops->update = _update_playing_info;
+       pops->selected_cb = _playing_selected_cb;
+       pops->ops_data = priv;
+
        gops = calloc(1, sizeof(*gops));
        if (!gops)
                goto err;
@@ -168,6 +310,7 @@ static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
        gops->selected_cb = _grid_selected_cb;
        gops->ops_data = priv;
 
+       data->pops = pops;
        data->gops = gops;
 
        return data;
@@ -177,7 +320,7 @@ err:
        return NULL;
 }
 
-static void _update_list_area(struct _priv *priv)
+static void _update_content_list(struct _priv *priv)
 {
        Eina_List *list;
 
@@ -197,6 +340,51 @@ static void _update_list_area(struct _priv *priv)
        priv->media_list = list;
 }
 
+static void _update_playing_item(struct _priv *priv)
+{
+       GList *list;
+       app_media *am;
+       app_media_info *info;
+       struct recent_data *recent;
+       int r;
+
+       list = NULL;
+       info = NULL;
+
+       r = app_contents_get_recent_list(CONTENTS_MUSIC, 1, &list);
+       if (r != APP_CONTENTS_ERROR_NONE) {
+               _ERR("failed to get movie recent list");
+               return;
+       }
+
+       recent = (struct recent_data *)g_list_nth_data(list, 0);
+
+       if (recent) {
+               am = util_find_media_info(mediadata_get_medialist(priv->md),
+                                       recent->id);
+               if (!am) {
+                       _ERR("failed to get app media");
+                       g_list_free(list);
+                       return;
+               }
+
+               info = app_media_get_info(am);
+               if (!info) {
+                       _ERR("failed to get app media info");
+                       g_list_free(list);
+                       return;
+               }
+
+               priv->playing_info = am;
+       }
+
+       if (!listmgr_update_play_info(priv->listmgr, info))
+               _ERR("failed to update now playing item");
+
+
+       g_list_free(list);
+}
+
 static bool _create(layoutmgr *lmgr, void *data)
 {
        struct listmgr *listmgr;
@@ -355,7 +543,8 @@ static void _update(void *layout_data, int update_type, void *data)
 
        switch (update_type) {
        case UPDATE_CONTENT:
-               _update_list_area(priv);
+               _update_content_list(priv);
+               _update_playing_item(priv);
                break;
        case UPDATE_FOCUS:
                if (!data) {
@@ -371,7 +560,7 @@ static void _update(void *layout_data, int update_type, void *data)
                        update = false;
 
                listmgr_update_focus_item(priv->listmgr, index, update);
-
+               _update_playing_item(priv);
                break;
        default:
                break;