mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-07 18:10:31 +05:30
add option for it
This commit is contained in:
parent
610121dd90
commit
0786e8f87c
@ -80,6 +80,7 @@ object PreferenceKeys {
|
|||||||
const val SB_SHOW_MARKERS = "sb_show_markers"
|
const val SB_SHOW_MARKERS = "sb_show_markers"
|
||||||
const val LIMIT_HLS = "limit_hls"
|
const val LIMIT_HLS = "limit_hls"
|
||||||
const val PROGRESSIVE_LOADING_INTERVAL_SIZE = "progressive_loading_interval"
|
const val PROGRESSIVE_LOADING_INTERVAL_SIZE = "progressive_loading_interval"
|
||||||
|
const val ALTERNATIVE_PLAYER_LAYOUT = "alternative_player_layout"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Background mode
|
* Background mode
|
||||||
|
@ -307,9 +307,9 @@ class BackgroundMode : Service() {
|
|||||||
*/
|
*/
|
||||||
private fun fetchSponsorBlockSegments() {
|
private fun fetchSponsorBlockSegments() {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
kotlin.runCatching {
|
runCatching {
|
||||||
val categories = PlayerHelper.getSponsorBlockCategories()
|
val categories = PlayerHelper.getSponsorBlockCategories()
|
||||||
if (categories.size > 0) {
|
if (categories.isEmpty()) return@runCatching
|
||||||
segmentData =
|
segmentData =
|
||||||
RetrofitInstance.api.getSegments(
|
RetrofitInstance.api.getSegments(
|
||||||
videoId,
|
videoId,
|
||||||
@ -319,7 +319,6 @@ class BackgroundMode : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check for SponsorBlock segments
|
* check for SponsorBlock segments
|
||||||
|
@ -27,6 +27,7 @@ import android.widget.Toast
|
|||||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
|
import androidx.core.view.isEmpty
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
@ -38,6 +39,7 @@ import com.github.libretube.api.CronetHelper
|
|||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
import com.github.libretube.api.obj.ChapterSegment
|
import com.github.libretube.api.obj.ChapterSegment
|
||||||
import com.github.libretube.api.obj.SegmentData
|
import com.github.libretube.api.obj.SegmentData
|
||||||
|
import com.github.libretube.api.obj.StreamItem
|
||||||
import com.github.libretube.api.obj.Streams
|
import com.github.libretube.api.obj.Streams
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
@ -134,7 +136,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
* for the comments
|
* for the comments
|
||||||
*/
|
*/
|
||||||
private var commentsAdapter: CommentsAdapter? = null
|
private var commentsAdapter: CommentsAdapter? = null
|
||||||
private var commentsLoaded: Boolean? = false
|
|
||||||
private var nextPage: String? = null
|
private var nextPage: String? = null
|
||||||
private var isLoading = true
|
private var isLoading = true
|
||||||
|
|
||||||
@ -457,11 +458,14 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleComments() {
|
private fun toggleComments() {
|
||||||
binding.commentsRecView.visibility =
|
if (binding.commentsRecView.isVisible) {
|
||||||
if (binding.commentsRecView.isVisible) View.GONE else View.VISIBLE
|
binding.commentsRecView.visibility = View.GONE
|
||||||
binding.relatedRecView.visibility =
|
binding.relatedRecView.visibility = View.VISIBLE
|
||||||
if (binding.relatedRecView.isVisible) View.GONE else View.VISIBLE
|
} else {
|
||||||
if (!commentsLoaded!!) fetchComments()
|
binding.commentsRecView.visibility = View.VISIBLE
|
||||||
|
binding.relatedRecView.visibility = View.GONE
|
||||||
|
if (binding.commentsRecView.isEmpty()) fetchComments()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@ -617,15 +621,13 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
// show the player notification
|
// show the player notification
|
||||||
initializePlayerNotification()
|
initializePlayerNotification()
|
||||||
if (PlayerHelper.sponsorBlockEnabled) fetchSponsorBlockSegments()
|
if (PlayerHelper.sponsorBlockEnabled) fetchSponsorBlockSegments()
|
||||||
// show comments if related streams disabled
|
|
||||||
if (!PlayerHelper.relatedStreamsEnabled) toggleComments()
|
// show comments if related streams are disabled or the alternative related streams layout is chosen
|
||||||
|
if (!PlayerHelper.relatedStreamsEnabled || PlayerHelper.alternativeVideoLayout) toggleComments()
|
||||||
|
|
||||||
// add the video to the watch history
|
// add the video to the watch history
|
||||||
if (PlayerHelper.watchHistoryEnabled) {
|
if (PlayerHelper.watchHistoryEnabled) {
|
||||||
DatabaseHelper.addToWatchHistory(
|
DatabaseHelper.addToWatchHistory(videoId!!, streams)
|
||||||
videoId!!,
|
|
||||||
streams
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -636,9 +638,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
*/
|
*/
|
||||||
private fun fetchSponsorBlockSegments() {
|
private fun fetchSponsorBlockSegments() {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
kotlin.runCatching {
|
runCatching {
|
||||||
val categories = PlayerHelper.getSponsorBlockCategories()
|
val categories = PlayerHelper.getSponsorBlockCategories()
|
||||||
if (categories.size > 0) {
|
if (categories.isEmpty()) return@runCatching
|
||||||
segmentData =
|
segmentData =
|
||||||
RetrofitInstance.api.getSegments(
|
RetrofitInstance.api.getSegments(
|
||||||
videoId!!,
|
videoId!!,
|
||||||
@ -648,7 +650,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
private fun refreshLiveStatus() {
|
private fun refreshLiveStatus() {
|
||||||
@ -706,7 +707,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
videoId = nextVideoId
|
videoId = nextVideoId
|
||||||
|
|
||||||
// forces the comments to reload for the new video
|
// forces the comments to reload for the new video
|
||||||
commentsLoaded = false
|
|
||||||
binding.commentsRecView.adapter = null
|
binding.commentsRecView.adapter = null
|
||||||
playVideo()
|
playVideo()
|
||||||
}
|
}
|
||||||
@ -749,7 +749,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
private fun initializePlayerView(response: com.github.libretube.api.obj.Streams) {
|
private fun initializePlayerView(response: Streams) {
|
||||||
// initialize the player view actions
|
// initialize the player view actions
|
||||||
binding.player.initialize(
|
binding.player.initialize(
|
||||||
childFragmentManager,
|
childFragmentManager,
|
||||||
@ -898,19 +898,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PlayerHelper.relatedStreamsEnabled) {
|
initializeRelatedVideos(response.relatedStreams)
|
||||||
// only show related streams if enabled
|
|
||||||
binding.relatedRecView.adapter = VideosAdapter(
|
|
||||||
response.relatedStreams.orEmpty().toMutableList(),
|
|
||||||
childFragmentManager
|
|
||||||
)
|
|
||||||
|
|
||||||
binding.alternativeTrendingRec.adapter = VideosAdapter(
|
|
||||||
response.relatedStreams.orEmpty().toMutableList(),
|
|
||||||
childFragmentManager,
|
|
||||||
forceMode = VideosAdapter.Companion.ForceMode.RELATED
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// set video description
|
// set video description
|
||||||
val description = response.description!!
|
val description = response.description!!
|
||||||
binding.playerDescription.text =
|
binding.playerDescription.text =
|
||||||
@ -973,6 +961,23 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initializeRelatedVideos(relatedStreams: List<StreamItem>?) {
|
||||||
|
if (!PlayerHelper.relatedStreamsEnabled) return
|
||||||
|
|
||||||
|
if (PlayerHelper.alternativeVideoLayout) {
|
||||||
|
binding.alternativeTrendingRec.adapter = VideosAdapter(
|
||||||
|
relatedStreams.orEmpty().toMutableList(),
|
||||||
|
childFragmentManager,
|
||||||
|
forceMode = VideosAdapter.Companion.ForceMode.RELATED
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
binding.relatedRecView.adapter = VideosAdapter(
|
||||||
|
relatedStreams.orEmpty().toMutableList(),
|
||||||
|
childFragmentManager
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun initializeChapters() {
|
private fun initializeChapters() {
|
||||||
if (chapters.isEmpty()) {
|
if (chapters.isEmpty()) {
|
||||||
binding.chaptersRecView.visibility = View.GONE
|
binding.chaptersRecView.visibility = View.GONE
|
||||||
@ -1171,7 +1176,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setStreamSource(
|
private fun setStreamSource(
|
||||||
streams: com.github.libretube.api.obj.Streams,
|
streams: Streams,
|
||||||
videosNameArray: Array<String>,
|
videosNameArray: Array<String>,
|
||||||
videosUrlArray: Array<Uri>
|
videosUrlArray: Array<Uri>
|
||||||
) {
|
) {
|
||||||
@ -1282,7 +1287,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
commentsAdapter = CommentsAdapter(videoId!!, commentsResponse.comments)
|
commentsAdapter = CommentsAdapter(videoId!!, commentsResponse.comments)
|
||||||
binding.commentsRecView.adapter = commentsAdapter
|
binding.commentsRecView.adapter = commentsAdapter
|
||||||
nextPage = commentsResponse.nextpage
|
nextPage = commentsResponse.nextpage
|
||||||
commentsLoaded = true
|
|
||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,6 +287,12 @@ object PlayerHelper {
|
|||||||
"fit"
|
"fit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val alternativeVideoLayout: Boolean
|
||||||
|
get() = PreferenceHelper.getBoolean(
|
||||||
|
PreferenceKeys.ALTERNATIVE_PLAYER_LAYOUT,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
fun getDefaultResolution(context: Context): String {
|
fun getDefaultResolution(context: Context): String {
|
||||||
return if (NetworkHelper.isNetworkMobile(context)) {
|
return if (NetworkHelper.isNetworkMobile(context)) {
|
||||||
PreferenceHelper.getString(
|
PreferenceHelper.getString(
|
||||||
|
@ -303,8 +303,7 @@
|
|||||||
android:id="@+id/alternativeTrendingRec"
|
android:id="@+id/alternativeTrendingRec"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="15dp"
|
android:layout_marginHorizontal="12dp" />
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
<com.google.android.material.card.MaterialCardView
|
||||||
android:id="@+id/comments_toggle"
|
android:id="@+id/comments_toggle"
|
||||||
|
@ -368,6 +368,8 @@
|
|||||||
<string name="alternative_trending_layout">Alternative trending layout</string>
|
<string name="alternative_trending_layout">Alternative trending layout</string>
|
||||||
<string name="navbar_order">Order</string>
|
<string name="navbar_order">Order</string>
|
||||||
<string name="layout">Layout</string>
|
<string name="layout">Layout</string>
|
||||||
|
<string name="alternative_player_layout">Alternative player layout</string>
|
||||||
|
<string name="alternative_player_layout_summary">Show the related videos as a row above the comments instead of below.</string>
|
||||||
|
|
||||||
<!-- Notification channel strings -->
|
<!-- Notification channel strings -->
|
||||||
<string name="download_channel_name">Download Service</string>
|
<string name="download_channel_name">Download Service</string>
|
||||||
|
@ -81,6 +81,13 @@
|
|||||||
app:key="alternative_videos_layout"
|
app:key="alternative_videos_layout"
|
||||||
app:title="@string/alternative_videos_layout" />
|
app:title="@string/alternative_videos_layout" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:icon="@drawable/ic_list"
|
||||||
|
app:defaultValue="false"
|
||||||
|
app:key="alternative_player_layout"
|
||||||
|
app:summary="@string/alternative_player_layout_summary"
|
||||||
|
app:title="@string/alternative_player_layout" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:icon="@drawable/ic_grid"
|
android:icon="@drawable/ic_grid"
|
||||||
app:defaultValue="@integer/grid_items"
|
app:defaultValue="@integer/grid_items"
|
||||||
|
Loading…
Reference in New Issue
Block a user