Commit 418bbc70 authored by Duncan McNAMARA's avatar Duncan McNAMARA
Browse files

Medialibrary: move Folder to AFolder

parent d2519832
......@@ -1791,7 +1791,7 @@ static JNINativeMethod methods[] = {
{"nativeGetPagedPlaylists", "(IZII)[Lorg/videolan/medialibrary/media/Playlist;", (void*)getPagedPlaylists },
{"nativeGetPlaylistsCount", "()I", (void*)getPlaylistsCount },
{"nativeGetPlaylist", "(J)Lorg/videolan/medialibrary/media/Playlist;", (void*)getPlaylist },
{"nativeGetFolders", "(IIZII)[Lorg/videolan/medialibrary/media/Folder;", (void*)folders },
{"nativeGetFolders", "(IIZII)[Lorg/videolan/medialibrary/interfaces/media/AFolder;", (void*)folders },
{"nativeGetFoldersCount", "(I)I", (void*)foldersCount },
{"nativePauseBackgroundOperations", "()V", (void*)pauseBackgroundOperations },
{"nativeResumeBackgroundOperations", "()V", (void*)resumeBackgroundOperations },
......@@ -1855,7 +1855,7 @@ static JNINativeMethod genre_methods[] = {
static JNINativeMethod folder_methods[] = {
{"nativeMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIIZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)mediaFromFolder },
{"nativeSubfolders", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/Folder;", (void*)subFolders },
{"nativeSubfolders", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/interfaces/media/AFolder;", (void*)subFolders },
{"nativeMediaCount", "(Lorg/videolan/medialibrary/Medialibrary;JI)I", (void*)mediaFromFolderCount },
{"nativeSubfoldersCount", "(Lorg/videolan/medialibrary/Medialibrary;JI)I", (void*)subFoldersCount },
{"nativeSearch", "(Lorg/videolan/medialibrary/Medialibrary;JLjava/lang/String;IIZII)[Lorg/videolan/medialibrary/interfaces/media/AMediaWrapper;", (void*)searchMediaFromFolder },
......
......@@ -35,9 +35,9 @@ import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
import org.videolan.medialibrary.interfaces.EntryPointsEventsCb;
import org.videolan.medialibrary.interfaces.media.AAlbum;
import org.videolan.medialibrary.interfaces.media.AArtist;
import org.videolan.medialibrary.interfaces.media.AFolder;
import org.videolan.medialibrary.interfaces.media.AGenre;
import org.videolan.medialibrary.interfaces.media.AMediaWrapper;
import org.videolan.medialibrary.media.Folder;
import org.videolan.medialibrary.media.Playlist;
import org.videolan.medialibrary.media.SearchAggregate;
......@@ -463,8 +463,8 @@ public class Medialibrary {
@NonNull
@WorkerThread
public Folder[] getFolders(int type, int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated ? nativeGetFolders(type, sort, desc, nbItems, offset) : new Folder[0];
public AFolder[] getFolders(int type, int sort, boolean desc, int nbItems, int offset) {
return mIsInitiated ? nativeGetFolders(type, sort, desc, nbItems, offset) : new AFolder[0];
}
@NonNull
......@@ -1017,7 +1017,7 @@ public class Medialibrary {
private native int nativeGetPlaylistsCount();
private native Playlist nativeGetPlaylist(long playlistId);
private native Playlist nativePlaylistCreate(String name);
private native Folder[] nativeGetFolders(int type, int sort, boolean desc, int nbItems, int offset);
private native AFolder[] nativeGetFolders(int type, int sort, boolean desc, int nbItems, int offset);
private native int nativeGetFoldersCount(int type);
private native void nativePauseBackgroundOperations();
private native void nativeResumeBackgroundOperations();
......
......@@ -7,14 +7,17 @@ import android.os.Parcel;
import org.videolan.libvlc.Media;
import org.videolan.medialibrary.interfaces.media.AAlbum;
import org.videolan.medialibrary.interfaces.media.AArtist;
import org.videolan.medialibrary.interfaces.media.AFolder;
import org.videolan.medialibrary.interfaces.media.AGenre;
import org.videolan.medialibrary.interfaces.media.AMediaWrapper;
import org.videolan.medialibrary.media.Album;
import org.videolan.medialibrary.media.Artist;
import org.videolan.medialibrary.media.Folder;
import org.videolan.medialibrary.media.Genre;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.medialibrary.stubs.StubAlbum;
import org.videolan.medialibrary.stubs.StubArtist;
import org.videolan.medialibrary.stubs.StubFolder;
import org.videolan.medialibrary.stubs.StubGenre;
import org.videolan.medialibrary.stubs.StubMediaWrapper;
......@@ -150,4 +153,21 @@ public class ServiceLocator {
return new StubAlbum(in);
}
}
//Folder
public static AFolder getAFolder(long id, String name, String mrl) {
if (mMode == LocatorMode.VLC_ANDROID) {
return new Folder(id, name, mrl);
} else {
return new StubFolder(id, name, mrl);
}
}
public static AFolder getAFolder(Parcel in) {
if (mMode == LocatorMode.VLC_ANDROID) {
return new Folder(in);
} else {
return new StubFolder(in);
}
}
}
package org.videolan.medialibrary.interfaces.media;
import android.os.Parcel;
import android.os.Parcelable;
import org.videolan.medialibrary.ServiceLocator;
import org.videolan.medialibrary.media.MediaLibraryItem;
public abstract class AFolder extends MediaLibraryItem {
public static int TYPE_FOLDER_UNKNOWN = 0;
public static int TYPE_FOLDER_VIDEO = 1;
public static int TYPE_FOLDER_AUDIO = 2;
public static int TYPE_FOLDER_EXTERNAL = 3;
public static int TYPE_FOLDER_STREAM = 4;
private String mMrl;
public AFolder(long id, String name, String mrl) {
super(id, name);
mMrl = mrl;
}
abstract public AMediaWrapper[] media(int type, int sort, boolean desc, int nbItems, int offset);
abstract public int mediaCount(int type);
abstract public AFolder[] subfolders(int sort, boolean desc, int nbItems, int offset);
abstract public int subfoldersCount(int type);
abstract public AMediaWrapper[] searchTracks(String query, int mediaType, int sort, boolean desc, int nbItems, int offset);
abstract public int searchTracksCount(String query, int mediaType);
@Override
public AMediaWrapper[] getTracks() {
return new AMediaWrapper[0];
}
@Override
public int getTracksCount() {
return 0;
}
@Override
public int getItemType() {
return TYPE_FOLDER;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeString(mMrl);
}
public static Parcelable.Creator<AFolder> CREATOR = new Parcelable.Creator<AFolder>() {
@Override
public AFolder createFromParcel(Parcel in) {
return ServiceLocator.getAFolder(in);
}
@Override
public AFolder[] newArray(int size) {
return new AFolder[size];
}
};
public AFolder(Parcel in) {
super(in);
this.mMrl = in.readString();
}
}
package org.videolan.medialibrary.media;
import android.os.Parcel;
import android.os.Parcelable;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.interfaces.media.AFolder;
import org.videolan.medialibrary.interfaces.media.AMediaWrapper;
@SuppressWarnings("JniMissingFunction")
public class Folder extends MediaLibraryItem {
public static int TYPE_FOLDER_UNKNOWN = 0;
public static int TYPE_FOLDER_VIDEO = 1;
public static int TYPE_FOLDER_AUDIO = 2;
public static int TYPE_FOLDER_EXTERNAL = 3;
public static int TYPE_FOLDER_STREAM = 4;
private String mMrl;
public class Folder extends AFolder {
public Folder(long id, String name, String mrl) {
super(id, name);
mMrl = mrl;
}
@Override
public AMediaWrapper[] getTracks() {
return new AMediaWrapper[0];
super(id, name, mrl);
}
@Override
public int getTracksCount() {
return 0;
}
@Override
public int getItemType() {
return TYPE_FOLDER;
public Folder(Parcel in) {
super(in);
}
public AMediaWrapper[] media(int type, int sort, boolean desc, int nbItems, int offset) {
......@@ -47,7 +27,7 @@ public class Folder extends MediaLibraryItem {
return ml.isInitiated() ? nativeMediaCount(ml, mId, type) : 0;
}
public Folder[] subfolders(int sort, boolean desc, int nbItems, int offset) {
public AFolder[] subfolders(int sort, boolean desc, int nbItems, int offset) {
final Medialibrary ml = Medialibrary.getInstance();
return ml.isInitiated() ? nativeSubfolders(ml, mId, sort, desc, nbItems, offset) : new Folder[0];
}
......@@ -71,31 +51,8 @@ public class Folder extends MediaLibraryItem {
// private native int nativeGetTracksCount();
private native AMediaWrapper[] nativeMedia(Medialibrary ml, long mId, int type, int sort, boolean desc, int nbItems, int offset);
private native int nativeMediaCount(Medialibrary ml, long mId, int type);
private native Folder[] nativeSubfolders(Medialibrary ml, long mId, int sort, boolean desc, int nbItems, int offset);
private native AFolder[] nativeSubfolders(Medialibrary ml, long mId, int sort, boolean desc, int nbItems, int offset);
private native int nativeSubfoldersCount(Medialibrary ml, long mId, int type);
private native AMediaWrapper[] nativeSearch(Medialibrary ml, long mId, String query, int mediaType, int sort, boolean desc, int nbItems, int offset);
private native int nativeGetSearchCount(Medialibrary ml, long mId, String query, int mediaType);
@Override
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeString(mMrl);
}
public static Parcelable.Creator<Folder> CREATOR = new Parcelable.Creator<Folder>() {
@Override
public Folder createFromParcel(Parcel in) {
return new Folder(in);
}
@Override
public Folder[] newArray(int size) {
return new Folder[size];
}
};
private Folder(Parcel in) {
super(in);
this.mMrl = in.readString();
}
}
package org.videolan.medialibrary.stubs;
import android.os.Parcel;
import org.videolan.medialibrary.interfaces.media.AFolder;
import org.videolan.medialibrary.interfaces.media.AMediaWrapper;
public class StubFolder extends AFolder {
public StubFolder(long id, String name, String mrl) {
super(id, name, mrl);
}
public StubFolder(Parcel in) {
super(in);
}
public AMediaWrapper[] media(int type, int sort, boolean desc, int nbItems, int offset) {
return null;
}
public int mediaCount(int type) {
return 0;
}
public AFolder[] subfolders(int sort, boolean desc, int nbItems, int offset) {
return null;
}
public int subfoldersCount(int type) {
return 0;
}
public AMediaWrapper[] searchTracks(String query, int mediaType, int sort, boolean desc, int nbItems, int offset) {
return null;
}
public int searchTracksCount(String query, int mediaType) {
return 0;
}
}
......@@ -5,7 +5,7 @@
<data>
<variable
name="folder"
type="org.videolan.medialibrary.media.Folder" />
type="org.videolan.medialibrary.interfaces.media.AFolder" />
<variable
name="bgColor"
......
......@@ -13,14 +13,14 @@ import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.tools.MultiSelectAdapter
import org.videolan.tools.MultiSelectHelper
import org.videolan.vlc.databinding.FolderItemBinding
import org.videolan.vlc.gui.helpers.SelectorViewHolder
import org.videolan.vlc.util.UPDATE_SELECTION
class FoldersAdapter(val actor: SendChannel<FolderAction>) : PagedListAdapter<Folder, FoldersAdapter.ViewHolder>(DIFF_CALLBACK), MultiSelectAdapter<Folder>, CoroutineScope {
class FoldersAdapter(val actor: SendChannel<FolderAction>) : PagedListAdapter<AFolder, FoldersAdapter.ViewHolder>(DIFF_CALLBACK), MultiSelectAdapter<AFolder>, CoroutineScope {
override val coroutineContext = Dispatchers.Main.immediate
private lateinit var inflater: LayoutInflater
......@@ -36,7 +36,7 @@ class FoldersAdapter(val actor: SendChannel<FolderAction>) : PagedListAdapter<Fo
val folder = getItem(position)
holder.binding.folder = folder
launch {
val count = withContext(Dispatchers.IO) { folder?.mediaCount(Folder.TYPE_FOLDER_VIDEO) ?: 0 }
val count = withContext(Dispatchers.IO) { folder?.mediaCount(AFolder.TYPE_FOLDER_VIDEO) ?: 0 }
holder.binding.folderDesc.visibility = if (count == 0) View.GONE else View.VISIBLE
if (count > 0) holder.binding.folderDesc.text = "$count videos"
}
......@@ -54,7 +54,7 @@ class FoldersAdapter(val actor: SendChannel<FolderAction>) : PagedListAdapter<Fo
}
}
override fun getItem(position: Int): Folder? = super.getItem(position)
override fun getItem(position: Int): AFolder? = super.getItem(position)
@TargetApi(Build.VERSION_CODES.M)
inner class ViewHolder(binding: FolderItemBinding) : SelectorViewHolder<FolderItemBinding>(binding) {
......@@ -81,10 +81,10 @@ class FoldersAdapter(val actor: SendChannel<FolderAction>) : PagedListAdapter<Fo
}
private const val UPDATE_PAYLOAD = 1
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Folder>() {
override fun areItemsTheSame( oldItem: Folder, newItem: Folder) = oldItem == newItem
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<AFolder>() {
override fun areItemsTheSame( oldItem: AFolder, newItem: AFolder) = oldItem == newItem
override fun areContentsTheSame(oldItem: Folder, newItem: Folder) = true
override fun areContentsTheSame(oldItem: AFolder, newItem: AFolder) = true
override fun getChangePayload(oldItem: Folder, newItem: Folder) = UPDATE_PAYLOAD
override fun getChangePayload(oldItem: AFolder, newItem: AFolder) = UPDATE_PAYLOAD
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.folders_fragment.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.actor
import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.vlc.R
import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.vlc.gui.browser.MediaBrowserFragment
......@@ -149,6 +149,6 @@ class FoldersFragment : MediaBrowserFragment<FoldersViewModel>(), CtxActionRecei
}
sealed class FolderAction
class FolderClick(val position: Int, val folder: Folder) : FolderAction()
class FolderLongClick(val position: Int, val folder: Folder) : FolderAction()
class FolderCtxClick(val position: Int, val folder: Folder) : FolderAction()
\ No newline at end of file
class FolderClick(val position: Int, val folder: AFolder) : FolderAction()
class FolderLongClick(val position: Int, val folder: AFolder) : FolderAction()
class FolderCtxClick(val position: Int, val folder: AFolder) : FolderAction()
\ No newline at end of file
......@@ -39,8 +39,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.medialibrary.interfaces.media.AMediaWrapper
import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.tools.MultiSelectHelper
import org.videolan.vlc.R
......@@ -105,7 +105,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
val seenMarkVisible = preferences.getBoolean("media_seen", true)
videoListAdapter = VideoListAdapter(this, seenMarkVisible)
multiSelectHelper = videoListAdapter.multiSelectHelper
val folder = if (savedInstanceState != null ) savedInstanceState.getParcelable<Folder>(KEY_FOLDER)
val folder = if (savedInstanceState != null ) savedInstanceState.getParcelable<AFolder>(KEY_FOLDER)
else arguments?.getParcelable(KEY_FOLDER)
viewModel = getViewModel(folder)
viewModel.provider.pagedList.observe(this, this)
......
......@@ -24,6 +24,7 @@ import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.ServiceLocator
import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.media.AAlbum
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.medialibrary.interfaces.media.AMediaWrapper
import org.videolan.medialibrary.media.*
import org.videolan.vlc.PlaybackService
......@@ -436,7 +437,7 @@ object MediaUtils : CoroutineScope {
}
@WorkerThread
fun Folder.getAll(type: Int = Folder.TYPE_FOLDER_VIDEO, sort: Int = Medialibrary.SORT_DEFAULT, desc: Boolean = false): List<AMediaWrapper> {
fun AFolder.getAll(type: Int = AFolder.TYPE_FOLDER_VIDEO, sort: Int = Medialibrary.SORT_DEFAULT, desc: Boolean = false) : List<AMediaWrapper> {
var index = 0
val count = mediaCount(type)
val all = mutableListOf<AMediaWrapper>()
......@@ -449,7 +450,7 @@ fun Folder.getAll(type: Int = Folder.TYPE_FOLDER_VIDEO, sort: Int = Medialibrary
return all
}
fun List<Folder>.getAll(type: Int = Folder.TYPE_FOLDER_VIDEO, sort: Int = Medialibrary.SORT_DEFAULT, desc: Boolean = false): List<AMediaWrapper> {
fun List<AFolder>.getAll(type: Int = AFolder.TYPE_FOLDER_VIDEO, sort: Int = Medialibrary.SORT_DEFAULT, desc: Boolean = false) : List<AMediaWrapper> {
return flatMap { it.getAll(type, sort, desc) }
}
......
......@@ -22,16 +22,16 @@ package org.videolan.vlc.providers.medialibrary
import android.content.Context
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.vlc.viewmodels.SortableModel
@ExperimentalCoroutinesApi
class FoldersProvider(context: Context, scope: SortableModel, val type: Int) : MedialibraryProvider<Folder>(context, scope) {
override fun getAll() : Array<Folder> = medialibrary.getFolders(type, sort, scope.desc, getTotalCount(), 0)
class FoldersProvider(context: Context, scope: SortableModel, val type: Int) : MedialibraryProvider<AFolder>(context, scope) {
override fun getAll() : Array<AFolder> = medialibrary.getFolders(type, sort, scope.desc, getTotalCount(), 0)
override fun getTotalCount() = medialibrary.getFoldersCount(type)
override fun getPage(loadSize: Int, startposition: Int) : Array<Folder> = medialibrary.getFolders(type, sort, scope.desc, loadSize, startposition).also { completeHeaders(it, startposition) }
override fun getPage(loadSize: Int, startposition: Int) : Array<AFolder> = medialibrary.getFolders(type, sort, scope.desc, loadSize, startposition).also { completeHeaders(it, startposition) }
}
\ No newline at end of file
......@@ -22,40 +22,40 @@ package org.videolan.vlc.providers.medialibrary
import android.content.Context
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.medialibrary.interfaces.media.AMediaWrapper
import org.videolan.medialibrary.media.Folder
import org.videolan.vlc.media.getAll
import org.videolan.vlc.viewmodels.SortableModel
@ExperimentalCoroutinesApi
class VideosProvider(val folder : Folder?, context: Context, scope: SortableModel) : MedialibraryProvider<AMediaWrapper>(context, scope){
class VideosProvider(val folder : AFolder?, context: Context, scope: SortableModel) : MedialibraryProvider<AMediaWrapper>(context, scope){
override fun canSortByFileNameName() = true
override fun canSortByDuration() = true
override fun canSortByLastModified() = folder == null
override fun getTotalCount() = if (scope.filterQuery == null) when {
folder !== null -> folder.mediaCount(Folder.TYPE_FOLDER_VIDEO)
folder !== null -> folder.mediaCount(AFolder.TYPE_FOLDER_VIDEO)
else -> medialibrary.videoCount
} else when {
folder !== null -> folder.searchTracksCount(scope.filterQuery, Folder.TYPE_FOLDER_VIDEO)
folder !== null -> folder.searchTracksCount(scope.filterQuery, AFolder.TYPE_FOLDER_VIDEO)
else -> medialibrary.getVideoCount(scope.filterQuery)
}
override fun getPage(loadSize: Int, startposition: Int): Array<AMediaWrapper> {
val list = if (scope.filterQuery == null) when {
folder !== null -> folder.media(Folder.TYPE_FOLDER_VIDEO, sort, scope.desc, loadSize, startposition)
folder !== null -> folder.media(AFolder.TYPE_FOLDER_VIDEO, sort, scope.desc, loadSize, startposition)
else -> medialibrary.getPagedVideos(sort, scope.desc, loadSize, startposition)
} else when {
folder !== null -> folder.searchTracks(scope.filterQuery, Folder.TYPE_FOLDER_VIDEO, sort, scope.desc, loadSize, startposition)
folder !== null -> folder.searchTracks(scope.filterQuery, AFolder.TYPE_FOLDER_VIDEO, sort, scope.desc, loadSize, startposition)
else -> medialibrary.searchVideo(scope.filterQuery, sort, scope.desc, loadSize, startposition)
}
return list.also { completeHeaders(it, startposition) }
}
override fun getAll(): Array<AMediaWrapper> = when {
folder !== null -> folder.getAll(Folder.TYPE_FOLDER_VIDEO, sort, scope.desc).toTypedArray()
folder !== null -> folder.getAll(AFolder.TYPE_FOLDER_VIDEO, sort, scope.desc).toTypedArray()
else -> medialibrary.videos
}
}
\ No newline at end of file
......@@ -15,8 +15,8 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.withContext
import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.Medialibrary.THUMBS_FOLDER_NAME
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.medialibrary.interfaces.media.AMediaWrapper
import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.helpers.AudioUtil.readCoverBitmap
......@@ -41,8 +41,8 @@ object ThumbnailsProvider {
private val lock = Any()
@WorkerThread
fun getFolderThumbnail(folder: Folder, width: Int): Bitmap? {
val media = listOf(*folder.media(Folder.TYPE_FOLDER_VIDEO, Medialibrary.SORT_DEFAULT, true, 4, 0))
fun getFolderThumbnail(folder: AFolder, width: Int): Bitmap? {
val media = listOf(*folder.media(AFolder.TYPE_FOLDER_VIDEO, Medialibrary.SORT_DEFAULT, true, 4, 0))
return getComposedImage("folder:" + folder.title, media, width)
}
......@@ -170,7 +170,7 @@ object ThumbnailsProvider {
suspend fun obtainBitmap(item: MediaLibraryItem, width: Int) = withContext(Dispatchers.IO) {
when (item) {
is AMediaWrapper -> getMediaThumbnail(item, width)
is Folder -> getFolderThumbnail(item, width)
is AFolder -> getFolderThumbnail(item, width)
else -> readCoverBitmap(Uri.decode(item.artworkMrl), width)
}
}
......
......@@ -25,7 +25,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import kotlinx.coroutines.*
import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.gui.folders.FoldersFragment
import org.videolan.vlc.media.MediaUtils
......@@ -51,12 +51,12 @@ class FoldersViewModel(context: Context, val type : Int) : MedialibraryViewModel
list?.let { MediaUtils.appendMedia(context, it) }
}
fun playSelection(selection: List<Folder>) = launch {
fun playSelection(selection: List<AFolder>) = launch {
val list = selection.flatMap { it.getAll() }
MediaUtils.openList(context, list, 0)
}
fun appendSelection(selection: List<Folder>) = launch {
fun appendSelection(selection: List<AFolder>) = launch {
val list = selection.flatMap { it.getAll() }
MediaUtils.appendMedia(context, list)
}
......@@ -71,4 +71,4 @@ class FoldersViewModel(context: Context, val type : Int) : MedialibraryViewModel
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
internal fun FoldersFragment.getViewModel() = ViewModelProviders.of(requireActivity(), FoldersViewModel.Factory(requireContext(), Folder.TYPE_FOLDER_VIDEO)).get(FoldersViewModel::class.java)
internal fun FoldersFragment.getViewModel() = ViewModelProviders.of(requireActivity(), FoldersViewModel.Factory(requireContext(), AFolder.TYPE_FOLDER_VIDEO)).get(FoldersViewModel::class.java)
......@@ -26,7 +26,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.medialibrary.media.Folder
import org.videolan.medialibrary.interfaces.media.AFolder
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.gui.video.VideoGridFragment
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
......@@ -34,11 +34,11 @@ import org.videolan.vlc.providers.medialibrary.VideosProvider
import org.videolan.vlc.viewmodels.MedialibraryViewModel
@ExperimentalCoroutinesApi
class VideosViewModel(context: Context, val folder: Folder?) : MedialibraryViewModel(context) {
class VideosViewModel(context: Context, val folder: AFolder?) : MedialibraryViewModel(context) {
val provider = VideosProvider(folder, context, this)
override val providers: Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
class Factory(val context: Context, val folder: Folder?): ViewModelProvider.NewInstanceFactory() {
class Factory(val context: Context, val folder: AFolder?): ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return VideosViewModel(context.applicationContext, folder) as T
......@@ -48,4 +48,4 @@ class VideosViewModel(context: Context, val folder: Folder?) : MedialibraryViewM
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
internal fun VideoGridFragment.getViewModel(folder: Folder?) = ViewModelProviders.of(requireActivity(), VideosViewModel.Factory(requireContext(), folder)).get(VideosViewModel::class.java)
\ No newline at end of file
internal fun VideoGridFragment.getViewModel(folder: AFolder?) = ViewModelProviders.of(requireActivity(), VideosViewModel.Factory(requireContext(), folder)).get(VideosViewModel::class.java)
\ No newline at end of file