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