mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06: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 LIMIT_HLS = "limit_hls"
|
||||
const val PROGRESSIVE_LOADING_INTERVAL_SIZE = "progressive_loading_interval"
|
||||
const val ALTERNATIVE_PLAYER_LAYOUT = "alternative_player_layout"
|
||||
|
||||
/**
|
||||
* Background mode
|
||||
|
@ -307,16 +307,15 @@ class BackgroundMode : Service() {
|
||||
*/
|
||||
private fun fetchSponsorBlockSegments() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
kotlin.runCatching {
|
||||
runCatching {
|
||||
val categories = PlayerHelper.getSponsorBlockCategories()
|
||||
if (categories.size > 0) {
|
||||
segmentData =
|
||||
RetrofitInstance.api.getSegments(
|
||||
videoId,
|
||||
ObjectMapper().writeValueAsString(categories)
|
||||
)
|
||||
checkForSegments()
|
||||
}
|
||||
if (categories.isEmpty()) return@runCatching
|
||||
segmentData =
|
||||
RetrofitInstance.api.getSegments(
|
||||
videoId,
|
||||
ObjectMapper().writeValueAsString(categories)
|
||||
)
|
||||
checkForSegments()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import android.widget.Toast
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isEmpty
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
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.obj.ChapterSegment
|
||||
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.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
@ -134,7 +136,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
* for the comments
|
||||
*/
|
||||
private var commentsAdapter: CommentsAdapter? = null
|
||||
private var commentsLoaded: Boolean? = false
|
||||
private var nextPage: String? = null
|
||||
private var isLoading = true
|
||||
|
||||
@ -457,11 +458,14 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
private fun toggleComments() {
|
||||
binding.commentsRecView.visibility =
|
||||
if (binding.commentsRecView.isVisible) View.GONE else View.VISIBLE
|
||||
binding.relatedRecView.visibility =
|
||||
if (binding.relatedRecView.isVisible) View.GONE else View.VISIBLE
|
||||
if (!commentsLoaded!!) fetchComments()
|
||||
if (binding.commentsRecView.isVisible) {
|
||||
binding.commentsRecView.visibility = View.GONE
|
||||
binding.relatedRecView.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.commentsRecView.visibility = View.VISIBLE
|
||||
binding.relatedRecView.visibility = View.GONE
|
||||
if (binding.commentsRecView.isEmpty()) fetchComments()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
@ -617,15 +621,13 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
// show the player notification
|
||||
initializePlayerNotification()
|
||||
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
|
||||
if (PlayerHelper.watchHistoryEnabled) {
|
||||
DatabaseHelper.addToWatchHistory(
|
||||
videoId!!,
|
||||
streams
|
||||
)
|
||||
DatabaseHelper.addToWatchHistory(videoId!!, streams)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -636,16 +638,15 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
*/
|
||||
private fun fetchSponsorBlockSegments() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
kotlin.runCatching {
|
||||
runCatching {
|
||||
val categories = PlayerHelper.getSponsorBlockCategories()
|
||||
if (categories.size > 0) {
|
||||
segmentData =
|
||||
RetrofitInstance.api.getSegments(
|
||||
videoId!!,
|
||||
ObjectMapper().writeValueAsString(categories)
|
||||
)
|
||||
playerBinding.exoProgress.setSegments(segmentData.segments)
|
||||
}
|
||||
if (categories.isEmpty()) return@runCatching
|
||||
segmentData =
|
||||
RetrofitInstance.api.getSegments(
|
||||
videoId!!,
|
||||
ObjectMapper().writeValueAsString(categories)
|
||||
)
|
||||
playerBinding.exoProgress.setSegments(segmentData.segments)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -706,7 +707,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
videoId = nextVideoId
|
||||
|
||||
// forces the comments to reload for the new video
|
||||
commentsLoaded = false
|
||||
binding.commentsRecView.adapter = null
|
||||
playVideo()
|
||||
}
|
||||
@ -749,7 +749,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun initializePlayerView(response: com.github.libretube.api.obj.Streams) {
|
||||
private fun initializePlayerView(response: Streams) {
|
||||
// initialize the player view actions
|
||||
binding.player.initialize(
|
||||
childFragmentManager,
|
||||
@ -898,19 +898,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PlayerHelper.relatedStreamsEnabled) {
|
||||
// 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
|
||||
)
|
||||
}
|
||||
initializeRelatedVideos(response.relatedStreams)
|
||||
// set video description
|
||||
val description = response.description!!
|
||||
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() {
|
||||
if (chapters.isEmpty()) {
|
||||
binding.chaptersRecView.visibility = View.GONE
|
||||
@ -1171,7 +1176,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
private fun setStreamSource(
|
||||
streams: com.github.libretube.api.obj.Streams,
|
||||
streams: Streams,
|
||||
videosNameArray: Array<String>,
|
||||
videosUrlArray: Array<Uri>
|
||||
) {
|
||||
@ -1282,7 +1287,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
commentsAdapter = CommentsAdapter(videoId!!, commentsResponse.comments)
|
||||
binding.commentsRecView.adapter = commentsAdapter
|
||||
nextPage = commentsResponse.nextpage
|
||||
commentsLoaded = true
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
|
@ -287,6 +287,12 @@ object PlayerHelper {
|
||||
"fit"
|
||||
)
|
||||
|
||||
val alternativeVideoLayout: Boolean
|
||||
get() = PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.ALTERNATIVE_PLAYER_LAYOUT,
|
||||
false
|
||||
)
|
||||
|
||||
fun getDefaultResolution(context: Context): String {
|
||||
return if (NetworkHelper.isNetworkMobile(context)) {
|
||||
PreferenceHelper.getString(
|
||||
|
@ -303,8 +303,7 @@
|
||||
android:id="@+id/alternativeTrendingRec"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:visibility="gone" />
|
||||
android:layout_marginHorizontal="12dp" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/comments_toggle"
|
||||
|
@ -368,6 +368,8 @@
|
||||
<string name="alternative_trending_layout">Alternative trending layout</string>
|
||||
<string name="navbar_order">Order</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 -->
|
||||
<string name="download_channel_name">Download Service</string>
|
||||
|
@ -81,6 +81,13 @@
|
||||
app:key="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
|
||||
android:icon="@drawable/ic_grid"
|
||||
app:defaultValue="@integer/grid_items"
|
||||
|
Loading…
Reference in New Issue
Block a user