[Android] Let medialibrary auto set the group name upon creation with medias

Nicolas Pomepuy git at videolan.org
Fri Apr 24 14:50:03 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Apr 24 09:07:47 2020 +0200| [48f711c5579bd920e08a5e1fd8a0ca91cc325092] | committer: Geoffrey Métais

Let medialibrary auto set the group name upon creation with medias

> https://code.videolan.org/videolan/vlc-android/commit/48f711c5579bd920e08a5e1fd8a0ca91cc325092
---

 .../vlc/viewmodels/mobile/VideosViewModel.kt       |   9 +-
 buildsystem/compile-medialibrary.sh                | 116 ++++++++++-----------
 .../medialibrary/media/VideoGroupImpl.java         |   4 +-
 3 files changed, 66 insertions(+), 63 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
index 008ce0d16..10e875664 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
@@ -188,12 +188,13 @@ class VideosViewModel(context: Context, type: VideoGroupingType, val folder: Fol
 
     suspend fun createGroup(medias: List<MediaWrapper>): VideoGroup? {
         if (medias.size < 2) return null
-        val group = withContext(Dispatchers.IO) {
-            val newGroup = medialibrary.createVideoGroup(medias[0].title)
-            medias.forEach { newGroup.add(it.id) }
+        return withContext(Dispatchers.IO) {
+            val newGroup = medialibrary.createVideoGroup(medias.map { it.id }.toLongArray())
+            if (newGroup.title.isNullOrBlank()) {
+                newGroup.rename(medias[0].title)
+            }
             newGroup
         }
-        return group
     }
 
     suspend fun groupSimilar(media: MediaWrapper): Boolean {
diff --git a/buildsystem/compile-medialibrary.sh b/buildsystem/compile-medialibrary.sh
index 0c85a30b7..dfb0fcfed 100755
--- a/buildsystem/compile-medialibrary.sh
+++ b/buildsystem/compile-medialibrary.sh
@@ -4,24 +4,24 @@
 # ARGUMENTS #
 #############
 
-MEDIALIBRARY_HASH=3745bf75
+MEDIALIBRARY_HASH=65cc81e9
 
 while [ $# -gt 0 ]; do
-    case $1 in
-        help|--help)
-            echo "Use -a to set the ARCH"
-            echo "Use --release to build in release mode"
-            exit 1
-            ;;
-        a|-a)
-            ANDROID_ABI=$2
-            shift
-            ;;
-        release|--release)
-            RELEASE=1
-            ;;
-    esac
+  case $1 in
+  help | --help)
+    echo "Use -a to set the ARCH"
+    echo "Use --release to build in release mode"
+    exit 1
+    ;;
+  a | -a)
+    ANDROID_ABI=$2
     shift
+    ;;
+  release | --release)
+    RELEASE=1
+    ;;
+  esac
+  shift
 done
 
 AVLC_SOURCED=1 . buildsystem/compile-libvlc.sh
@@ -31,7 +31,7 @@ AVLC_SOURCED=1 . buildsystem/compile-libvlc.sh
 ################
 
 if [ ! -d "${SRC_DIR}/medialibrary" ]; then
-    mkdir "${SRC_DIR}/medialibrary"
+  mkdir "${SRC_DIR}/medialibrary"
 fi
 
 ##########
@@ -45,18 +45,18 @@ SQLITE_RELEASE="sqlite-autoconf-3250300"
 SQLITE_SHA1="5d6dc7634ec59e7a6fffa8758c1e184b2522c2e5"
 
 if [ ! -d "${MEDIALIBRARY_MODULE_DIR}/${SQLITE_RELEASE}" ]; then
-    echo -e "\e[1m\e[32msqlite source not found, downloading\e[0m"
-    cd ${MEDIALIBRARY_MODULE_DIR}
-    rm -rf ${MEDIALIBRARY_BUILD_DIR}/build-android*
-    rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/libs
-    rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/obj
-    wget https://download.videolan.org/pub/contrib/sqlite/${SQLITE_RELEASE}.tar.gz
+  echo -e "\e[1m\e[32msqlite source not found, downloading\e[0m"
+  cd ${MEDIALIBRARY_MODULE_DIR}
+  rm -rf ${MEDIALIBRARY_BUILD_DIR}/build-android*
+  rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/libs
+  rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/obj
+  wget https://download.videolan.org/pub/contrib/sqlite/${SQLITE_RELEASE}.tar.gz
     if [ ! "`sha1sum ${SQLITE_RELEASE}.tar.gz`" = "${SQLITE_SHA1}  ${SQLITE_RELEASE}.tar.gz" ]; then
-        echo "Wrong sha1 for ${SQLITE_RELEASE}.tar.gz"
-        exit 1
-    fi
-    tar -xozf ${SQLITE_RELEASE}.tar.gz
-    rm -f ${SQLITE_RELEASE}.tar.gz
+    echo "Wrong sha1 for ${SQLITE_RELEASE}.tar.gz"
+    exit 1
+  fi
+  tar -xozf ${SQLITE_RELEASE}.tar.gz
+  rm -f ${SQLITE_RELEASE}.tar.gz
 fi
 cd ${MEDIALIBRARY_MODULE_DIR}/${SQLITE_RELEASE}
 if [ ! -d "build-$ANDROID_ABI" ]; then
@@ -65,7 +65,7 @@ fi;
 cd "build-$ANDROID_ABI";
 
 if [ ! -e ./config.status -o "$RELEASE" = "1" ]; then
-../configure \
+  ../configure \
     --host=$TARGET_TUPLE \
     --disable-shared \
     CFLAGS="${VLC_CFLAGS}" \
@@ -84,25 +84,25 @@ avlc_checkfail "sqlite build failed"
 ##############################
 
 if [ ! -d "${MEDIALIBRARY_MODULE_DIR}/medialibrary" ]; then
-    echo -e "\e[1m\e[32mmedialibrary source not found, cloning\e[0m"
-    git clone http://code.videolan.org/videolan/medialibrary.git "${SRC_DIR}/medialibrary/medialibrary"
-    avlc_checkfail "medialibrary source: git clone failed"
-    cd ${MEDIALIBRARY_MODULE_DIR}/medialibrary
-#    git checkout 0.5.x
-    git submodule update --init libvlcpp
+  echo -e "\e[1m\e[32mmedialibrary source not found, cloning\e[0m"
+  git clone http://code.videolan.org/videolan/medialibrary.git "${SRC_DIR}/medialibrary/medialibrary"
+  avlc_checkfail "medialibrary source: git clone failed"
+  cd ${MEDIALIBRARY_MODULE_DIR}/medialibrary
+  #    git checkout 0.5.x
+  git submodule update --init libvlcpp
 else
-    cd ${MEDIALIBRARY_MODULE_DIR}/medialibrary
-    if ! git cat-file -e ${MEDIALIBRARY_HASH}; then
-      git pull --rebase
-      rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/libs
-      rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/obj
-    fi
+  cd ${MEDIALIBRARY_MODULE_DIR}/medialibrary
+  if ! git cat-file -e ${MEDIALIBRARY_HASH}; then
+    git pull --rebase
+    rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/libs
+    rm -rf ${MEDIALIBRARY_MODULE_DIR}/jni/obj
+  fi
 fi
 if [ "$RELEASE" = "1" ]; then
-    git reset --hard ${MEDIALIBRARY_HASH}
-    # In case of VLC 4.0 build, we need this commit to fix the build, but we
-    # still don't want to change the HASH for that.
-    git cherry-pick bfb2ad6e8b34a62c482e3064e6e13751482b903f
+  git reset --hard ${MEDIALIBRARY_HASH}
+  # In case of VLC 4.0 build, we need this commit to fix the build, but we
+  # still don't want to change the HASH for that.
+  git cherry-pick bfb2ad6e8b34a62c482e3064e6e13751482b903f
 fi
 cd ${SRC_DIR}
 
@@ -123,11 +123,11 @@ fi;
 cd "build-android-$ANDROID_ABI/";
 
 if [ "$RELEASE" = "1" ]; then
-    MEDIALIBRARY_MODE=--disable-debug
+  MEDIALIBRARY_MODE=--disable-debug
 fi
 if [ ! -e ./config.h -o "$RELEASE" = "1" ]; then
-../bootstrap
-../configure \
+  ../bootstrap
+  ../configure \
     --host=$TARGET_TUPLE \
     --disable-shared \
     ${MEDIALIBRARY_MODE} \
@@ -144,7 +144,7 @@ if [ ! -e ./config.h -o "$RELEASE" = "1" ]; then
     SQLITE_LIBS="-L$MEDIALIBRARY_MODULE_DIR/$SQLITE_RELEASE/build-$ANDROID_ABI/.libs -lsqlite3" \
     SQLITE_CFLAGS="-I$MEDIALIBRARY_MODULE_DIR/$SQLITE_RELEASE" \
     AR="${CROSS_TOOLS}ar"
-avlc_checkfail "medialibrary: autoconf failed"
+  avlc_checkfail "medialibrary: autoconf failed"
 fi
 
 ############
@@ -165,15 +165,15 @@ MEDIALIBRARY_LDLIBS="$VLC_OUT_LDLIBS \
 -L${NDK_LIB_DIR} -lc++abi ${NDK_LIB_UNWIND}"
 
 $NDK_BUILD -C medialibrary \
-    APP_STL="c++_shared" \
-    LOCAL_CPP_FEATURES="rtti exceptions" \
-    APP_BUILD_SCRIPT=jni/Android.mk \
-    APP_PLATFORM=android-${ANDROID_API} \
-    APP_ABI=${ANDROID_ABI} \
-    NDK_PROJECT_PATH=jni \
-    NDK_TOOLCHAIN_VERSION=clang \
-    MEDIALIBRARY_LDLIBS="${MEDIALIBRARY_LDLIBS}" \
-    MEDIALIBRARY_INCLUDE_DIR=${MEDIALIBRARY_BUILD_DIR}/include \
-    NDK_DEBUG=${NDK_DEBUG}
+  APP_STL="c++_shared" \
+  LOCAL_CPP_FEATURES="rtti exceptions" \
+  APP_BUILD_SCRIPT=jni/Android.mk \
+  APP_PLATFORM=android-${ANDROID_API} \
+  APP_ABI=${ANDROID_ABI} \
+  NDK_PROJECT_PATH=jni \
+  NDK_TOOLCHAIN_VERSION=clang \
+  MEDIALIBRARY_LDLIBS="${MEDIALIBRARY_LDLIBS}" \
+  MEDIALIBRARY_INCLUDE_DIR=${MEDIALIBRARY_BUILD_DIR}/include \
+  NDK_DEBUG=${NDK_DEBUG}
 
 avlc_checkfail "nkd-build medialibrary failed"
diff --git a/medialibrary/src/org/videolan/medialibrary/media/VideoGroupImpl.java b/medialibrary/src/org/videolan/medialibrary/media/VideoGroupImpl.java
index 64ad6a948..b5119c3c0 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/VideoGroupImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/VideoGroupImpl.java
@@ -64,7 +64,9 @@ public class VideoGroupImpl extends VideoGroup {
     @Override
     public boolean rename(String name) {
         final Medialibrary ml = Medialibrary.getInstance();
-        return ml.isInitiated() && nativeGroupRename(ml, mId, name);
+        boolean newNameSet = ml.isInitiated() && nativeGroupRename(ml, mId, name);
+        if (newNameSet) setTitle(name);
+        return newNameSet;
     }
 
     @Override



More information about the Android mailing list