[Android] Use model pagination and new adapter for videos
Nicolas Pomepuy
git at videolan.org
Thu Apr 11 18:38:03 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Apr 5 11:48:02 2019 +0200| [2e2489cd94ef0a0bdb0c68a11b83bd05d1915d77] | committer: Geoffrey Métais
Use model pagination and new adapter for videos
> https://code.videolan.org/videolan/vlc-android/commit/2e2489cd94ef0a0bdb0c68a11b83bd05d1915d77
---
.../vlc/gui/tv/browser/AudioBrowserTvFragment.kt | 4 +++
.../vlc/gui/tv/browser/VerticalGridActivity.java | 10 +-----
.../vlc/gui/tv/browser/VideoBrowserFragment.kt | 41 ----------------------
.../videolan/vlc/gui/tv/browser/VideosFragment.kt | 21 -----------
vlc-android/src/org/videolan/vlc/util/Constants.kt | 1 +
.../vlc/viewmodels/paged/PagedVideosModel.kt | 20 ++++++-----
6 files changed, 18 insertions(+), 79 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt
index 4a4e2443e..fd1656ec0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt
@@ -45,6 +45,7 @@ import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.videolan.medialibrary.Medialibrary
+import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
@@ -111,6 +112,8 @@ class AudioBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
viewModel = ViewModelProviders.of(this, PagedArtistsModel.Factory(requireContext(), Settings.getInstance(requireContext()).getBoolean(KEY_ARTISTS_SHOW_ALL, false))).get(PagedArtistsModel::class.java) as MLPagedModel<MediaLibraryItem>
CATEGORY_GENRES ->
viewModel = ViewModelProviders.of(this, PagedGenresModel.Factory(requireContext())).get(PagedGenresModel::class.java) as MLPagedModel<MediaLibraryItem>
+ CATEGORY_VIDEOS ->
+ viewModel = ViewModelProviders.of(this, PagedVideosModel.Factory(requireContext(), currentItem as? Folder)).get(PagedVideosModel::class.java) as MLPagedModel<MediaLibraryItem>
}
@@ -165,6 +168,7 @@ class AudioBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
CATEGORY_ALBUMS -> title.setText(R.string.albums)
CATEGORY_ARTISTS -> title.setText(R.string.artists)
CATEGORY_GENRES -> title.setText(R.string.genres)
+ CATEGORY_VIDEOS -> title.setText(R.string.videos)
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
index fc94893b9..5884ec787 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
@@ -31,7 +31,6 @@ import android.widget.TextView;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.vlc.R;
-import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.tv.MainTvActivity;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserActivityInterface;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface;
@@ -59,14 +58,7 @@ public class VerticalGridActivity extends BaseTvActivity implements BrowserActiv
if (savedInstanceState == null) {
long type = getIntent().getLongExtra(MainTvActivity.BROWSER_TYPE, -1);
if (type == Constants.HEADER_VIDEO) {
- final String group = getIntent().getStringExtra(Constants.KEY_GROUP);
- if (group != null) {
- mFragment = new VideosFragment();
- final Bundle args = new Bundle(1);
- args.putString(Constants.KEY_GROUP, group);
- ((Fragment)mFragment).setArguments(args);
- } else if (VLCApplication.getMLInstance().getVideoCount() > GRID_LIMIT) mFragment = new VideoBrowserFragment();
- else mFragment = new VideosFragment();
+ mFragment = AudioBrowserTvFragment.Companion.newInstance(Constants.CATEGORY_VIDEOS, null);
}
else if (type == Constants.HEADER_CATEGORIES) {
final long audioCategory = getIntent().getLongExtra(Constants.AUDIO_CATEGORY, Constants.CATEGORY_SONGS);
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VideoBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VideoBrowserFragment.kt
deleted file mode 100644
index f3507326f..000000000
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VideoBrowserFragment.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * *************************************************************************
- * VideoBrowserFragment.kt
- * **************************************************************************
- * Copyright © 2018 VLC authors and VideoLAN
- * Author: Geoffrey Métais
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- * ***************************************************************************
- */
-
-package org.videolan.vlc.gui.tv.browser
-
-import android.annotation.TargetApi
-import androidx.lifecycle.Observer
-import android.os.Build
-import android.os.Bundle
-import org.videolan.vlc.util.KEY_GROUP
-import org.videolan.vlc.viewmodels.VideosModel
-
- at TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
-class VideoBrowserFragment : CategoriesFragment<VideosModel>() {
-
- override fun onCreate(savedInstanceState: Bundle?) {
- viewModel = VideosModel.get(requireContext(), this, group = arguments?.getString(KEY_GROUP))
- viewModel.categories.observe(this, Observer { update(it) })
- super.onCreate(savedInstanceState)
- }
-}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VideosFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VideosFragment.kt
deleted file mode 100644
index cb1d508b4..000000000
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VideosFragment.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.videolan.vlc.gui.tv.browser
-
-import androidx.lifecycle.Observer
-import android.os.Bundle
-import org.videolan.vlc.R
-import org.videolan.vlc.util.KEY_GROUP
-import org.videolan.vlc.viewmodels.VideosModel
-
-
-class VideosFragment : MediaLibBrowserFragment<VideosModel>() {
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- val group = arguments?.getString(KEY_GROUP)
- title = group ?: getString(R.string.videos)
- model = VideosModel.get(requireContext(), this, group = group)
- model.dataset.observe(this, Observer { update(it!!) })
- }
-
- fun sort(sort: Int) = model.sort(sort)
-}
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index c5c39c1bc..8b46df5c7 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -122,6 +122,7 @@ const val CATEGORY_ARTISTS = 21L
const val CATEGORY_ALBUMS = 22L
const val CATEGORY_GENRES = 23L
const val CATEGORY_SONGS = 24L
+const val CATEGORY_VIDEOS = 25L
const val AUDIO_CATEGORY = "category"
const val AUDIO_ITEM = "item"
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedVideosModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedVideosModel.kt
index 711d945a5..c01751860 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedVideosModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedVideosModel.kt
@@ -59,12 +59,16 @@ class PagedVideosModel(
else -> medialibrary.getVideoCount(filterQuery)
}
- override fun getPage(loadSize: Int, startposition: Int): Array<MediaWrapper> = if (filterQuery == null) when {
- folder !== null -> folder.media(Folder.TYPE_FOLDER_VIDEO, sort, desc, loadSize, startposition)
- else -> medialibrary.getPagedVideos(sort, desc, loadSize, startposition)
- } else when {
- folder !== null -> folder.searchTracks(filterQuery, Folder.TYPE_FOLDER_VIDEO, sort, desc, loadSize, startposition)
- else -> medialibrary.searchVideo(filterQuery, sort, desc, loadSize, startposition)
+ override fun getPage(loadSize: Int, startposition: Int): Array<MediaWrapper> {
+ val list = if (filterQuery == null) when {
+ folder !== null -> folder.media(Folder.TYPE_FOLDER_VIDEO, sort, desc, loadSize, startposition)
+ else -> medialibrary.getPagedVideos(sort, desc, loadSize, startposition)
+ } else when {
+ folder !== null -> folder.searchTracks(filterQuery, Folder.TYPE_FOLDER_VIDEO, sort, desc, loadSize, startposition)
+ else -> medialibrary.searchVideo(filterQuery, sort, desc, loadSize, startposition)
+ }
+
+ return list.also { completeHeaders(it, startposition) }
}
override fun getAll(): Array<MediaWrapper> = when {
@@ -81,8 +85,8 @@ class PagedVideosModel(
class Factory(
private val context: Context,
private val folder : Folder?,
- private val sort : Int,
- private val desc : Boolean?
+ private val sort: Int = Medialibrary.SORT_DEFAULT,
+ private val desc: Boolean? = null
): ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
More information about the Android
mailing list