mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-26 23:10:32 +05:30
commit
1aaf674cc1
@ -78,7 +78,7 @@ class VideoOptionsBottomSheet(
|
||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
context?.getString(R.string.play_next) -> {
|
||||
PlayingQueue.playNext(videoId)
|
||||
PlayingQueue.addAsNext(videoId)
|
||||
}
|
||||
context?.getString(R.string.add_to_queue) -> {
|
||||
PlayingQueue.add(videoId)
|
||||
|
@ -35,16 +35,6 @@ class BottomSheetAdapter(
|
||||
root.setOnClickListener {
|
||||
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.videoSpinner.visibility = View.GONE
|
||||
binding.audioSpinner.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
binding.videoRadio.setOnClickListener {
|
||||
binding.audioSpinner.visibility = View.GONE
|
||||
binding.videoSpinner.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.bundleOf
|
||||
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.SubtitleConfiguration
|
||||
import com.google.android.exoplayer2.MediaItem.fromUri
|
||||
import com.google.android.exoplayer2.PlaybackException
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||
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.DefaultDataSource
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
|
||||
import com.google.android.exoplayer2.video.VideoSize
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
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) {
|
||||
exoPlayerView.keepScreenOn = !(
|
||||
playbackState == Player.STATE_IDLE ||
|
||||
@ -1032,6 +1015,18 @@ class PlayerFragment : BaseFragment() {
|
||||
}
|
||||
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
|
||||
|
@ -36,7 +36,10 @@ open class MaterialPreferenceFragment : PreferenceFragmentCompat() {
|
||||
preference.callChangeListener(newValue)
|
||||
|
||||
// invoke the on change listeners
|
||||
preference.callChangeListener(preference.value)
|
||||
if (preference.callChangeListener(newValue)) {
|
||||
preference.value = newValue
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
@ -52,14 +55,13 @@ open class MaterialPreferenceFragment : PreferenceFragmentCompat() {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(preference.title)
|
||||
.setView(binding.root)
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
// save the new value
|
||||
preference.text = binding.input.text.toString()
|
||||
|
||||
// invoke the on change listeners
|
||||
preference.callChangeListener(preference.text)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
val newValue = binding.input.text.toString()
|
||||
if (preference.callChangeListener(newValue)) {
|
||||
preference.text = newValue
|
||||
}
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ class AutoPlayHelper(
|
||||
if (relatedStreams == null || relatedStreams.isEmpty()) return null
|
||||
var index = 0
|
||||
var nextStreamId: String? = null
|
||||
while (nextStreamId == null || PlayingQueue.containsBefore(nextStreamId)) {
|
||||
while (nextStreamId == null || PlayingQueue.containsBeforeCurrent(nextStreamId)) {
|
||||
nextStreamId = relatedStreams[index].url!!.toID()
|
||||
if (index + 1 < relatedStreams.size) {
|
||||
index += 1
|
||||
|
@ -58,7 +58,7 @@ object NavBarHelper {
|
||||
*/
|
||||
fun applyNavBarStyle(bottomNav: BottomNavigationView): Int {
|
||||
val labelVisibilityMode = when (
|
||||
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "always")
|
||||
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "selected")
|
||||
) {
|
||||
"always" -> NavigationBarView.LABEL_VISIBILITY_LABELED
|
||||
"selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED
|
||||
|
@ -4,17 +4,13 @@ object PlayingQueue {
|
||||
private val queue = mutableListOf<String>()
|
||||
private var currentVideoId: String? = null
|
||||
|
||||
fun clear() {
|
||||
queue.clear()
|
||||
}
|
||||
|
||||
fun add(videoId: String) {
|
||||
if (currentVideoId == videoId) return
|
||||
if (queue.contains(videoId)) queue.remove(videoId)
|
||||
queue.add(videoId)
|
||||
}
|
||||
|
||||
fun playNext(videoId: String) {
|
||||
fun addAsNext(videoId: String) {
|
||||
if (currentVideoId == videoId) return
|
||||
if (queue.contains(videoId)) queue.remove(videoId)
|
||||
queue.add(
|
||||
@ -24,11 +20,10 @@ object PlayingQueue {
|
||||
}
|
||||
|
||||
fun getNext(): String? {
|
||||
val currentIndex = queue.indexOf(currentVideoId)
|
||||
return if (currentIndex >= queue.size) {
|
||||
return try {
|
||||
queue[currentIndex() + 1]
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
} else {
|
||||
queue[currentIndex + 1]
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,18 +36,20 @@ object PlayingQueue {
|
||||
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) {
|
||||
currentVideoId = videoId
|
||||
queue.add(videoId)
|
||||
}
|
||||
|
||||
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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingBottom="20dp"
|
||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -5,19 +5,22 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp">
|
||||
android:paddingHorizontal="30dp"
|
||||
android:paddingVertical="12dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/drawable"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="25dp"
|
||||
tools:src="@drawable/ic_download" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="16sp"
|
||||
tools:text="Option" />
|
||||
|
||||
|
@ -2,7 +2,8 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
@ -16,7 +17,6 @@
|
||||
<RadioGroup
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:checkedButton="@id/video_radio"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
android:id="@+id/audio_radio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="@string/audio" />
|
||||
|
||||
</RadioGroup>
|
||||
@ -39,19 +39,20 @@
|
||||
android:id="@+id/video_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp" />
|
||||
android:layout_marginVertical="10dp" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/audio_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:visibility="gone" />
|
||||
android:layout_marginVertical="10dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/download"
|
||||
style="@style/CustomDialogButton"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:text="@string/download" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -573,18 +573,6 @@
|
||||
<item>purple</item>
|
||||
</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">
|
||||
<item>@string/hls</item>
|
||||
<item>1080p</item>
|
||||
@ -595,7 +583,7 @@
|
||||
<item>144p</item>
|
||||
</string-array>
|
||||
<string-array name="defresValue">
|
||||
<item></item>
|
||||
<item />
|
||||
<item>1080p</item>
|
||||
<item>720p</item>
|
||||
<item>480p</item>
|
||||
@ -693,14 +681,14 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="labelVisibility">
|
||||
<item>@string/always</item>
|
||||
<item>@string/selected</item>
|
||||
<item>@string/always</item>
|
||||
<item>@string/never</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="labelVisibilityValues">
|
||||
<item>always</item>
|
||||
<item>selected</item>
|
||||
<item>always</item>
|
||||
<item>never</item>
|
||||
</string-array>
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
<ListPreference
|
||||
android:icon="@drawable/ic_label"
|
||||
app:defaultValue="always"
|
||||
app:defaultValue="selected"
|
||||
app:entries="@array/labelVisibility"
|
||||
app:entryValues="@array/labelVisibilityValues"
|
||||
app:key="label_visibility"
|
||||
|
Loading…
x
Reference in New Issue
Block a user