Commit 36bc38c2 authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Geoffrey Métais

PlaylistsViewModel for PlaylistFragment

parent 43d4d0d4
......@@ -56,11 +56,11 @@ import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.reloadLibrary
import org.videolan.vlc.util.CTX_PLAY_ALL
import org.videolan.vlc.util.getScreenWidth
import org.videolan.vlc.viewmodels.paged.PagedPlaylistsModel
import org.videolan.vlc.viewmodels.mobile.PlaylistsViewModel
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
class PlaylistFragment : BaseAudioBrowser<PagedPlaylistsModel>(), SwipeRefreshLayout.OnRefreshListener {
class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLayout.OnRefreshListener {
private lateinit var binding: PlaylistsFragmentBinding
private lateinit var playlists: RecyclerView
......@@ -69,7 +69,7 @@ class PlaylistFragment : BaseAudioBrowser<PagedPlaylistsModel>(), SwipeRefreshLa
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel = ViewModelProviders.of(requireActivity(), PagedPlaylistsModel.Factory(requireContext())).get(PagedPlaylistsModel::class.java)
viewModel = ViewModelProviders.of(requireActivity(), PlaylistsViewModel.Factory(requireContext())).get(PlaylistsViewModel::class.java)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
......@@ -120,11 +120,11 @@ class PlaylistFragment : BaseAudioBrowser<PagedPlaylistsModel>(), SwipeRefreshLa
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel.pagedList.observe(requireActivity(), Observer {
viewModel.provider.pagedList.observe(requireActivity(), Observer {
playlistAdapter.submitList(it as PagedList<MediaLibraryItem>)
binding.empty.visibility = if (it.isNullOrEmpty()) View.VISIBLE else View.GONE
})
viewModel.loading.observe(this, Observer<Boolean> { loading ->
viewModel.provider.loading.observe(this, Observer<Boolean> { loading ->
launch { binding.swipeLayout.isRefreshing = loading == true }
})
......@@ -132,7 +132,6 @@ class PlaylistFragment : BaseAudioBrowser<PagedPlaylistsModel>(), SwipeRefreshLa
}
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
mode.menuInflater.inflate(R.menu.action_mode_audio_browser, menu)
menu.findItem(R.id.action_mode_audio_add_playlist).isVisible = false
......@@ -152,15 +151,13 @@ class PlaylistFragment : BaseAudioBrowser<PagedPlaylistsModel>(), SwipeRefreshLa
else super.onCtxAction(position, option)
}
override fun onRefresh() {
activity?.reloadLibrary()
}
override fun getTitle(): String = getString(R.string.playlists)
override fun getCurrentRV(): RecyclerView = playlists
override fun hasFAB() = false
}
\ No newline at end of file
}
/*****************************************************************************
* AlbumSongsViewModel.kt
*****************************************************************************
* Copyright © 2019 VLC authors and VideoLAN
*
* 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.viewmodels.mobile
import android.content.Context
......
/*****************************************************************************
* AudioBrowserViewModel.kt
*****************************************************************************
* Copyright © 2019 VLC authors and VideoLAN
*
* 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.viewmodels.mobile
import android.content.Context
......
/*****************************************************************************
* PlaylistViewModel.kt
*****************************************************************************
* Copyright © 2019 VLC authors and VideoLAN
*
* 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.viewmodels.mobile
import android.content.Context
......
/*****************************************************************************
* PlaylistsViewModel.kt
*****************************************************************************
* Copyright © 2019 VLC authors and VideoLAN
*
* 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.viewmodels.mobile
import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.providers.medialibrary.PlaylistsProvider
import org.videolan.vlc.viewmodels.MedialibraryViewModel
class PlaylistsViewModel(context: Context) : MedialibraryViewModel(context) {
val provider = PlaylistsProvider(context, this)
override val providers : Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
class Factory(val context: Context): ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return PlaylistsViewModel(context.applicationContext) as T
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment