[TNEXT-822] Corrected Reorder logic to save the order 25/133125/2
authorRahul Dadhich <r.dadhich@samsung.com>
Fri, 9 Jun 2017 04:47:40 +0000 (10:17 +0530)
committerRahul Dadhich <r.dadhich@samsung.com>
Fri, 9 Jun 2017 07:31:46 +0000 (13:01 +0530)
Change-Id: If34b1a26b491578c9d8200d2205e81d77a0f6c6e
Signed-off-by: Rahul Dadhich <r.dadhich@samsung.com>
inc/gallery.h
inc/util/gl-util.h
src/2dview/gl-albums.c
src/data/gl-data.c
src/gallery.c
src/util/gl-util.c

index 2a35325233bd72b1d72fb5826a4f9bc217b86958..d697c25a3c4aef60464ff818a3fc3831ef298d04 100644 (file)
@@ -214,6 +214,7 @@ extern "C" {
 #define GL_NAVIFRAME_POP_CB_KEY "gl_naviframe_pop_cb_key"
 
 #define GL_LAUNCH_STATE "gallery_launch_state"
+#define GL_REORDER_STATE "gallery_reorder_state"
 
 /******** Enumeration ********/
        typedef enum _gl_view_mode {
@@ -464,6 +465,7 @@ extern "C" {
                int externalStorageId;
                bool lang_changed;
                bool hide_noti;
+               bool reorder;
        } gl_main_info;
 
 
index 2756d756b310e0aad1adbf33d0e062b7def7a19d..bb60c1f1911c5dc27dfb2e3e0561f1cfd039ad66 100644 (file)
@@ -227,6 +227,8 @@ extern "C" {
        void *_gl_get_app_data();
        int _gl_albums_set_current(void *data, gl_cluster * current);
        gl_cluster *_gl_albums_get_current(void *data);
+       void _gl_set_reorder_value(void *data);
+       void _gl_set_reorder_state_preference();
 
 #ifdef __cplusplus
 }
index ce8567d38cfb878d38176aa413b18f2e054b0c43..c71e78f8b6e8a475a8d657f33ba47db3c0361275 100644 (file)
@@ -759,10 +759,14 @@ void _gl_update_list_data(void *data)
        Elm_Object_Item *f_it = elm_gengrid_first_item_get(ad->albuminfo.view);
        gl_cluster *album_item = NULL;
        Eina_List *list = NULL;
+       int i = 1, ret;
        if (f_it) {
                album_item = elm_object_item_data_get(f_it);
-               if (album_item) {
+               if (album_item && album_item->cluster) {
                        list = eina_list_append(list, album_item);
+                       media_folder_set_order(album_item->cluster->folder_h, i);
+                       media_folder_update_to_db(album_item->cluster->folder_h);
+                       i++;
                        album_item = NULL;
                }
        }
@@ -771,8 +775,11 @@ void _gl_update_list_data(void *data)
                        f_it = elm_gengrid_item_next_get(f_it);
                        if (f_it) {
                                album_item = elm_object_item_data_get(f_it);
-                               if (album_item) {
+                               if (album_item && album_item->cluster) {
                                        list = eina_list_append(list, album_item);
+                                       ret = media_folder_set_order(album_item->cluster->folder_h, i);
+                                       ret = media_folder_update_to_db(album_item->cluster->folder_h);
+                                       i++;
                                        album_item = NULL;
                                }
                        }
@@ -783,6 +790,8 @@ void _gl_update_list_data(void *data)
        } else if (list == NULL) {
                gl_dbg("new list is null");
        }
+       ad->maininfo.reorder = true;
+       _gl_set_reorder_state_preference();
 }
 
 static Eina_Bool __gl_albums_pop_op(void *data)
index 89ad258ae710412e9094d094ac61c37ebd4c00a3..8d7ddb856ccac834ab35a6e3851b22d06cf83a2d 100644 (file)
@@ -139,7 +139,11 @@ static int __gl_data_get_cluster_list(void *data, bool b_update)
        /* Get all contents(including local and cloud) for albums list */
        g_strlcpy(filter.cond, GL_CONDITION_IMAGE_VIDEO, CONDITION_LENGTH);
        filter.sort_type = MEDIA_CONTENT_ORDER_ASC;
-       g_strlcpy(filter.sort_keyword, FOLDER_NAME, KEYWORD_LENGTH);
+       if (ad->maininfo.reorder) {
+               g_strlcpy(filter.sort_keyword, FOLDER_ORDER, KEYWORD_LENGTH);
+       } else {
+               g_strlcpy(filter.sort_keyword, FOLDER_NAME, KEYWORD_LENGTH);
+       }
        filter.collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
        filter.offset = GL_GET_ALL_RECORDS;
        filter.count = GL_GET_ALL_RECORDS;
@@ -166,24 +170,24 @@ static int __gl_data_get_cluster_list(void *data, bool b_update)
                gl_sdbg("folder id: %s.", f_data->uuid);
 
                /**
-               * There are Phone and web filters in libmedia-info,
-               * but the are seperated, if we want to get  phone and web photos
-               * only we can use is WMINFO_CLUSTER_TYPE_ALL,
-               * and add condition checking to skip MMC albums.
-               *
-               * To skip MMC albums if MMC already unmounted,
-               * in case of delay updating in DB.
-               */
+                * There are Phone and web filters in libmedia-info,
+                * but the are seperated, if we want to get  phone and web photos
+                * only we can use is WMINFO_CLUSTER_TYPE_ALL,
+                * and add condition checking to skip MMC albums.
+                *
+                * To skip MMC albums if MMC already unmounted,
+                * in case of delay updating in DB.
+                */
                if ((ad->maininfo.mmc_state == GL_MMC_STATE_REMOVED_MOVING ||
-                        ad->maininfo.mmc_state == GL_MMC_STATE_REMOVED) &&
-                       f_data->type == GL_STORE_T_MMC) {
+                               ad->maininfo.mmc_state == GL_MMC_STATE_REMOVED) &&
+                               f_data->type == GL_STORE_T_MMC) {
                        gl_dbgW("MMC was unmounted, skip MMC album!");
                        _gl_data_type_free_glitem((void **) &f_data);
                        continue;
                }
 
                if (f_data->type == GL_STORE_T_PHONE ||
-                       f_data->type == GL_STORE_T_MMC) {
+                               f_data->type == GL_STORE_T_MMC) {
                        if (f_data->count == 0) {
                                if (!g_strcmp0(f_data->uuid, new_mc_id)) {
                                        /* append the newly created cluster to list */
@@ -197,7 +201,7 @@ static int __gl_data_get_cluster_list(void *data, bool b_update)
                        }
                        all_item_cnt += f_data->count;
                        if (f_data->type == GL_STORE_T_PHONE ||
-                               f_data->type == GL_STORE_T_MMC) {
+                                       f_data->type == GL_STORE_T_MMC) {
                                phone_cnt++;
                        }
                }
@@ -213,60 +217,63 @@ static int __gl_data_get_cluster_list(void *data, bool b_update)
                gcluster->cluster = f_data;
 
                length += f_data->count;
-
-               if (_gl_data_is_camera_album(f_data)) {
-                       /**
-                       * Default album: Camera
-                       * Now Camera Shot is located in Phone/MMC.
-                       * If user can determine the location of default album,
-                       * here we should get the path and check it's in Phone or MMC.
-                       */
-                       if (default_album) {
-                               /* album 'Camera' is in phone, set it before MMC album 'Camera' */
-                               char *phone_root_path =
-                                       _gl_get_root_directory_path(STORAGE_TYPE_INTERNAL);
-                               if (phone_root_path
-                                       && _gl_data_check_root_type(f_data->path,
-                                                                                               phone_root_path)) {
+               if (ad->maininfo.reorder) {
+                       ad->albuminfo.elist->clist =
+                                       eina_list_append(ad->albuminfo.elist->clist, gcluster);
+               } else {
+                       if (_gl_data_is_camera_album(f_data)) {
+                               /**
+                                * Default album: Camera
+                                * Now Camera Shot is located in Phone/MMC.
+                                * If user can determine the location of default album,
+                                * here we should get the path and check it's in Phone or MMC.
+                                */
+                               if (default_album) {
+                                       /* album 'Camera' is in phone, set it before MMC album 'Camera' */
+                                       char *phone_root_path =
+                                                       _gl_get_root_directory_path(STORAGE_TYPE_INTERNAL);
+                                       if (phone_root_path
+                                                       && _gl_data_check_root_type(f_data->path,
+                                                                       phone_root_path)) {
+                                               ad->albuminfo.elist->clist =
+                                                               eina_list_prepend(ad->albuminfo.elist->clist,
+                                                                               gcluster);
+                                       } else {
+                                               ad->albuminfo.elist->clist =
+                                                               eina_list_append_relative(ad->albuminfo.elist->
+                                                                               clist, gcluster,
+                                                                               default_album);
+                                               default_album = gcluster;
+                                       }
+                                       GL_FREEIF(phone_root_path);
+                               } else {
                                        ad->albuminfo.elist->clist =
-                                               eina_list_prepend(ad->albuminfo.elist->clist,
-                                                                                 gcluster);
+                                                       eina_list_prepend(ad->albuminfo.elist->clist,
+                                                                       gcluster);
+                               }
+                       } else
+                               if (_gl_data_is_default_album(GL_STR_ALBUM_DOWNLOADS, f_data)
+                                               || _gl_data_is_screenshot_album(GL_STR_ALBUM_SCREENSHOTS,
+                                                               f_data)) {
+                                       if (default_album)
+                                               ad->albuminfo.elist->clist =
+                                                               eina_list_append_relative(ad->albuminfo.elist->clist,
+                                                                               gcluster, default_album);
+                                       else
+                                               ad->albuminfo.elist->clist =
+                                                               eina_list_prepend(ad->albuminfo.elist->clist,
+                                                                               gcluster);
                                } else {
                                        ad->albuminfo.elist->clist =
-                                               eina_list_append_relative(ad->albuminfo.elist->
-                                                                                                 clist, gcluster,
-                                                                                                 default_album);
-                                       default_album = gcluster;
+                                                       eina_list_append(ad->albuminfo.elist->clist, gcluster);
                                }
-                               GL_FREEIF(phone_root_path);
-                       } else {
-                               default_album = gcluster;
-                               ad->albuminfo.elist->clist =
-                                       eina_list_prepend(ad->albuminfo.elist->clist,
-                                                                         gcluster);
-                       }
-               } else
-                       if (_gl_data_is_default_album(GL_STR_ALBUM_DOWNLOADS, f_data)
-                               || _gl_data_is_screenshot_album(GL_STR_ALBUM_SCREENSHOTS,
-                                                                                               f_data)) {
-                       if (default_album)
-                               ad->albuminfo.elist->clist =
-                                       eina_list_append_relative(ad->albuminfo.elist->clist,
-                                                                                         gcluster, default_album);
-                       else
-                               ad->albuminfo.elist->clist =
-                                       eina_list_prepend(ad->albuminfo.elist->clist,
-                                                                         gcluster);
-               } else {
-                       ad->albuminfo.elist->clist =
-                               eina_list_append(ad->albuminfo.elist->clist, gcluster);
                }
                /* Default album 'Camera shots' showed in edit view */
                edit_album_cnt++;
 
                if (sel_id_list) {
                        b_selected = _gl_data_util_check_selected_str_id(&sel_id_list,
-                                                                                                                        f_data->uuid);
+                                       f_data->uuid);
                        if (b_selected) {
                                b_selected = false;
                                /* Set checkbox state */
@@ -310,16 +317,20 @@ static int __gl_data_get_cluster_list(void *data, bool b_update)
                        /* Append gcluster to selected list */
                        _gl_data_albums_selected_list_append(ad, gcluster);
                }
-
-               if (default_album) {
+               if (ad->maininfo.reorder) {
                        ad->albuminfo.elist->clist =
-                               eina_list_append_relative(ad->albuminfo.elist->clist,
-                                                                                 gcluster, default_album);
+                                       eina_list_prepend(ad->albuminfo.elist->clist, gcluster);
                } else {
-                       ad->albuminfo.elist->clist =
-                               eina_list_prepend(ad->albuminfo.elist->clist, gcluster);
+                       if (default_album) {
+                               ad->albuminfo.elist->clist =
+                                               eina_list_append_relative(ad->albuminfo.elist->clist,
+                                                               gcluster, default_album);
+                       } else {
+                               ad->albuminfo.elist->clist =
+                                               eina_list_prepend(ad->albuminfo.elist->clist, gcluster);
+                       }
+                       default_album = gcluster;
                }
-               default_album = gcluster;
        }
 
        if (all_item_cnt) {
index df8bf17554fb7d85ed86fe13c3db3b352dd9efdd..2efe71a1bf512962392d56fbbedc9f499603862e 100644 (file)
@@ -157,12 +157,6 @@ static void _gallery_low_battery_cb(app_event_info_h event_info,
        /* 0 : default handler, 1:user handler */
 }
 
-Eina_Bool test_timer(void *data)
-{
-       gl_dbg("timer called");
-       return 1;
-}
-
 static bool _gallery_create(void *data)
 {
        GL_PROFILE_IN;
@@ -202,9 +196,11 @@ static bool _gallery_create(void *data)
                ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
                                                                __gallery_key_down_cb, data);
 
+       /* Update reorder value*/
+       _gl_set_reorder_value(data);
+
        GL_PROFILE_F_OUT("register noti callback");
        GL_PROFILE_OUT;
-       ecore_timer_add(3.0, test_timer, NULL);
        return true;
 }
 
index b59109f40bb4d1e3eb202b51aafff2403373f591..63d7ccb62f6d39d85f667b6c9814f53c9a11d125 100644 (file)
@@ -2082,3 +2082,38 @@ gl_cluster *_gl_albums_get_current(void *data)
        gl_appdata *ad = (gl_appdata *) data;
        return ad->albuminfo.current;
 }
+
+void _gl_set_reorder_value(void *data)
+{
+       GL_CHECK(data);
+       gl_appdata *ad = (gl_appdata *) data;
+       int ret;
+       bool preference_exists = false;
+       bool reorder_state = false;
+       ad->maininfo.reorder = false;
+       ret = preference_is_existing(GL_REORDER_STATE, &preference_exists);
+       if (ret != PREFERENCE_ERROR_NONE) {
+               gl_dbgE("Unable to get preference_exists for reorder State ERROR(%d)", ret);
+               return;
+       }
+       if (preference_exists) {
+               ret = preference_get_boolean(GL_REORDER_STATE, &reorder_state);
+               if (ret != PREFERENCE_ERROR_NONE) {
+                       gl_dbgE("Unable to get preference for reorder State ERROR(%d)",
+                                       ret);
+                       return;
+               } else {
+                       ad->maininfo.reorder = reorder_state;
+               }
+       }
+}
+
+void _gl_set_reorder_state_preference()
+{
+       int ret;
+               ret = preference_set_boolean(GL_REORDER_STATE, true);
+       if (ret != PREFERENCE_ERROR_NONE) {
+               gl_dbgE(" Unable to set preference for reorder State ERROR(%d)",
+                               ret);
+       }
+}