Add new key for the bundle of playlist 63/257063/2
authorjiyong.min <jiyong.min@samsung.com>
Mon, 19 Apr 2021 06:13:33 +0000 (15:13 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 19 Apr 2021 08:03:03 +0000 (17:03 +0900)
[Problem]
 Playlist is sorted by item index. Playlist should not be sorted.
[Cause]
 The bundle is parcelable data, the data is sorted by a key.
 And playlist use the item index as the key of bundle.
 Therefore playlist is sorted by the item index.
[Solution]
 Add new dummy key. So it is no longer sorted by item index.

Change-Id: I0cce605dcecdfff9f76a5a51b04e2fff8386ca22

src/media_controller_playlist.c
svc/media_controller_db_util.c

index 7a7c129..c3fd4a6 100644 (file)
@@ -44,10 +44,12 @@ static int __get_bundle_data(GList *playlist, bundle_raw **bundle_data, int *bun
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
        bundle *bundle = NULL;
        mc_playlist_item_s *item = NULL;
-       char *meta = NULL;
        GList *iter = NULL;
        bundle_raw *raw_data = NULL;
        int size_r = 0;
+       unsigned int index = 0;
+       char *bundle_key = NULL;
+       char *bundle_meta = NULL;
 
        mc_retvm_if(!playlist, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
        mc_retvm_if(!bundle_data, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid bundle_data");
@@ -64,7 +66,10 @@ static int __get_bundle_data(GList *playlist, bundle_raw **bundle_data, int *bun
                        continue;
                }
 
-               meta = g_strdup_printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+               bundle_key = g_strdup_printf("%d", ++index);
+
+               bundle_meta = g_strdup_printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+                               item->index, MC_STRING_DELIMITER,
                                item->metadata->title, MC_STRING_DELIMITER,
                                item->metadata->artist, MC_STRING_DELIMITER,
                                item->metadata->album, MC_STRING_DELIMITER,
@@ -80,12 +85,13 @@ static int __get_bundle_data(GList *playlist, bundle_raw **bundle_data, int *bun
                                item->metadata->episode, MC_STRING_DELIMITER,
                                item->metadata->resolution);
 
-               if (meta) {
-                       ret = bundle_add_str(bundle, item->index, meta);
-                       g_free(meta);
+               if (bundle_key && bundle_meta) {
+                       ret = bundle_add_str(bundle, bundle_key, bundle_meta);
                        if (ret != BUNDLE_ERROR_NONE)
                                mc_error("fail to bundle_add_str[%p]", iter->data);
                }
+               g_free(bundle_key);
+               g_free(bundle_meta);
        }
 
        ret = bundle_encode(bundle, &raw_data, &size_r);
index ea9b956..25cd2ec 100644 (file)
@@ -618,10 +618,10 @@ static void  __make_playlist_query_cb(const char *key, const int type, const bun
        mc_retm_if_failed(params);
 
        sql_str = sqlite3_mprintf("INSERT INTO %q(server_name, playlist_name, item_index, %s) VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);",
-                               MC_DB_TABLE_PLAYLIST, META_LIST, query->server_name, query->playlist_name, key,
-                               __replace_null(params[0]), __replace_null(params[1]), __replace_null(params[2]), __replace_null(params[3]), __replace_null(params[4]),
-                               __replace_null(params[5]), __replace_null(params[6]), __replace_null(params[7]), __replace_null(params[8]), __replace_null(params[9]),
-                               __replace_null(params[10]), __replace_null(params[11]), __replace_null(params[12]), __replace_null(params[13]));
+                               MC_DB_TABLE_PLAYLIST, META_LIST, query->server_name, query->playlist_name, __replace_null(params[0]),
+                               __replace_null(params[1]), __replace_null(params[2]), __replace_null(params[3]), __replace_null(params[4]), __replace_null(params[5]),
+                               __replace_null(params[6]), __replace_null(params[7]), __replace_null(params[8]), __replace_null(params[9]), __replace_null(params[10]),
+                               __replace_null(params[11]), __replace_null(params[12]), __replace_null(params[13]), __replace_null(params[14]));
 
        g_strfreev(params);