sort recent data with launched time 14/45414/1
authorSoohye Shin <soohye.shin@samsung.com>
Thu, 6 Aug 2015 01:36:42 +0000 (10:36 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Thu, 6 Aug 2015 01:36:42 +0000 (10:36 +0900)
Change-Id: I964caa8bd1f7f83b5f9cd8984c32a7bc48347249
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
include/datamgr.h
src/data/data_recent.c

index 8278688..b63de7e 100644 (file)
@@ -48,6 +48,7 @@ struct datamgr_item {
        bool noti;
        enum datamgr_item_select_action action;
        int type;
+       time_t time;
 };
 
 struct data_class {
index d752b85..ae0c582 100644 (file)
@@ -23,6 +23,7 @@
 #include <tv_service_proxy_channel_info.h>
 #include <media_content.h>
 #include <app_media.h>
+#include <time.h>
 
 #include "data_recent.h"
 #include "datamgr.h"
@@ -33,7 +34,7 @@
 
 static struct datamgr_item *_new_datamgr_item(char *title, char *thumb,
                char *subtitle, char *parameter, char *key, char *value,
-               char *icon, int type)
+               char *icon, int type, time_t time)
 {
        struct datamgr_item *di;
 
@@ -48,6 +49,7 @@ static struct datamgr_item *_new_datamgr_item(char *title, char *thumb,
        di->type = type;
        di->parameter = strdup(parameter);
        di->action = ITEM_SELECT_ACTION_LAUNCH;
+       di->time = time;
        if (thumb)
                di->icon = strdup(thumb);
        if (subtitle)
@@ -104,7 +106,7 @@ static void _app_list_foreach(gpointer data, gpointer user_data)
                thumb = IMAGE_RECENT_THUMB_APP;
 
        di = _new_datamgr_item(label, thumb, NULL, rdata->id, NULL, NULL,
-                       IMAGE_RECENT_ICON_APP, 0);
+                       IMAGE_RECENT_ICON_APP, 0, rdata->time);
        if (di)
                dm->list = eina_list_append(dm->list, di);
 
@@ -145,7 +147,7 @@ static void _channel_list_foreach(gpointer data, gpointer user_data)
                                                channel.program_name : "");
 
        di = _new_datamgr_item(buf, NULL, NULL, PACKAGE_LIVETV, KEY_CHANNEL,
-                       rdata->id, IMAGE_RECENT_ICON_CHANNEL, 1);
+                       rdata->id, IMAGE_RECENT_ICON_CHANNEL, 1, rdata->time);
        if (di)
                dm->list = eina_list_append(dm->list, di);
 }
@@ -191,7 +193,7 @@ static void _gallery_list_foreach(gpointer data, gpointer user_data)
 
        di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path, NULL,
                        PACKAGE_MEDIAHUB, KEY_MEDIA, rdata->id,
-                       IMAGE_RECENT_ICON_GALLERY, 1);
+                       IMAGE_RECENT_ICON_GALLERY, 1, rdata->time);
        if (di)
                dm->list = eina_list_append(dm->list, di);
 
@@ -262,7 +264,7 @@ static void _movie_list_foreach(gpointer data, gpointer user_data)
 
        di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path,
                        dur ? dur : NULL, PACKAGE_MEDIAHUB, KEY_MEDIA,
-                       rdata->id, IMAGE_RECENT_ICON_MOVIE, 1);
+                       rdata->id, IMAGE_RECENT_ICON_MOVIE, 1, rdata->time);
        if (di)
                dm->list = eina_list_append(dm->list, di);
 
@@ -311,7 +313,7 @@ static void _music_list_foreach(gpointer data, gpointer user_data)
 
        di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path,
                        aminfo->audio->artist, PACKAGE_MEDIAHUB, KEY_MEDIA,
-                       rdata->id, IMAGE_RECENT_ICON_MUSIC, 1);
+                       rdata->id, IMAGE_RECENT_ICON_MUSIC, 1, rdata->time);
        if (di)
                dm->list = eina_list_append(dm->list, di);
 
@@ -357,6 +359,22 @@ static void _unload_recent(struct datamgr *dm)
        dm->list = NULL;
 }
 
+static int _sort_list(const void *data1, const void *data2)
+{
+       struct datamgr_item *di1, *di2;
+
+       di1 = (struct datamgr_item *)data1;
+       di2 = (struct datamgr_item *)data2;
+
+       if (!di1 || !di2)
+               return -1;
+
+       if (di1->time < di2->time)
+               return 1;
+
+       return -1;
+}
+
 static Eina_List *_get_items(struct datamgr *dm)
 {
        if (!dm) {
@@ -381,7 +399,7 @@ static Eina_List *_get_items(struct datamgr *dm)
        if (!_load_recent(dm, CONTENTS_MUSIC, 1, _music_list_foreach))
                _ERR("failed to load recent music contents");
 
-       /* TODO: Sort for contents list */
+       dm->list = eina_list_sort(dm->list, 0, _sort_list);
 
        return dm->list;
 }