Skip to content

Commit

Permalink
vod chat fixes
Browse files Browse the repository at this point in the history
(cherry picked from commit 2ef31be)
  • Loading branch information
crackededed committed Apr 3, 2024
1 parent 5595f5f commit 98c1f60
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 134 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
applicationId = "com.github.andreyasadchy.xtra"
minSdk = 21
targetSdk = 34
versionCode = 233
versionName = "2.30.6"
versionCode = 234
versionName = "2.30.7"
resourceConfigurations += listOf("ar", "de", "en", "es", "fr", "in", "it", "ja", "pt-rBR", "ru", "tr", "zh-rTW", "zh-rCN")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ class ChatFragment : BaseNetworkFragment(), LifecycleListener, MessageClickedDia
} else {
args.getString(KEY_VIDEO_ID).let {
if (it != null && !args.getBoolean(KEY_START_TIME_EMPTY)) {
val getCurrentPosition = (parentFragment as ChatReplayPlayerFragment)::getCurrentPosition
viewModel.startReplay(account, helixClientId, gqlHeaders, channelId, channelLogin, it, args.getDouble(KEY_START_TIME), getCurrentPosition, messageLimit, emoteQuality, animateGifs, enableStv, enableBttv, enableFfz, checkIntegrity)
val getCurrentPosition = (parentFragment as BasePlayerFragment)::getCurrentPosition
val getCurrentSpeed = (parentFragment as BasePlayerFragment)::getCurrentSpeed
viewModel.startReplay(account, helixClientId, gqlHeaders, channelId, channelLogin, it, args.getInt(KEY_START_TIME), getCurrentPosition, getCurrentSpeed, messageLimit, emoteQuality, animateGifs, enableStv, enableBttv, enableFfz, checkIntegrity)
}
}
}
Expand Down Expand Up @@ -221,6 +222,14 @@ class ChatFragment : BaseNetworkFragment(), LifecycleListener, MessageClickedDia
viewModel.reloadEmotes(helixClientId, helixToken, gqlHeaders, channelId, channelLogin, emoteQuality, animateGifs, enableStv, enableBttv, enableFfz, checkIntegrity)
}

fun updatePosition(position: Long) {
(viewModel.chat as? ChatViewModel.VideoChatController)?.updatePosition(position)
}

fun updateSpeed(speed: Float) {
(viewModel.chat as? ChatViewModel.VideoChatController)?.updateSpeed(speed)
}

fun updateStreamId(id: String?) {
viewModel.streamId = id
}
Expand Down Expand Up @@ -333,15 +342,15 @@ class ChatFragment : BaseNetworkFragment(), LifecycleListener, MessageClickedDia
}
}

fun newInstance(channelId: String?, channelLogin: String?, videoId: String?, startTime: Double?) = ChatFragment().apply {
fun newInstance(channelId: String?, channelLogin: String?, videoId: String?, startTime: Int?) = ChatFragment().apply {
arguments = Bundle().apply {
putBoolean(KEY_IS_LIVE, false)
putString(KEY_CHANNEL_ID, channelId)
putString(KEY_CHANNEL_LOGIN, channelLogin)
putString(KEY_VIDEO_ID, videoId)
if (startTime != null) {
putBoolean(KEY_START_TIME_EMPTY, false)
putDouble(KEY_START_TIME, startTime)
putInt(KEY_START_TIME, startTime)
} else {
putBoolean(KEY_START_TIME_EMPTY, true)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ class ChatViewModel @Inject constructor(
}
}

fun startReplay(account: Account, helixClientId: String?, gqlHeaders: Map<String, String>, channelId: String?, channelLogin: String?, videoId: String, startTime: Double, getCurrentPosition: () -> Double, messageLimit: Int, emoteQuality: String, animateGifs: Boolean, enableStv: Boolean, enableBttv: Boolean, enableFfz: Boolean, checkIntegrity: Boolean) {
fun startReplay(account: Account, helixClientId: String?, gqlHeaders: Map<String, String>, channelId: String?, channelLogin: String?, videoId: String, startTime: Int, getCurrentPosition: () -> Long?, getCurrentSpeed: () -> Float?, messageLimit: Int, emoteQuality: String, animateGifs: Boolean, enableStv: Boolean, enableBttv: Boolean, enableFfz: Boolean, checkIntegrity: Boolean) {
if (chat == null) {
this.messageLimit = messageLimit
chat = VideoChatController(
gqlHeaders = gqlHeaders,
videoId = videoId,
startTime = startTime,
getCurrentPosition = getCurrentPosition
getCurrentPosition = getCurrentPosition,
getCurrentSpeed = getCurrentSpeed
)
chat?.start()
loadEmotes(
Expand Down Expand Up @@ -1186,29 +1187,36 @@ class ChatViewModel @Inject constructor(
}
}

private inner class VideoChatController(
private val gqlHeaders: Map<String, String>,
private val videoId: String,
private val startTime: Double,
private val getCurrentPosition: () -> Double) : ChatController() {
inner class VideoChatController(
private val gqlHeaders: Map<String, String>,
private val videoId: String,
private val startTime: Int,
private val getCurrentPosition: () -> Long?,
private val getCurrentSpeed: () -> Float?) : ChatController() {

private var chatReplayManager: ChatReplayManager? = null

override fun send(message: CharSequence) {

}
override fun send(message: CharSequence) {}

override fun start() {
stop()
chatReplayManager = ChatReplayManager(gqlHeaders, repository, videoId, startTime, getCurrentPosition, this, { _chatMessages.postValue(ArrayList()) }, { _integrity.postValue(true) }, viewModelScope)
pause()
chatReplayManager = ChatReplayManager(gqlHeaders, repository, videoId, startTime, getCurrentPosition, getCurrentSpeed, this, { _chatMessages.postValue(ArrayList()) }, { _integrity.postValue(true) }, viewModelScope).apply { start() }
}

override fun pause() {
chatReplayManager?.stop()
}

override fun stop() {
chatReplayManager?.stop()
pause()
}

fun updatePosition(position: Long) {
chatReplayManager?.updatePosition(position)
}

fun updateSpeed(speed: Float) {
chatReplayManager?.updateSpeed(speed)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.FragmentTransaction
import androidx.media3.common.MimeTypes
Expand Down Expand Up @@ -498,7 +497,7 @@ class MainActivity : AppCompatActivity(), SlidingLayout.Listener {
if (playerFragment == null) {
playerFragment = supportFragmentManager.findFragmentById(R.id.playerContainer) as BasePlayerFragment?
} else {
if (playerFragment?.slidingLayout?.secondView?.isVisible == false && prefs.getString(C.PLAYER_BACKGROUND_PLAYBACK, "0") == "0") {
if (playerFragment?.secondViewIsHidden() == true && prefs.getString(C.PLAYER_BACKGROUND_PLAYBACK, "0") == "0") {
playerFragment?.maximize()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.media3.common.PlaybackException
import androidx.media3.common.PlaybackParameters
import androidx.media3.common.Player
import androidx.media3.common.Timeline
import androidx.media3.common.TrackSelectionOverride
Expand All @@ -46,6 +47,7 @@ import androidx.media3.ui.AspectRatioFrameLayout
import androidx.recyclerview.widget.RecyclerView
import com.github.andreyasadchy.xtra.R
import com.github.andreyasadchy.xtra.model.Account
import com.github.andreyasadchy.xtra.ui.chat.ChatFragment
import com.github.andreyasadchy.xtra.ui.common.BaseNetworkFragment
import com.github.andreyasadchy.xtra.ui.common.RadioButtonDialogFragment
import com.github.andreyasadchy.xtra.ui.main.IntegrityDialog
Expand Down Expand Up @@ -83,14 +85,15 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
protected val player: MediaController?
get() = if (controllerFuture.isDone) controllerFuture.get() else null

lateinit var slidingLayout: SlidingLayout
protected lateinit var slidingLayout: SlidingLayout
private lateinit var playerView: CustomPlayerView
private lateinit var aspectRatioFrameLayout: AspectRatioFrameLayout
private lateinit var chatLayout: ViewGroup
protected var chatFragment: ChatFragment? = null

protected abstract val viewModel: PlayerViewModel

var isPortrait = false
protected var isPortrait = false
private set
private var isKeyboardShown = false

Expand Down Expand Up @@ -127,6 +130,20 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
requireView().findViewById<CustomPlayerView>(R.id.playerView)?.player = player
player.addListener(object : Player.Listener {

override fun onPositionDiscontinuity(oldPosition: Player.PositionInfo, newPosition: Player.PositionInfo, reason: Int) {
if (view != null) {
if (reason == Player.DISCONTINUITY_REASON_SEEK) {
chatFragment?.updatePosition(newPosition.positionMs)
}
}
}

override fun onPlaybackParametersChanged(playbackParameters: PlaybackParameters) {
if (view != null) {
chatFragment?.updateSpeed(playbackParameters.speed)
}
}

override fun onIsPlayingChanged(isPlaying: Boolean) {
if (view != null) {
if (!prefs.getBoolean(C.PLAYER_KEEP_SCREEN_ON_WHEN_PAUSED, false)) {
Expand Down Expand Up @@ -416,9 +433,9 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
playerView.useController = false
chatLayout.gone()
// player dialog
(childFragmentManager.findFragmentByTag("closeOnPip") as? BottomSheetDialogFragment?)?.dismiss()
(childFragmentManager.findFragmentByTag("closeOnPip") as? BottomSheetDialogFragment)?.dismiss()
// player chat message dialog
(childFragmentManager.findFragmentById(R.id.chatFragmentContainer)?.childFragmentManager?.findFragmentByTag("closeOnPip") as? BottomSheetDialogFragment?)?.dismiss()
(chatFragment?.childFragmentManager?.findFragmentByTag("closeOnPip") as? BottomSheetDialogFragment)?.dismiss()
} else {
playerView.useController = true
}
Expand Down Expand Up @@ -824,6 +841,16 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
}
}

fun getCurrentSpeed() = player?.playbackParameters?.speed

fun getCurrentPosition() = player?.currentPosition

fun getIsPortrait() = isPortrait

fun secondViewIsHidden() = slidingLayout.secondView?.isVisible == false

fun reloadEmotes() = chatFragment?.reloadEmotes()

override fun onResume() {
super.onResume()
viewModel.pipMode = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && requireActivity().isInPictureInPictureMode)
Expand Down
Loading

0 comments on commit 98c1f60

Please sign in to comment.