rlottie/example: sort the resource list before displaying. 61/201461/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Wed, 13 Mar 2019 10:13:15 +0000 (19:13 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Thu, 14 Mar 2019 09:51:16 +0000 (18:51 +0900)
Change-Id: Ida87b1a7f4f353b236b0009f8538a436cfee5014

example/evasapp.cpp
example/lottieviewer.cpp

index c9170b8..943fbba 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "evasapp.h"
 #include <dirent.h>
+#include <algorithm>
 
 static void
 _on_resize(Ecore_Evas *ee)
@@ -132,6 +133,9 @@ EvasApp::jsonFiles(const std::string &dirName, bool recurse)
       }
       closedir(d);
     }
+
+    std::sort(result.begin(), result.end(), [](auto & a, auto &b){return a < b;});
+
     return result;
 }
 
index 92f90bb..2d6bd40 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <Elementary.h>
 #include "lottieview.h"
+#include "evasapp.h"
 #include<iostream>
 #include <stdio.h>
 #include <stdlib.h>
@@ -147,10 +148,7 @@ create_layout(Evas_Object *parent, const char *file)
 
    //LOTTIEVIEW
    LottieView *view = new LottieView(evas_object_evas_get(layout), renderMode);
-   std::string filePath = DEMO_DIR;
-   filePath +=file;
-
-   view->setFilePath(filePath.c_str());
+   view->setFilePath(file);
    view->setSize(500, 500);
 
    //IMAGE from LOTTIEVIEW
@@ -205,7 +203,9 @@ static char *
 _gl_text_get(void *data, Evas_Object *obj, const char *part)
 {
    ItemData *id = (ItemData *) data;
-   return strdup(jsonFiles[id->index].c_str());
+   const char *ptr = strrchr(jsonFiles[id->index].c_str(), '/');
+   int len = int(ptr + 1 - jsonFiles[id->index].c_str()); // +1 to include '/'
+   return strdup(jsonFiles[id->index].substr(len).c_str());
 }
 
 static void
@@ -219,8 +219,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
    Evas_Object *win, *nf, *genlist;
    Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
    ItemData *itemData;
-   DIR *dir;
-   struct dirent *ent;
+
 
    if (argc > 1) {
       if (!strcmp(argv[1], "--disable-render"))
@@ -249,17 +248,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
    itc->func.text_get = _gl_text_get;
    itc->func.del = _gl_del;
 
-   std::string rscPath = DEMO_DIR;
-
-   dir = opendir(rscPath.c_str());
-   while ((ent = readdir(dir)) != NULL) {
-      if (!strncmp(ent->d_name + (strlen(ent->d_name) - 4), "json", 4)) {
-         jsonFiles.push_back(ent->d_name);
-      }
-   }
-   closedir(dir);
-
-   std::sort(jsonFiles.begin(), jsonFiles.end(), [](auto & a, auto &b){return a < b;});
+   jsonFiles = EvasApp::jsonFiles(DEMO_DIR);
 
    for (uint i = 0; i < jsonFiles.size(); i++) {
       itemData = (ItemData *)calloc(sizeof(ItemData), 1);