diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt index 6e0677bd6..63bbfcd3d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt @@ -50,11 +50,20 @@ class Gestures( when { e.x < width * 0.4F -> activity.doubleTapSeek(-interval, e) e.x > width * 0.6F -> activity.doubleTapSeek(interval, e) - else -> return false } return true } + override fun onDoubleTapEvent(e: MotionEvent): Boolean { + if (activity.isLocked) return false + if (e.y < height * 0.05F || e.y > height * 0.95F || e.x < width * 0.05F || e.x > width * 0.95F) return false + if (e.action == MotionEvent.ACTION_UP && e.x > width * 0.4F && e.x < width * 0.6F) { + activity.toggleControls() + return true + } + return false + } + override fun onScroll( e1: MotionEvent, e2: MotionEvent, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt index 5328f5dd6..50c3e15e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt @@ -85,7 +85,7 @@ class PlayerActivity : internal var isLocked = false private val windowInsetsController by lazy { WindowInsetsControllerCompat(window, binding.root) } - + private var audioFocusRestore: () -> Unit = {} private val audioFocusChangeListener = AudioManager.OnAudioFocusChangeListener { type -> @@ -271,8 +271,26 @@ class PlayerActivity : binding.playbackSeekbar.setOnSeekBarChangeListener(seekBarChangeListener) // player.playFile(currentVideoList!!.first().videoUrl!!.toString()) - binding.nextBtn.setOnClickListener { presenter.nextEpisode() } - binding.prevBtn.setOnClickListener { presenter.previousEpisode() } + binding.nextBtn.setOnClickListener { + val wasPlayerPaused = player.paused + player.paused = true + showLoadingIndicator(true) + presenter.nextEpisode { + if (wasPlayerPaused == false) { + player.paused = false + } + } + } + binding.prevBtn.setOnClickListener { + val wasPlayerPaused = player.paused + player.paused = true + showLoadingIndicator(true) + presenter.previousEpisode { + if (wasPlayerPaused == false) { + player.paused = false + } + } + } if (presenter?.needsInit() == true) { val anime = intent.extras!!.getLong("anime", -1) @@ -288,7 +306,6 @@ class PlayerActivity : } fun toggleControls() { - windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) if (isLocked) { // Hide controls @@ -307,6 +324,12 @@ class PlayerActivity : } } + private fun showLoadingIndicator(visible: Boolean) { + if (binding.loadingIndicator.isVisible == visible) return + binding.playBtn.isVisible = !visible + binding.loadingIndicator.isVisible = visible + } + private fun pickAudio() { val restore = pauseForDialog() @@ -397,16 +420,15 @@ class PlayerActivity : val picker = SpeedPickerDialog() val restore = pauseForDialog() - genericPickerDialog(picker, R.string.title_speed_dialog, "speed") { + speedPickerDialog(picker, R.string.title_speed_dialog) { updateSpeedButton() restore() } } - private fun genericPickerDialog( + private fun speedPickerDialog( picker: PickerDialog, @StringRes titleRes: Int, - property: String, restoreState: StateRestoreCallback ) { val dialog = with(AlertDialog.Builder(this)) { @@ -415,9 +437,9 @@ class PlayerActivity : setPositiveButton(R.string.dialog_ok) { _, _ -> picker.number?.let { if (picker.isInteger()) { - MPVLib.setPropertyInt(property, it.toInt()) + MPVLib.setPropertyInt("speed", it.toInt()) } else { - MPVLib.setPropertyDouble(property, it) + MPVLib.setPropertyDouble("speed", it) } } } @@ -426,7 +448,7 @@ class PlayerActivity : create() } - picker.number = MPVLib.getPropertyDouble(property) + picker.number = MPVLib.getPropertyDouble("speed") dialog.show() } @@ -792,6 +814,7 @@ class PlayerActivity : } private fun fileLoaded() { + launchUI { showLoadingIndicator(false) } clearTracks() player.loadTracks() subTracks += player.tracks.getValue("sub") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt index 0417d85a4..257ee8ddd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt @@ -185,7 +185,7 @@ class PlayerPresenter( return source is AnimeHttpSource && !EpisodeLoader.isDownloaded(currentEpisode, anime) } - fun nextEpisode() { + fun nextEpisode(callback: () -> Unit) { val anime = anime ?: return val source = sourceManager.getOrStub(anime.source) @@ -200,6 +200,7 @@ class PlayerPresenter( { activity, it -> currentVideoList = it activity.setVideoList(it) + callback() }, PlayerActivity::setInitialEpisodeError ) @@ -209,7 +210,7 @@ class PlayerPresenter( } } - fun previousEpisode() { + fun previousEpisode(callback: () -> Unit) { val anime = anime ?: return val source = sourceManager.getOrStub(anime.source) @@ -224,6 +225,7 @@ class PlayerPresenter( { activity, it -> currentVideoList = it activity.setVideoList(it) + callback() }, PlayerActivity::setInitialEpisodeError ) diff --git a/app/src/main/res/layout/player_activity.xml b/app/src/main/res/layout/player_activity.xml index 14f51574e..25e9d63e1 100644 --- a/app/src/main/res/layout/player_activity.xml +++ b/app/src/main/res/layout/player_activity.xml @@ -176,25 +176,25 @@ - + android:layout_height="match_parent" + tools:visibility="visible"> + tools:src="@drawable/ic_play_arrow_100dp" + tools:visibility="visible" /> + +