Browse Source

ABRepeat refactor common methods

Fixes #1139
merge-requests/509/head
Nicolas Pomepuy 6 years ago
committed by Geoffrey Métais
parent
commit
bfa5ec18c1
  1. 2
      application/vlc-android/res/layout/player_hud.xml
  2. 49
      application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
  3. 62
      application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
  4. 54
      application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt

2
application/vlc-android/res/layout/player_hud.xml

@ -211,7 +211,7 @@
android:minHeight="@dimen/seekbar_height"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:progress="@{player.getTime(progress.time)}"
android:progress="@{player.service.getTime(progress.time)}"
android:progressDrawable="@drawable/po_seekbar_video"
android:splitTrack="false"
android:thumb="@drawable/seekbar_thumb"

49
application/vlc-android/src/org/videolan/vlc/PlaybackService.kt

@ -36,6 +36,8 @@ import android.support.v4.media.session.PlaybackStateCompat
import android.telephony.TelephonyManager
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.MainThread
import androidx.annotation.RequiresApi
@ -1352,6 +1354,29 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
or PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID or PlaybackStateCompat.ACTION_PLAY_FROM_URI
or PlaybackStateCompat.ACTION_PLAY_PAUSE)
}
fun getTime(realTime: Long): Int {
playlistManager.abRepeat.value?.let {
if (it.start != -1L && it.stop != -1L) return when {
playlistManager.abRepeatOn.value!! -> {
val start = it.start
val end = it.stop
when {
start != -1L && realTime < start -> {
start.toInt()
}
end != -1L && realTime > it.stop -> {
end.toInt()
}
else -> realTime.toInt()
}
}
else -> realTime.toInt()
}
}
return realTime.toInt()
}
}
// Actor actions sealed classes
@ -1365,3 +1390,27 @@ private class CbRemove(val cb: PlaybackService.Callback) : CbAction()
private object ShowNotification : CbAction()
private class HideNotification(val remove: Boolean) : CbAction()
private object UpdateMeta : CbAction()
fun PlaybackService.manageAbRepeatStep(abRepeatReset: View, abRepeatStop: View, abRepeatContainer: View, abRepeatAddMarker: TextView) {
when {
playlistManager.abRepeatOn.value != true -> abRepeatContainer.visibility = View.GONE
playlistManager.abRepeat.value?.start != -1L && playlistManager.abRepeat.value?.stop != -1L -> {
abRepeatReset.visibility = View.VISIBLE
abRepeatStop.visibility = View.VISIBLE
abRepeatContainer.visibility = View.GONE
}
playlistManager.abRepeat.value?.start == -1L && playlistManager.abRepeat.value?.stop == -1L -> {
abRepeatContainer.visibility = View.VISIBLE
abRepeatAddMarker.text = getString(R.string.abrepeat_add_first_marker)
abRepeatReset.visibility = View.GONE
abRepeatStop.visibility = View.GONE
}
playlistManager.abRepeat.value?.start == -1L || playlistManager.abRepeat.value?.stop == -1L -> {
abRepeatAddMarker.text = getString(R.string.abrepeat_add_second_marker)
abRepeatContainer.visibility = View.VISIBLE
abRepeatReset.visibility = View.GONE
abRepeatStop.visibility = View.GONE
}
}
}

62
application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt

@ -67,6 +67,7 @@ import org.videolan.vlc.gui.helpers.*
import org.videolan.vlc.gui.video.VideoPlayerActivity
import org.videolan.vlc.gui.view.AudioMediaSwitcher
import org.videolan.vlc.gui.view.AudioMediaSwitcher.AudioMediaSwitcherListener
import org.videolan.vlc.manageAbRepeatStep
import org.videolan.vlc.media.PlaylistManager.Companion.hasMedia
import org.videolan.vlc.util.share
import org.videolan.vlc.viewmodels.PlaybackProgress
@ -162,12 +163,12 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
binding.abRepeatB = if (abvalues.stop == -1L) -1F else abvalues.stop / playlistModel.service!!.playlistManager.player.getLength().toFloat()
binding.abRepeatMarkerA.visibility = if (abvalues.start == -1L) View.GONE else View.VISIBLE
binding.abRepeatMarkerB.visibility = if (abvalues.stop == -1L) View.GONE else View.VISIBLE
manageAbRepeatStep()
playlistModel.service?.manageAbRepeatStep(binding.abRepeatReset, binding.abRepeatStop, binding.abRepeatContainer, abRepeatAddMarker)
})
playlistModel.service?.playlistManager?.abRepeatOn?.observe(this, Observer {
binding.abRepeatMarkerGuidelineContainer.visibility = if (it) View.VISIBLE else View.GONE
manageAbRepeatStep()
playlistModel.service?.manageAbRepeatStep(binding.abRepeatReset, binding.abRepeatStop, binding.abRepeatContainer, abRepeatAddMarker)
})
abRepeatAddMarker.setOnClickListener {
@ -297,13 +298,14 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
val displayTime = if (showRemainingTime) Tools.millisToString(progress.time - progress.length) else progress.timeText
binding.headerTime.text = displayTime
binding.time.text = displayTime
binding.timeline.progress = getTime(progress.time)
binding.timeline.progress = playlistModel.service?.getTime(progress.time)
?: progress.time.toInt()
binding.progressBar.progress = progress.time.toInt()
}
}
override fun onSelectionSet(position: Int) {
if (playerState != BottomSheetBehavior.STATE_COLLAPSED && playerState != com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN) {
if (playerState != BottomSheetBehavior.STATE_COLLAPSED && playerState != BottomSheetBehavior.STATE_HIDDEN) {
binding.songsList.scrollToPosition(position)
}
}
@ -328,11 +330,11 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
}
fun onNextClick(view: View) {
if (!playlistModel.next()) Snackbar.make(binding.root, R.string.lastsong, com.google.android.material.snackbar.Snackbar.LENGTH_SHORT).show()
if (!playlistModel.next()) Snackbar.make(binding.root, R.string.lastsong, Snackbar.LENGTH_SHORT).show()
}
fun onPreviousClick(view: View) {
if (!playlistModel.previous()) Snackbar.make(binding.root, R.string.firstsong, com.google.android.material.snackbar.Snackbar.LENGTH_SHORT).show()
if (!playlistModel.previous()) Snackbar.make(binding.root, R.string.firstsong, Snackbar.LENGTH_SHORT).show()
}
fun onRepeatClick(view: View) {
@ -582,52 +584,4 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
playlistModel.filter(null)
}
}
private fun manageAbRepeatStep() {
when {
playlistModel.service?.playlistManager?.abRepeatOn?.value != true -> binding.abRepeatContainer.visibility = View.GONE
playlistModel.service?.playlistManager?.abRepeat?.value?.start != -1L && playlistModel.service?.playlistManager?.abRepeat?.value?.stop != -1L -> {
binding.abRepeatReset.visibility = View.VISIBLE
binding.abRepeatStop.visibility = View.VISIBLE
binding.abRepeatContainer.visibility = View.GONE
}
playlistModel.service?.playlistManager?.abRepeat?.value?.start == -1L && playlistModel.service?.playlistManager?.abRepeat?.value?.stop == -1L -> {
binding.abRepeatContainer.visibility = View.VISIBLE
abRepeatAddMarker.text = getString(R.string.abrepeat_add_first_marker)
binding.abRepeatReset.visibility = View.GONE
binding.abRepeatStop.visibility = View.GONE
}
playlistModel.service?.playlistManager?.abRepeat?.value?.start == -1L || playlistModel.service?.playlistManager?.abRepeat?.value?.stop == -1L -> {
abRepeatAddMarker.text = getString(R.string.abrepeat_add_second_marker)
binding.abRepeatContainer.visibility = View.VISIBLE
binding.abRepeatReset.visibility = View.GONE
binding.abRepeatStop.visibility = View.GONE
}
}
}
private fun getTime(realTime: Long): Int {
playlistModel.service?.let { service ->
service.playlistManager.abRepeat.value?.let {
if (it.start != -1L && it.stop != -1L) return when {
service.playlistManager.abRepeatOn.value!! -> {
val start = it.start
val end = it.stop
when {
start != -1L && realTime < start -> {
start.toInt()
}
end != -1L && realTime > it.stop -> {
end.toInt()
}
else -> realTime.toInt()
}
}
else -> realTime.toInt()
}
}
}
return realTime.toInt()
}
}

54
application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt

@ -2121,13 +2121,13 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
hudBinding = DataBindingUtil.bind(findViewById(R.id.progress_overlay)) ?: return
hudBinding.player = this
hudBinding.progress = service.playlistManager.player.progress
abRepeatAddMarker = hudBinding.abRepeatContainer.findViewById<Button>(R.id.ab_repeat_add_marker)
abRepeatAddMarker = hudBinding.abRepeatContainer.findViewById(R.id.ab_repeat_add_marker)
service.playlistManager.abRepeat.observe(this, Observer { abvalues ->
hudBinding.abRepeatA = if (abvalues.start == -1L) -1F else abvalues.start / service.playlistManager.player.getLength().toFloat()
hudBinding.abRepeatB = if (abvalues.stop == -1L) -1F else abvalues.stop / service.playlistManager.player.getLength().toFloat()
hudBinding.abRepeatMarkerA.visibility = if (abvalues.start == -1L) View.GONE else View.VISIBLE
hudBinding.abRepeatMarkerB.visibility = if (abvalues.stop == -1L) View.GONE else View.VISIBLE
manageAbRepeatStep()
service.manageAbRepeatStep(hudRightBinding.abRepeatReset, hudRightBinding.abRepeatStop, hudBinding.abRepeatContainer, abRepeatAddMarker)
})
service.playlistManager.abRepeatOn.observe(this, Observer {
hudBinding.abRepeatMarkerGuidelineContainer.visibility = if (it) View.VISIBLE else View.GONE
@ -2137,7 +2137,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
hudBinding.playerOverlayTime.nextFocusUpId = R.id.ab_repeat_add_marker
}
manageAbRepeatStep()
service.manageAbRepeatStep(hudRightBinding.abRepeatReset, hudRightBinding.abRepeatStop, hudBinding.abRepeatContainer, abRepeatAddMarker)
})
service.playlistManager.videoStatsOn.observe(this, Observer {
if (it) showOverlay(true)
@ -2192,54 +2192,6 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
}
}
private fun manageAbRepeatStep() {
when {
service?.playlistManager?.abRepeatOn?.value != true -> hudBinding.abRepeatContainer.visibility = View.GONE
service?.playlistManager?.abRepeat?.value?.start != -1L && service?.playlistManager?.abRepeat?.value?.stop != -1L -> {
hudRightBinding.abRepeatReset.visibility = View.VISIBLE
hudRightBinding.abRepeatStop.visibility = View.VISIBLE
hudBinding.abRepeatContainer.visibility = View.GONE
}
service?.playlistManager?.abRepeat?.value?.start == -1L && service?.playlistManager?.abRepeat?.value?.stop == -1L -> {
hudBinding.abRepeatContainer.visibility = View.VISIBLE
abRepeatAddMarker.text = getString(R.string.abrepeat_add_first_marker)
hudRightBinding.abRepeatReset.visibility = View.GONE
hudRightBinding.abRepeatStop.visibility = View.GONE
}
service?.playlistManager?.abRepeat?.value?.start == -1L || service?.playlistManager?.abRepeat?.value?.stop == -1L -> {
abRepeatAddMarker.text = getString(R.string.abrepeat_add_second_marker)
hudBinding.abRepeatContainer.visibility = View.VISIBLE
hudRightBinding.abRepeatReset.visibility = View.GONE
hudRightBinding.abRepeatStop.visibility = View.GONE
}
}
}
fun getTime(realTime: Long): Int {
service?.let { service ->
service.playlistManager.abRepeat.value?.let {
if (it.start != -1L && it.stop != -1L) return when {
service.playlistManager.abRepeatOn.value!! -> {
val start = it.start
val end = it.stop
when {
start != -1L && realTime < start -> {
start.toInt()
}
end != -1L && realTime > it.stop -> {
end.toInt()
}
else -> realTime.toInt()
}
}
else -> realTime.toInt()
}
}
}
return realTime.toInt()
}
/**
* hider overlay
*/

Loading…
Cancel
Save