mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
fixes
This commit is contained in:
parent
0729c0b500
commit
a6cd8a8c12
@ -60,7 +60,7 @@ import com.github.libretube.util.BackgroundHelper
|
|||||||
import com.github.libretube.util.ConnectionHelper
|
import com.github.libretube.util.ConnectionHelper
|
||||||
import com.github.libretube.util.CronetHelper
|
import com.github.libretube.util.CronetHelper
|
||||||
import com.github.libretube.util.DescriptionAdapter
|
import com.github.libretube.util.DescriptionAdapter
|
||||||
import com.github.libretube.util.OnCustomEventListener
|
import com.github.libretube.util.OnDoubleTapEventListener
|
||||||
import com.github.libretube.util.PlayerHelper
|
import com.github.libretube.util.PlayerHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.github.libretube.util.formatShort
|
import com.github.libretube.util.formatShort
|
||||||
@ -90,7 +90,6 @@ 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.util.RepeatModeUtil
|
import com.google.android.exoplayer2.util.RepeatModeUtil
|
||||||
import com.google.android.exoplayer2.video.VideoSize
|
import com.google.android.exoplayer2.video.VideoSize
|
||||||
import com.google.android.material.button.MaterialButton
|
|
||||||
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
|
||||||
@ -113,6 +112,7 @@ class PlayerFragment : Fragment() {
|
|||||||
*/
|
*/
|
||||||
private var videoId: String? = null
|
private var videoId: String? = null
|
||||||
private var playlistId: String? = null
|
private var playlistId: String? = null
|
||||||
|
private var channelId: String? = null
|
||||||
private var isSubscribed: Boolean = false
|
private var isSubscribed: Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -740,6 +740,7 @@ class PlayerFragment : Fragment() {
|
|||||||
title = response.title!!
|
title = response.title!!
|
||||||
uploader = response.uploader!!
|
uploader = response.uploader!!
|
||||||
thumbnailUrl = response.thumbnailUrl!!
|
thumbnailUrl = response.thumbnailUrl!!
|
||||||
|
channelId = response.uploaderUrl?.replace("/channel/", "")
|
||||||
|
|
||||||
// save related streams for autoplay
|
// save related streams for autoplay
|
||||||
relatedStreams = response.relatedStreams
|
relatedStreams = response.relatedStreams
|
||||||
@ -1078,7 +1079,7 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
val channelId = response.uploaderUrl?.replace("/channel/", "")
|
val channelId = response.uploaderUrl?.replace("/channel/", "")
|
||||||
isSubscribed(binding.playerSubscribe, channelId!!)
|
isSubscribed()
|
||||||
binding.relPlayerSave.setOnClickListener {
|
binding.relPlayerSave.setOnClickListener {
|
||||||
val newFragment = AddtoPlaylistDialog()
|
val newFragment = AddtoPlaylistDialog()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
@ -1086,6 +1087,10 @@ class PlayerFragment : Fragment() {
|
|||||||
newFragment.arguments = bundle
|
newFragment.arguments = bundle
|
||||||
newFragment.show(childFragmentManager, "AddToPlaylist")
|
newFragment.show(childFragmentManager, "AddToPlaylist")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
binding.relPlayerSave.setOnClickListener {
|
||||||
|
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1095,7 +1100,7 @@ class PlayerFragment : Fragment() {
|
|||||||
doubleTapOverlayBinding.rewindTV.text = seekIncrementText
|
doubleTapOverlayBinding.rewindTV.text = seekIncrementText
|
||||||
doubleTapOverlayBinding.forwardTV.text = seekIncrementText
|
doubleTapOverlayBinding.forwardTV.text = seekIncrementText
|
||||||
binding.player.setOnDoubleTapListener(
|
binding.player.setOnDoubleTapListener(
|
||||||
object : OnCustomEventListener {
|
object : OnDoubleTapEventListener {
|
||||||
override fun onEvent(x: Float) {
|
override fun onEvent(x: Float) {
|
||||||
val width = exoPlayerView.width
|
val width = exoPlayerView.width
|
||||||
when {
|
when {
|
||||||
@ -1527,12 +1532,12 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSubscribed(button: MaterialButton, channel_id: String) {
|
private fun isSubscribed() {
|
||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.authApi.isSubscribed(
|
RetrofitInstance.authApi.isSubscribed(
|
||||||
channel_id,
|
channelId!!,
|
||||||
token
|
token
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
@ -1547,18 +1552,21 @@ class PlayerFragment : Fragment() {
|
|||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if (response.subscribed == true) {
|
if (response.subscribed == true) {
|
||||||
isSubscribed = true
|
isSubscribed = true
|
||||||
button.text = getString(R.string.unsubscribe)
|
binding.playerSubscribe.text = getString(R.string.unsubscribe)
|
||||||
}
|
}
|
||||||
if (response.subscribed != null) {
|
if (response.subscribed != null) {
|
||||||
button.setOnClickListener {
|
binding.playerSubscribe.setOnClickListener {
|
||||||
if (isSubscribed) {
|
if (isSubscribed) {
|
||||||
unsubscribe(channel_id)
|
unsubscribe(channelId!!)
|
||||||
button.text = getString(R.string.subscribe)
|
binding.playerSubscribe.text = getString(R.string.subscribe)
|
||||||
} else {
|
} else {
|
||||||
subscribe(channel_id)
|
subscribe(channelId!!)
|
||||||
button.text = getString(R.string.unsubscribe)
|
binding.playerSubscribe.text = getString(R.string.unsubscribe)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1566,13 +1574,13 @@ class PlayerFragment : Fragment() {
|
|||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribe(channel_id: String) {
|
private fun subscribe(channelId: String) {
|
||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
try {
|
try {
|
||||||
RetrofitInstance.authApi.subscribe(
|
RetrofitInstance.authApi.subscribe(
|
||||||
token,
|
token,
|
||||||
Subscribe(channel_id)
|
Subscribe(channelId)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package com.github.libretube.util
|
package com.github.libretube.util
|
||||||
|
|
||||||
interface OnCustomEventListener {
|
interface OnDoubleTapEventListener {
|
||||||
fun onEvent(x: Float)
|
fun onEvent(x: Float)
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ import android.view.View
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||||
import com.github.libretube.util.DoubleTapListener
|
import com.github.libretube.util.DoubleTapListener
|
||||||
import com.github.libretube.util.OnCustomEventListener
|
import com.github.libretube.util.OnDoubleTapEventListener
|
||||||
import com.google.android.exoplayer2.ui.StyledPlayerView
|
import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@ -19,19 +19,18 @@ internal class CustomExoPlayerView(
|
|||||||
val TAG = "CustomExoPlayerView"
|
val TAG = "CustomExoPlayerView"
|
||||||
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
||||||
|
|
||||||
var doubleTapListener: OnCustomEventListener? = null
|
private var doubleTapListener: OnDoubleTapEventListener? = null
|
||||||
|
|
||||||
var lastToggled: Long? = null
|
// the x-position of where the user clicked
|
||||||
var xPos = 0F
|
private var xPos = 0F
|
||||||
|
|
||||||
fun setOnDoubleTapListener(
|
fun setOnDoubleTapListener(
|
||||||
eventListener: OnCustomEventListener?
|
eventListener: OnDoubleTapEventListener?
|
||||||
) {
|
) {
|
||||||
doubleTapListener = eventListener
|
doubleTapListener = eventListener
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleController() {
|
private fun toggleController() {
|
||||||
lastToggled = System.currentTimeMillis()
|
|
||||||
if (isControllerFullyVisible) hideController() else showController()
|
if (isControllerFullyVisible) hideController() else showController()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +50,7 @@ internal class CustomExoPlayerView(
|
|||||||
binding.toggleOptions.animate().rotation(0F).setDuration(250).start()
|
binding.toggleOptions.animate().rotation(0F).setDuration(250).start()
|
||||||
binding.advancedOptions.visibility = View.GONE
|
binding.advancedOptions.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
// set the double click listener for rewind/forward
|
||||||
setOnClickListener(doubleTouchListener)
|
setOnClickListener(doubleTouchListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,9 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
// save the x position of the touch event
|
||||||
xPos = event.x
|
xPos = event.x
|
||||||
|
// listen for a double touch
|
||||||
doubleTouchListener.onClick(this)
|
doubleTouchListener.onClick(this)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user