Commit a456cfbe authored by Geoffrey Métais's avatar Geoffrey Métais

TV: Play all by default

parent 4d5f1cf8
Pipeline #4451 passed with stage
in 3 minutes and 47 seconds
......@@ -27,4 +27,9 @@ val LifecycleOwner.coroutineScope: CoroutineScope
lifecycleCoroutineScopes[lifecycle] = newScope
it.invokeOnCompletion { lifecycleCoroutineScopes -= lifecycle }
newScope
}
\ No newline at end of file
}
fun <T> List<T>.getposition(target: T) : Int {
for ((index, item) in this.withIndex()) if (item == target) return index
return -1
}
\ No newline at end of file
......@@ -58,7 +58,6 @@ import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity
import org.videolan.vlc.gui.tv.browser.VerticalGridActivity
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.repository.DirectoryRepository
import org.videolan.vlc.repository.createDirectory
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.HistoryModel
import org.videolan.vlc.viewmodels.VideosModel
......@@ -173,7 +172,6 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val browsePath = activity?.intent?.getStringExtra(EXTRA_PATH) ?: return
TvUtil.openMedia(requireActivity(), createDirectory(browsePath, requireContext()), null)
}
fun updateAudioCategories(current: DummyItem? = null) {
......@@ -262,7 +260,12 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
ID_LICENCE -> startActivity(Intent(activity, org.videolan.vlc.gui.tv.LicenceActivity::class.java))
}
}
else -> TvUtil.openMedia(activity, item, row)
else -> {
val model = if (row?.id == HEADER_HISTORY && this::historyModel.isInitialized) historyModel
else if (row?.id == HEADER_VIDEO && this::videoModel.isInitialized) videoModel
else null
TvUtil.openMedia(activity, item, model)
}
}
}
......
/*****************************************************************************
* MediaItemDetailsFragment.java
*****************************************************************************
* Copyright © 2014-2015 VLC authors, VideoLAN and VideoLabs
* Copyright © 2014-2019 VLC authors, VideoLAN and VideoLabs
* Author: Geoffrey Métais
*
* This program is free software; you can redistribute it and/or modify
......@@ -37,15 +37,12 @@ import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.repository.BrowserFavRepository;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.WorkersKt;
import java.util.List;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.leanback.app.BackgroundManager;
......@@ -70,8 +67,7 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment {
private static final int ID_FAVORITE_DELETE = 4;
private static final int ID_BROWSE = 5;
private static final int ID_DL_SUBS = 6;
private static final int ID_PLAY_ALL = 7;
private static final int ID_PLAY_FROM_START = 8;
private static final int ID_PLAY_FROM_START = 7;
private BackgroundManager mBackgroundManager;
private ArrayObjectAdapter mRowsAdapter;
......@@ -121,7 +117,6 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment {
mMediaWrapper = media;
setTitle(media.getTitle());
final List<MediaWrapper> mediaList = null;
// Attach your media item details presenter to the row presenter:
FullWidthDetailsOverviewRowPresenter rowPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
......@@ -173,19 +168,6 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment {
case ID_DL_SUBS:
MediaUtils.INSTANCE.getSubs(requireActivity(), media);
break;
case ID_PLAY_ALL:
if (mediaList != null) {
int position = -1;
for (int i= 0; i < mediaList.size(); ++i)
if (media.equals(mediaList.get(i)))
position = i;
Activity activity = getActivity();
MediaUtils.INSTANCE.openList(activity, mediaList, position);
if (media.getType() == MediaWrapper.TYPE_AUDIO)
getActivity().startActivity(new Intent(activity, AudioPlayerActivity.class));
getActivity().finish();
}
break;
case ID_PLAY_FROM_START:
mMediaStarted = false;
VideoPlayerActivity.start(getActivity(), media.getUri(), true);
......@@ -231,8 +213,6 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment {
detailsOverview.addAction(new Action(ID_PLAY, res.getString(R.string.play)));
detailsOverview.addAction(new Action(ID_LISTEN, res.getString(R.string.listen)));
if (mediaList != null && mediaList.contains(media))
detailsOverview.addAction(new Action(ID_PLAY_ALL, res.getString(R.string.play_all)));
} else if (media.getType() == MediaWrapper.TYPE_VIDEO) {
// Add images and action buttons to the details view
if (cover == null)
......@@ -244,8 +224,6 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment {
detailsOverview.addAction(new Action(ID_PLAY_FROM_START, res.getString(R.string.play_from_start)));
if (FileUtils.canWrite(media.getUri()))
detailsOverview.addAction(new Action(ID_DL_SUBS, res.getString(R.string.download_subtitles)));
if (mediaList != null && mediaList.contains(media))
detailsOverview.addAction(new Action(ID_PLAY_ALL, res.getString(R.string.play_all)));
}
mRowsAdapter.add(detailsOverview);
setAdapter(mRowsAdapter);
......
......@@ -48,7 +48,7 @@ class SearchFragment : SearchSupportFragment(), SearchSupportFragment.SearchResu
private val rowsAdapter = ArrayObjectAdapter(ListRowPresenter())
private val defaultItemClickedListener: OnItemViewClickedListener
get() = OnItemViewClickedListener { _, item, _, row ->
if (item is MediaWrapper) TvUtil.openMedia(requireActivity(), item, row)
if (item is MediaWrapper) TvUtil.openMedia(requireActivity(), item, null)
else TvUtil.openAudioCategory(requireActivity(), item as MediaLibraryItem)
requireActivity().finish()
}
......
......@@ -36,13 +36,11 @@ import androidx.fragment.app.FragmentActivity
import androidx.leanback.app.BackgroundManager
import androidx.leanback.widget.DiffCallback
import androidx.leanback.widget.ListRow
import androidx.leanback.widget.Row
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.*
import org.videolan.medialibrary.media.DummyItem
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.tools.getposition
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.DialogActivity
......@@ -53,9 +51,12 @@ import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity
import org.videolan.vlc.gui.tv.browser.VerticalGridActivity
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.BaseModel
import java.util.*
import kotlin.collections.ArrayList
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
object TvUtil {
......@@ -108,10 +109,15 @@ object TvUtil {
MediaUtils.openMedia(activity, media)
}
fun openMedia(activity: FragmentActivity, item: Any?, row: Row?) {
@Suppress("UNCHECKED_CAST")
fun openMedia(activity: FragmentActivity, item: Any?, model: BaseModel<out MediaLibraryItem>?) {
when (item) {
is MediaWrapper -> when {
item.type == MediaWrapper.TYPE_AUDIO -> openAudioCategory(activity, item)
item.type == MediaWrapper.TYPE_AUDIO -> {
val list = (model!!.dataset.value as List<MediaWrapper>).filter { it.type != MediaWrapper.TYPE_DIR } as ArrayList<MediaWrapper>
val position = list.getposition(item)
playAudioList(activity, list, position)
}
item.type == MediaWrapper.TYPE_DIR -> {
val intent = Intent(activity, VerticalGridActivity::class.java)
intent.putExtra(MainTvActivity.BROWSER_TYPE, if ("file" == item.uri.scheme) HEADER_DIRECTORIES else HEADER_NETWORK)
......@@ -125,7 +131,11 @@ object TvUtil {
intent.putExtra(KEY_GROUP, title)
activity.startActivity(intent)
}
else -> MediaUtils.openMedia(activity, item)
else -> {
val list = (model!!.dataset.value as List<MediaWrapper>).filter { it.type != MediaWrapper.TYPE_DIR }
val position = list.getposition(item)
MediaUtils.openList(activity, list, position)
}
}
is DummyItem -> when {
item.id == HEADER_STREAM -> activity.startActivity(Intent(activity, DialogActivity::class.java).setAction(DialogActivity.KEY_STREAM)
......
......@@ -109,6 +109,6 @@ public class BrowserGridFragment extends GridFragment implements OnItemViewSelec
if (media.getType() == MediaWrapper.TYPE_DIR)
TvUtil.INSTANCE.browseFolder(requireActivity(), Constants.HEADER_NETWORK, ((MediaWrapper) item).getUri());
else
TvUtil.INSTANCE.openMedia(requireActivity(), item, null);
TvUtil.INSTANCE.openMedia(requireActivity(), item, provider);
}
}
......@@ -95,7 +95,7 @@ open class CategoriesFragment<T : BaseModel<out MediaLibraryItem>> : BrowseSuppo
override fun onItemClicked(viewHolder: Presenter.ViewHolder, item: Any, viewHolder1: RowPresenter.ViewHolder, row: Row) {
val media = item as MediaWrapper
if (media.type == MediaWrapper.TYPE_DIR) TvUtil.browseFolder(requireActivity(), getCategoryId(), item.uri)
else TvUtil.openMedia(requireActivity(), item, null)
else TvUtil.openMedia(requireActivity(), item, viewModel)
}
override fun refresh() {
......
......@@ -93,7 +93,7 @@ abstract class MediaLibBrowserFragment<T : BaseModel<out MediaLibraryItem>> : Gr
override fun onItemClicked(itemViewHolder: Presenter.ViewHolder?, item: Any?,
rowViewHolder: RowPresenter.ViewHolder?, row: Row?) {
TvUtil.openMedia(mContext, item, row)
TvUtil.openMedia(mContext, item, model)
}
override fun getVM(): BaseModel<out MediaLibraryItem> = this.model
......
......@@ -25,11 +25,12 @@ package org.videolan.vlc.gui.tv.preferences;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import androidx.preference.Preference;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
import androidx.preference.Preference;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class PreferencesVideo extends BasePreferenceFragment {
......@@ -53,11 +54,7 @@ public class PreferencesVideo extends BasePreferenceFragment {
findPreference("enable_volume_gesture").setVisible(AndroidDevices.hasTsp);
findPreference("enable_brightness_gesture").setVisible(AndroidDevices.hasTsp);
findPreference("popup_keepscreen").setVisible(false);
}
@Override
public void onStart() {
super.onStart();
findPreference("force_play_all").setVisible(false);
}
@Override
......
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