mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-19 19:14:51 +00:00
Merge branch 'playlist-fixes' into 'master'
Playlist Fixes See merge request videostreaming/grayjay!21
This commit is contained in:
commit
c76ef7f19b
2 changed files with 117 additions and 69 deletions
|
@ -14,6 +14,7 @@ import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
|||
import com.futo.platformplayer.api.media.models.video.SerializedPlatformVideo
|
||||
import com.futo.platformplayer.constructs.TaskHandler
|
||||
import com.futo.platformplayer.downloads.VideoDownload
|
||||
import com.futo.platformplayer.fragment.mainactivity.topbar.NavigationTopBarFragment
|
||||
import com.futo.platformplayer.logging.Logger
|
||||
import com.futo.platformplayer.models.Playlist
|
||||
import com.futo.platformplayer.states.StateApp
|
||||
|
@ -144,53 +145,59 @@ class PlaylistFragment : MainFragment() {
|
|||
}
|
||||
|
||||
fun onShown(parameter: Any?) {
|
||||
_taskLoadPlaylist.cancel();
|
||||
_taskLoadPlaylist.cancel()
|
||||
|
||||
if (parameter is Playlist?) {
|
||||
_playlist = parameter;
|
||||
_url = null;
|
||||
_playlist = parameter
|
||||
_url = null
|
||||
|
||||
if(parameter != null) {
|
||||
setName(parameter.name);
|
||||
setVideos(parameter.videos, true);
|
||||
setVideoCount(parameter.videos.size);
|
||||
setButtonDownloadVisible(true);
|
||||
setButtonEditVisible(true);
|
||||
if (parameter != null) {
|
||||
setName(parameter.name)
|
||||
setVideos(parameter.videos, true)
|
||||
setVideoCount(parameter.videos.size)
|
||||
setButtonDownloadVisible(true)
|
||||
setButtonEditVisible(true)
|
||||
|
||||
if (!StatePlaylists.instance.playlistStore.getItems().contains(parameter)) {
|
||||
_fragment.topBar?.assume<NavigationTopBarFragment>()
|
||||
?.setMenuItems(arrayListOf(Pair(R.drawable.ic_copy) {
|
||||
StatePlaylists.instance.playlistStore.save(parameter)
|
||||
UIDialogs.toast("Playlist saved")
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
setName(null);
|
||||
setVideos(null, false);
|
||||
setVideoCount(-1);
|
||||
setButtonDownloadVisible(false);
|
||||
setButtonEditVisible(false);
|
||||
setName(null)
|
||||
setVideos(null, false)
|
||||
setVideoCount(-1)
|
||||
setButtonDownloadVisible(false)
|
||||
setButtonEditVisible(false)
|
||||
}
|
||||
|
||||
//TODO: Do I have to remove the showConvertPlaylistButton(); button here?
|
||||
} else if (parameter is IPlatformPlaylist) {
|
||||
_playlist = null;
|
||||
_url = parameter.url;
|
||||
_playlist = null
|
||||
_url = parameter.url
|
||||
|
||||
setVideoCount(parameter.videoCount);
|
||||
setName(parameter.name);
|
||||
setVideos(null, false);
|
||||
setButtonDownloadVisible(false);
|
||||
setButtonEditVisible(false);
|
||||
setVideoCount(parameter.videoCount)
|
||||
setName(parameter.name)
|
||||
setVideos(null, false)
|
||||
setButtonDownloadVisible(false)
|
||||
setButtonEditVisible(false)
|
||||
|
||||
fetchPlaylist();
|
||||
fetchPlaylist()
|
||||
} else if (parameter is String) {
|
||||
_playlist = null;
|
||||
_url = parameter;
|
||||
_playlist = null
|
||||
_url = parameter
|
||||
|
||||
setName(null);
|
||||
setVideos(null, false);
|
||||
setVideoCount(-1);
|
||||
setButtonDownloadVisible(false);
|
||||
setButtonEditVisible(false);
|
||||
setName(null)
|
||||
setVideos(null, false)
|
||||
setVideoCount(-1)
|
||||
setButtonDownloadVisible(false)
|
||||
setButtonEditVisible(false)
|
||||
|
||||
fetchPlaylist();
|
||||
fetchPlaylist()
|
||||
}
|
||||
|
||||
_playlist?.let {
|
||||
updateDownloadState(VideoDownload.GROUP_PLAYLIST, it.id, this::download);
|
||||
updateDownloadState(VideoDownload.GROUP_PLAYLIST, it.id, this::download)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,12 +31,16 @@ import com.futo.platformplayer.images.GlideHelper.Companion.crossfade
|
|||
import com.futo.platformplayer.logging.Logger
|
||||
import com.futo.platformplayer.states.StateApp
|
||||
import com.futo.platformplayer.states.StatePlatform
|
||||
import com.futo.platformplayer.states.StatePlayer
|
||||
import com.futo.platformplayer.states.StatePlaylists
|
||||
import com.futo.platformplayer.views.adapters.InsertedViewAdapterWithLoader
|
||||
import com.futo.platformplayer.views.adapters.VideoListEditorViewHolder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
enum class Action {
|
||||
PLAY_ALL, SHUFFLE, PLAY, NONE
|
||||
}
|
||||
|
||||
class RemotePlaylistFragment : MainFragment() {
|
||||
override val isMainView : Boolean = true;
|
||||
|
@ -85,6 +89,8 @@ class RemotePlaylistFragment : MainFragment() {
|
|||
private val _adapterVideos: InsertedViewAdapterWithLoader<VideoListEditorViewHolder>;
|
||||
private val _scrollListener: RecyclerView.OnScrollListener
|
||||
|
||||
|
||||
|
||||
constructor(fragment: RemotePlaylistFragment, inflater: LayoutInflater) : super(inflater.context) {
|
||||
inflater.inflate(R.layout.fragment_remote_playlist, this);
|
||||
|
||||
|
@ -97,18 +103,25 @@ class RemotePlaylistFragment : MainFragment() {
|
|||
_imageLoader = findViewById(R.id.image_loader);
|
||||
_recyclerPlaylist = findViewById(R.id.recycler_playlist);
|
||||
_llmPlaylist = LinearLayoutManager(context);
|
||||
_adapterVideos = InsertedViewAdapterWithLoader(context, arrayListOf(), arrayListOf(),
|
||||
_adapterVideos = InsertedViewAdapterWithLoader(context,
|
||||
arrayListOf(),
|
||||
arrayListOf(),
|
||||
childCountGetter = { _videos.size },
|
||||
childViewHolderBinder = { viewHolder, position -> viewHolder.bind(_videos[position], false); },
|
||||
childViewHolderBinder = { viewHolder, position ->
|
||||
viewHolder.bind(
|
||||
_videos[position],
|
||||
false
|
||||
)
|
||||
},
|
||||
childViewHolderFactory = { viewGroup, _ ->
|
||||
val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.list_playlist, viewGroup, false);
|
||||
val holder = VideoListEditorViewHolder(view, null);
|
||||
val view = LayoutInflater.from(viewGroup.context)
|
||||
.inflate(R.layout.list_playlist, viewGroup, false)
|
||||
val holder = VideoListEditorViewHolder(view, null)
|
||||
holder.onClick.subscribe {
|
||||
showConvertConfirmationModal();
|
||||
};
|
||||
return@InsertedViewAdapterWithLoader holder;
|
||||
}
|
||||
);
|
||||
convertPlaylist(false, Action.PLAY, holder.video)
|
||||
}
|
||||
return@InsertedViewAdapterWithLoader holder
|
||||
})
|
||||
|
||||
_recyclerPlaylist.adapter = _adapterVideos;
|
||||
_recyclerPlaylist.layoutManager = _llmPlaylist;
|
||||
|
@ -128,10 +141,10 @@ class RemotePlaylistFragment : MainFragment() {
|
|||
};
|
||||
|
||||
buttonPlayAll.setOnClickListener {
|
||||
showConvertConfirmationModal();
|
||||
convertPlaylist(false, Action.PLAY_ALL);
|
||||
};
|
||||
buttonShuffle.setOnClickListener {
|
||||
showConvertConfirmationModal();
|
||||
convertPlaylist(false, Action.SHUFFLE);
|
||||
};
|
||||
|
||||
_taskLoadPlaylist = TaskHandler<String, IPlatformPlaylistDetails>(
|
||||
|
@ -253,48 +266,76 @@ class RemotePlaylistFragment : MainFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun showConvertConfirmationModal() {
|
||||
val remotePlaylist = _remotePlaylist;
|
||||
private fun convertPlaylist(
|
||||
savePlaylist: Boolean, action: Action, video: IPlatformVideo? = null
|
||||
) {
|
||||
val remotePlaylist = _remotePlaylist
|
||||
if (remotePlaylist == null) {
|
||||
UIDialogs.toast(context.getString(R.string.please_wait_for_playlist_to_finish_loading));
|
||||
return;
|
||||
UIDialogs.toast(context.getString(R.string.please_wait_for_playlist_to_finish_loading))
|
||||
return
|
||||
}
|
||||
|
||||
val c = context ?: return;
|
||||
UIDialogs.showConfirmationDialog(c, "Conversion to local playlist is required for this action", {
|
||||
setLoading(true);
|
||||
val convert = {
|
||||
setLoading(true)
|
||||
|
||||
UIDialogs.showDialogProgress(context) {
|
||||
it.setText("Converting playlist..");
|
||||
it.setProgress(0f);
|
||||
it.setText("Converting playlist..")
|
||||
it.setProgress(0f)
|
||||
|
||||
_fragment.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val playlist = remotePlaylist.toPlaylist() { progress ->
|
||||
val playlist = remotePlaylist.toPlaylist { progress ->
|
||||
_fragment.lifecycleScope.launch(Dispatchers.Main) {
|
||||
it.setProgress(progress.toDouble() / remotePlaylist.videoCount);
|
||||
it.setProgress(progress.toDouble() / remotePlaylist.videoCount)
|
||||
}
|
||||
};
|
||||
|
||||
StatePlaylists.instance.playlistStore.save(playlist);
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
UIDialogs.toast("Playlist converted");
|
||||
it.dismiss();
|
||||
_fragment.navigate<PlaylistFragment>(playlist);
|
||||
}
|
||||
}
|
||||
catch(ex: Throwable) {
|
||||
UIDialogs.appToast("Failed to convert playlist.\n" + ex.message);
|
||||
|
||||
if (savePlaylist) {
|
||||
StatePlaylists.instance.playlistStore.save(playlist)
|
||||
}
|
||||
|
||||
_fragment.lifecycleScope.launch(Dispatchers.Main) {
|
||||
UIDialogs.toast("Playlist converted")
|
||||
it.dismiss()
|
||||
_fragment.navigate<PlaylistFragment>(playlist)
|
||||
when (action) {
|
||||
Action.SHUFFLE -> StatePlayer.instance.setPlaylist(
|
||||
playlist, focus = true, shuffle = true
|
||||
)
|
||||
|
||||
Action.PLAY_ALL -> StatePlayer.instance.setPlaylist(
|
||||
playlist, focus = true
|
||||
)
|
||||
|
||||
Action.PLAY -> {
|
||||
StatePlayer.instance.setPlaylist(
|
||||
playlist, _videos.indexOf(video), true
|
||||
)
|
||||
}
|
||||
|
||||
Action.NONE -> {}
|
||||
}
|
||||
}
|
||||
} catch (ex: Throwable) {
|
||||
UIDialogs.appToast("Failed to convert playlist.\n" + ex.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (remotePlaylist.videoCount > 100) {
|
||||
val c = context ?: return
|
||||
UIDialogs.showConfirmationDialog(
|
||||
c, "Conversion to local playlist is required for this action", convert
|
||||
)
|
||||
} else {
|
||||
convert()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showConvertPlaylistButton() {
|
||||
_fragment.topBar?.assume<NavigationTopBarFragment>()?.setMenuItems(arrayListOf(Pair(R.drawable.ic_copy) {
|
||||
showConvertConfirmationModal();
|
||||
convertPlaylist(true, Action.NONE);
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue