mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-29 17:49:03 +03:00
add loading indicator
This commit is contained in:
parent
7449825936
commit
017b6b5b7d
4 changed files with 62 additions and 19 deletions
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -176,25 +176,25 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/controls_bottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
tools:visibility="visible">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/playBtn"
|
||||
android:id="@+id/play_btn"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="Play/Pause"
|
||||
android:maxWidth="50dp"
|
||||
android:maxHeight="50dp"
|
||||
android:onClick="playPause"
|
||||
android:textColor="@android:color/white"
|
||||
android:visibility="gone"
|
||||
app:tint="?attr/colorOnPrimarySurface"
|
||||
tools:src="@drawable/ic_play_arrow_100dp" />
|
||||
tools:src="@drawable/ic_play_arrow_100dp"
|
||||
tools:visibility="visible" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
|
@ -352,6 +352,15 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/loading_indicator"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:indeterminate="true"
|
||||
app:indicatorColor="?attr/colorAccent"
|
||||
app:indicatorSize="65dp" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gestureTextView"
|
||||
|
|
Loading…
Reference in a new issue