[Android] Factorize Medialibrary paging size declaration

Geoffrey Métais git at videolan.org
Tue Jan 15 10:15:41 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan 15 10:14:39 2019 +0100| [372f2d9cc544b6cf03de940c779784e209dd3d06] | committer: Geoffrey Métais

Factorize Medialibrary paging size declaration

> https://code.videolan.org/videolan/vlc-android/commit/372f2d9cc544b6cf03de940c779784e209dd3d06
---

 vlc-android/src/org/videolan/vlc/media/MediaUtils.kt         | 12 ++++++------
 vlc-android/src/org/videolan/vlc/util/Constants.kt           |  2 +-
 .../src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt    |  5 +++--
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index 2e3f9544a..1c8132084 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -142,7 +142,7 @@ object MediaUtils : CoroutineScope {
             val count = withContext(Dispatchers.IO) { model.getTotalCount() }
             when (count) {
                 0 -> null
-                in 1..PLAYBACK_LOAD_SIZE -> withContext(Dispatchers.IO) {
+                in 1..MEDIALIBRARY_PAGE_SIZE -> withContext(Dispatchers.IO) {
                     mutableListOf<MediaWrapper>().apply {
                         for (album in model.getAll()) album.tracks?.let { addAll(it) }
                     }
@@ -151,7 +151,7 @@ object MediaUtils : CoroutineScope {
                     mutableListOf<MediaWrapper>().apply {
                         var index = 0
                         while (index < count) {
-                            val pageCount = min(PLAYBACK_LOAD_SIZE, count-index)
+                            val pageCount = min(MEDIALIBRARY_PAGE_SIZE, count-index)
                             val albums = withContext(Dispatchers.IO) { model.getPage(pageCount, index) }
                             for (album in albums) addAll(album.tracks)
                             index += pageCount
@@ -170,16 +170,16 @@ object MediaUtils : CoroutineScope {
         SuspendDialogCallback(context) { service ->
             val count = withContext(Dispatchers.IO) { model.getTotalCount() }
             fun play(list : List<MediaWrapper>) {
-                service.load(list, if (shuffle) Random().nextInt(min(count, PLAYBACK_LOAD_SIZE)) else position)
+                service.load(list, if (shuffle) Random().nextInt(min(count, MEDIALIBRARY_PAGE_SIZE)) else position)
                 if (shuffle && !service.isShuffling) service.shuffle()
             }
             when (count) {
                 0 -> return at SuspendDialogCallback
-                in 1..PLAYBACK_LOAD_SIZE -> play(withContext(Dispatchers.IO) { model.getAll().toList() })
+                in 1..MEDIALIBRARY_PAGE_SIZE -> play(withContext(Dispatchers.IO) { model.getAll().toList() })
                 else -> {
                     var index = 0
                     while (index < count) {
-                        val pageCount = min(PLAYBACK_LOAD_SIZE, count - index)
+                        val pageCount = min(MEDIALIBRARY_PAGE_SIZE, count - index)
                         val list = withContext(Dispatchers.IO) { model.getPage(pageCount, index).toList() }
                         if (index == 0) play(list)
                         else service.append(list)
@@ -384,7 +384,7 @@ fun Folder.getAll(type: Int = Folder.TYPE_FOLDER_VIDEO, sort: Int = Medialibrary
     val count = mediaCount(type)
     val all = mutableListOf<MediaWrapper>()
     while (index < count) {
-        val pageCount = min(PLAYBACK_LOAD_SIZE, count - index)
+        val pageCount = min(MEDIALIBRARY_PAGE_SIZE, count - index)
         val list = media(type, sort, desc, pageCount, index)
         all.addAll(list)
         index += pageCount
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index cd043100e..878f4f00e 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -63,7 +63,7 @@ const val PLAYLIST_TYPE_VIDEO = 1
 const val REPEAT_NONE = 0
 const val REPEAT_ONE = 1
 const val REPEAT_ALL = 2
-const val PLAYBACK_LOAD_SIZE = 500
+const val MEDIALIBRARY_PAGE_SIZE = 100
 
 
 // MediaParsingService
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
index 5f7d20ec9..a25526457 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
@@ -12,6 +12,7 @@ import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
 import org.videolan.medialibrary.Medialibrary
 import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.vlc.util.MEDIALIBRARY_PAGE_SIZE
 import org.videolan.vlc.util.Settings
 import org.videolan.vlc.viewmodels.SortableModel
 
@@ -20,8 +21,8 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
     val loading = MutableLiveData<Boolean>().apply { value = false }
 
     private val pagingConfig = PagedList.Config.Builder()
-            .setPageSize(100)
-            .setPrefetchDistance(100)
+            .setPageSize(MEDIALIBRARY_PAGE_SIZE)
+            .setPrefetchDistance(MEDIALIBRARY_PAGE_SIZE/2)
             .setEnablePlaceholders(true)
             .build()
 



More information about the Android mailing list