mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30:31 +05:30
commit
1aaf674cc1
@ -78,7 +78,7 @@ class VideoOptionsBottomSheet(
|
|||||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||||
}
|
}
|
||||||
context?.getString(R.string.play_next) -> {
|
context?.getString(R.string.play_next) -> {
|
||||||
PlayingQueue.playNext(videoId)
|
PlayingQueue.addAsNext(videoId)
|
||||||
}
|
}
|
||||||
context?.getString(R.string.add_to_queue) -> {
|
context?.getString(R.string.add_to_queue) -> {
|
||||||
PlayingQueue.add(videoId)
|
PlayingQueue.add(videoId)
|
||||||
|
@ -35,16 +35,6 @@ class BottomSheetAdapter(
|
|||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
listener.invoke(position)
|
listener.invoke(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
// increase padding if there's no drawable
|
|
||||||
if (item.drawable == null) {
|
|
||||||
root.setPadding(
|
|
||||||
root.paddingLeft * 2,
|
|
||||||
root.paddingTop,
|
|
||||||
root.paddingRight,
|
|
||||||
root.paddingBottom
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,9 @@ class DownloadDialog(
|
|||||||
|
|
||||||
binding.audioRadio.setOnClickListener {
|
binding.audioRadio.setOnClickListener {
|
||||||
binding.videoSpinner.visibility = View.GONE
|
binding.videoSpinner.visibility = View.GONE
|
||||||
binding.audioSpinner.visibility = View.VISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.videoRadio.setOnClickListener {
|
binding.videoRadio.setOnClickListener {
|
||||||
binding.audioSpinner.visibility = View.GONE
|
|
||||||
binding.videoSpinner.visibility = View.VISIBLE
|
binding.videoSpinner.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
@ -78,6 +77,7 @@ import com.google.android.exoplayer2.ExoPlayer
|
|||||||
import com.google.android.exoplayer2.MediaItem
|
import com.google.android.exoplayer2.MediaItem
|
||||||
import com.google.android.exoplayer2.MediaItem.SubtitleConfiguration
|
import com.google.android.exoplayer2.MediaItem.SubtitleConfiguration
|
||||||
import com.google.android.exoplayer2.MediaItem.fromUri
|
import com.google.android.exoplayer2.MediaItem.fromUri
|
||||||
|
import com.google.android.exoplayer2.PlaybackException
|
||||||
import com.google.android.exoplayer2.Player
|
import com.google.android.exoplayer2.Player
|
||||||
import com.google.android.exoplayer2.audio.AudioAttributes
|
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||||
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
|
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
|
||||||
@ -91,7 +91,6 @@ import com.google.android.exoplayer2.ui.StyledPlayerView
|
|||||||
import com.google.android.exoplayer2.upstream.DataSource
|
import com.google.android.exoplayer2.upstream.DataSource
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSource
|
import com.google.android.exoplayer2.upstream.DefaultDataSource
|
||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
|
||||||
import com.google.android.exoplayer2.video.VideoSize
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -971,22 +970,6 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onVideoSizeChanged(
|
|
||||||
videoSize: VideoSize
|
|
||||||
) {
|
|
||||||
// Set new width/height of view
|
|
||||||
// height or width must be cast to float as int/int will give 0
|
|
||||||
|
|
||||||
// Redraw the player container with the new layout height
|
|
||||||
val params = binding.player.layoutParams
|
|
||||||
params.height = videoSize.height / videoSize.width * params.width
|
|
||||||
binding.player.layoutParams = params
|
|
||||||
binding.player.requestLayout()
|
|
||||||
(binding.mainContainer.layoutParams as ConstraintLayout.LayoutParams).apply {
|
|
||||||
matchConstraintPercentHeight = (videoSize.height / videoSize.width).toFloat()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
exoPlayerView.keepScreenOn = !(
|
exoPlayerView.keepScreenOn = !(
|
||||||
playbackState == Player.STATE_IDLE ||
|
playbackState == Player.STATE_IDLE ||
|
||||||
@ -1032,6 +1015,18 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
super.onPlaybackStateChanged(playbackState)
|
super.onPlaybackStateChanged(playbackState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Catch player errors to prevent the app from stopping
|
||||||
|
*/
|
||||||
|
override fun onPlayerError(error: PlaybackException) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
error.localizedMessage,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
super.onPlayerError(error)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// check if livestream
|
// check if livestream
|
||||||
|
@ -36,7 +36,10 @@ open class MaterialPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
preference.callChangeListener(newValue)
|
preference.callChangeListener(newValue)
|
||||||
|
|
||||||
// invoke the on change listeners
|
// invoke the on change listeners
|
||||||
preference.callChangeListener(preference.value)
|
if (preference.callChangeListener(newValue)) {
|
||||||
|
preference.value = newValue
|
||||||
|
}
|
||||||
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
@ -52,14 +55,13 @@ open class MaterialPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(preference.title)
|
.setTitle(preference.title)
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
.setPositiveButton(R.string.okay) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
// save the new value
|
val newValue = binding.input.text.toString()
|
||||||
preference.text = binding.input.text.toString()
|
if (preference.callChangeListener(newValue)) {
|
||||||
|
preference.text = newValue
|
||||||
// invoke the on change listeners
|
}
|
||||||
preference.callChangeListener(preference.text)
|
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +40,7 @@ class AutoPlayHelper(
|
|||||||
if (relatedStreams == null || relatedStreams.isEmpty()) return null
|
if (relatedStreams == null || relatedStreams.isEmpty()) return null
|
||||||
var index = 0
|
var index = 0
|
||||||
var nextStreamId: String? = null
|
var nextStreamId: String? = null
|
||||||
while (nextStreamId == null || PlayingQueue.containsBefore(nextStreamId)) {
|
while (nextStreamId == null || PlayingQueue.containsBeforeCurrent(nextStreamId)) {
|
||||||
nextStreamId = relatedStreams[index].url!!.toID()
|
nextStreamId = relatedStreams[index].url!!.toID()
|
||||||
if (index + 1 < relatedStreams.size) {
|
if (index + 1 < relatedStreams.size) {
|
||||||
index += 1
|
index += 1
|
||||||
|
@ -58,7 +58,7 @@ object NavBarHelper {
|
|||||||
*/
|
*/
|
||||||
fun applyNavBarStyle(bottomNav: BottomNavigationView): Int {
|
fun applyNavBarStyle(bottomNav: BottomNavigationView): Int {
|
||||||
val labelVisibilityMode = when (
|
val labelVisibilityMode = when (
|
||||||
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "always")
|
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "selected")
|
||||||
) {
|
) {
|
||||||
"always" -> NavigationBarView.LABEL_VISIBILITY_LABELED
|
"always" -> NavigationBarView.LABEL_VISIBILITY_LABELED
|
||||||
"selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED
|
"selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED
|
||||||
|
@ -4,17 +4,13 @@ object PlayingQueue {
|
|||||||
private val queue = mutableListOf<String>()
|
private val queue = mutableListOf<String>()
|
||||||
private var currentVideoId: String? = null
|
private var currentVideoId: String? = null
|
||||||
|
|
||||||
fun clear() {
|
|
||||||
queue.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun add(videoId: String) {
|
fun add(videoId: String) {
|
||||||
if (currentVideoId == videoId) return
|
if (currentVideoId == videoId) return
|
||||||
if (queue.contains(videoId)) queue.remove(videoId)
|
if (queue.contains(videoId)) queue.remove(videoId)
|
||||||
queue.add(videoId)
|
queue.add(videoId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playNext(videoId: String) {
|
fun addAsNext(videoId: String) {
|
||||||
if (currentVideoId == videoId) return
|
if (currentVideoId == videoId) return
|
||||||
if (queue.contains(videoId)) queue.remove(videoId)
|
if (queue.contains(videoId)) queue.remove(videoId)
|
||||||
queue.add(
|
queue.add(
|
||||||
@ -24,11 +20,10 @@ object PlayingQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getNext(): String? {
|
fun getNext(): String? {
|
||||||
val currentIndex = queue.indexOf(currentVideoId)
|
return try {
|
||||||
return if (currentIndex >= queue.size) {
|
queue[currentIndex() + 1]
|
||||||
|
} catch (e: Exception) {
|
||||||
null
|
null
|
||||||
} else {
|
|
||||||
queue[currentIndex + 1]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,18 +36,20 @@ object PlayingQueue {
|
|||||||
return queue.indexOf(currentVideoId) > 0
|
return queue.indexOf(currentVideoId) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun contains(videoId: String): Boolean {
|
|
||||||
return queue.contains(videoId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun containsBefore(videoId: String): Boolean {
|
|
||||||
return queue.contains(videoId) && queue.indexOf(videoId) < queue.indexOf(currentVideoId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateCurrent(videoId: String) {
|
fun updateCurrent(videoId: String) {
|
||||||
currentVideoId = videoId
|
currentVideoId = videoId
|
||||||
queue.add(videoId)
|
queue.add(videoId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isNotEmpty() = queue.isNotEmpty()
|
fun isNotEmpty() = queue.isNotEmpty()
|
||||||
|
|
||||||
|
fun clear() = queue.clear()
|
||||||
|
|
||||||
|
fun currentIndex() = queue.indexOf(currentVideoId)
|
||||||
|
|
||||||
|
fun contains(videoId: String) = queue.contains(videoId)
|
||||||
|
|
||||||
|
fun containsBeforeCurrent(videoId: String): Boolean {
|
||||||
|
return queue.contains(videoId) && queue.indexOf(videoId) < currentIndex()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
style="@style/Widget.Material3.BottomSheet"
|
style="@style/Widget.Material3.BottomSheet"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:paddingBottom="10dp"
|
android:paddingBottom="20dp"
|
||||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -5,19 +5,22 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="10dp">
|
android:paddingHorizontal="30dp"
|
||||||
|
android:paddingVertical="12dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/drawable"
|
android:id="@+id/drawable"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="24dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="24dp"
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginEnd="25dp"
|
||||||
tools:src="@drawable/ic_download" />
|
tools:src="@drawable/ic_download" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
tools:text="Option" />
|
tools:text="Option" />
|
||||||
|
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:paddingHorizontal="20dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
@ -16,7 +17,6 @@
|
|||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="10dp"
|
|
||||||
android:checkedButton="@id/video_radio"
|
android:checkedButton="@id/video_radio"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
@ -30,7 +30,7 @@
|
|||||||
android:id="@+id/audio_radio"
|
android:id="@+id/audio_radio"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="20dp"
|
||||||
android:text="@string/audio" />
|
android:text="@string/audio" />
|
||||||
|
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
@ -39,19 +39,20 @@
|
|||||||
android:id="@+id/video_spinner"
|
android:id="@+id/video_spinner"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp" />
|
android:layout_marginVertical="10dp" />
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/audio_spinner"
|
android:id="@+id/audio_spinner"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
android:layout_marginVertical="10dp" />
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/download"
|
android:id="@+id/download"
|
||||||
style="@style/CustomDialogButton"
|
style="@style/CustomDialogButton"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginBottom="15dp"
|
||||||
android:text="@string/download" />
|
android:text="@string/download" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -573,18 +573,6 @@
|
|||||||
<item>purple</item>
|
<item>purple</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="tabs">
|
|
||||||
<item>@string/startpage</item>
|
|
||||||
<item>@string/subscriptions</item>
|
|
||||||
<item>@string/library</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="tabsValue">
|
|
||||||
<item>home</item>
|
|
||||||
<item>subscriptions</item>
|
|
||||||
<item>library</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="defres">
|
<string-array name="defres">
|
||||||
<item>@string/hls</item>
|
<item>@string/hls</item>
|
||||||
<item>1080p</item>
|
<item>1080p</item>
|
||||||
@ -595,7 +583,7 @@
|
|||||||
<item>144p</item>
|
<item>144p</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="defresValue">
|
<string-array name="defresValue">
|
||||||
<item></item>
|
<item />
|
||||||
<item>1080p</item>
|
<item>1080p</item>
|
||||||
<item>720p</item>
|
<item>720p</item>
|
||||||
<item>480p</item>
|
<item>480p</item>
|
||||||
@ -693,14 +681,14 @@
|
|||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="labelVisibility">
|
<string-array name="labelVisibility">
|
||||||
<item>@string/always</item>
|
|
||||||
<item>@string/selected</item>
|
<item>@string/selected</item>
|
||||||
|
<item>@string/always</item>
|
||||||
<item>@string/never</item>
|
<item>@string/never</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="labelVisibilityValues">
|
<string-array name="labelVisibilityValues">
|
||||||
<item>always</item>
|
|
||||||
<item>selected</item>
|
<item>selected</item>
|
||||||
|
<item>always</item>
|
||||||
<item>never</item>
|
<item>never</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:icon="@drawable/ic_label"
|
android:icon="@drawable/ic_label"
|
||||||
app:defaultValue="always"
|
app:defaultValue="selected"
|
||||||
app:entries="@array/labelVisibility"
|
app:entries="@array/labelVisibility"
|
||||||
app:entryValues="@array/labelVisibilityValues"
|
app:entryValues="@array/labelVisibilityValues"
|
||||||
app:key="label_visibility"
|
app:key="label_visibility"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user