some player ui changes

This commit is contained in:
jmir1 2022-01-14 21:20:02 +01:00
parent d82172cc71
commit ab6128e1f5
5 changed files with 167 additions and 64 deletions

View file

@ -881,7 +881,7 @@ class AnimeController :
duration = data.getLongExtra("extra_duration", 0L)
} else {
currentPosition = data.getIntExtra("position", 0).toLong()
duration = 1440000L
duration = data.getIntExtra("duration", 0).toLong()
}
}
if (cause == "playback_completion") {

View file

@ -11,6 +11,7 @@ import android.widget.SeekBar
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.data.database.models.Anime
@ -19,6 +20,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.NewPlayerActivityBinding
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.base.activity.BaseThemedActivity.Companion.applyAppTheme
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.toast
import `is`.xyz.mpv.MPVLib
@ -27,7 +29,6 @@ import logcat.LogPriority
import nucleus.factory.RequiresPresenter
import uy.kohesive.injekt.injectLazy
import java.io.File
import kotlin.math.abs
@RequiresPresenter(NewPlayerPresenter::class)
class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPresenter>(), MPVLib.EventObserver {
@ -70,6 +71,8 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
private var currentVideoList: List<Video>? = null
private var playerViewMode: Int = preferences.getPlayerViewMode()
@RequiresApi(Build.VERSION_CODES.P)
override fun onCreate(savedInstanceState: Bundle?) {
logcat { "bruh" }
@ -100,6 +103,22 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
}
presenter.init(anime, episode)
}
setViewMode()
}
private fun setViewMode() {
when (playerViewMode) {
2 -> {
MPVLib.setOptionString("keepaspect", "yes")
MPVLib.setOptionString("panscan", "1.0")
}
1 -> {
MPVLib.setOptionString("keepaspect", "yes")
MPVLib.setOptionString("panscan", "0.0")
}
0 -> MPVLib.setOptionString("keepaspect", "no")
}
}
@Suppress("DEPRECATION")
@ -118,7 +137,7 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
}
fun updatePlaybackPos(position: Int) {
binding.playbackPositionTxt.text = prettyTime(position)
binding.playbackPositionTxt.text = Utils.prettyTime(position)
if (!userIsOperatingSeekbar) {
binding.playbackSeekbar.progress = position
}
@ -177,9 +196,58 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
player.cycleSub(); TrackData(player.sid, "sub")
}
@Suppress("UNUSED_PARAMETER")
fun cycleViewMode(view: View) {
playerViewMode = when (playerViewMode) {
0 -> 1
1 -> 2
2 -> 0
else -> 1
}
preferences.setPlayerViewMode(playerViewMode)
setViewMode()
}
private var currentQuality = 0
@Suppress("UNUSED_PARAMETER")
fun openSettings(view: View) {
if (currentVideoList?.isNotEmpty() == true) {
val qualityAlert = MaterialAlertDialogBuilder(this)
qualityAlert.setTitle(R.string.playback_quality_dialog_title)
var requestedQuality = 0
val qualities = currentVideoList!!.map { it.quality }.toTypedArray()
qualityAlert.setSingleChoiceItems(qualities, currentQuality) { qualityDialog, selectedQuality ->
if (selectedQuality > qualities.lastIndex) {
qualityDialog.cancel()
} else {
requestedQuality = selectedQuality
}
}
qualityAlert.setPositiveButton(android.R.string.ok) { qualityDialog, _ ->
if (requestedQuality != currentQuality) changeQuality(requestedQuality)
qualityDialog.dismiss()
}
qualityAlert.setNegativeButton(android.R.string.cancel) { qualityDialog, _ ->
qualityDialog.cancel()
}
qualityAlert.show()
}
}
private fun changeQuality(quality: Int) {
setVideoList(null, quality, player.timePos)
}
@Suppress("UNUSED_PARAMETER")
fun switchDecoder(view: View) {
player.cycleHwdec()
preferences.getPlayerViewMode()
updateDecoderButton()
}
@ -203,8 +271,6 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
val plCount = presenter.episodeList.size
val plPos = presenter.getCurrentEpisodeIndex()
logcat(LogPriority.ERROR) { "count: $plCount, pos: $plPos" }
if (plCount == 1) {
// use View.GONE so the buttons won't take up any space
binding.prevBtn.visibility = View.GONE
@ -246,15 +312,19 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
toast(error.message)
}
fun setVideoList(videos: List<Video>) {
fun setVideoList(videos: List<Video>?, videoPos: Int = 0, timePos: Int? = null) {
logcat(LogPriority.INFO) { "loaded!!" }
currentVideoList = videos
currentVideoList?.first()?.videoUrl.let {
currentVideoList = videos ?: currentVideoList
currentVideoList?.getOrNull(videoPos)?.videoUrl.let {
timePos?.let {
MPVLib.command(arrayOf("set", "start", "$timePos"))
} ?: presenter.currentEpisode?.last_second_seen?.let { pos ->
val intPos = pos / 1000F
MPVLib.command(arrayOf("set", "start", "$intPos"))
}
MPVLib.command(arrayOf("loadfile", it))
// presenter.currentEpisode?.last_second_seen?.let { pos -> player.timePos = (pos / 1000L).toInt() }
}
refreshUi()
updatePlaylistButtons()
launchUI { refreshUi() }
}
fun setHttpOptions(headers: Map<String, String>) {
@ -268,20 +338,6 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
MPVLib.setOptionString("cache-dir", cacheDir)
}
private fun prettyTime(d: Int, sign: Boolean = false): String {
if (sign) {
return (if (d >= 0) "+" else "-") + prettyTime(abs(d))
}
val hours = d / 3600
val minutes = d % 3600 / 60
val seconds = d % 60
if (hours == 0) {
return "%02d:%02d".format(minutes, seconds)
}
return "%d:%02d:%02d".format(hours, minutes, seconds)
}
// mpv events
private fun eventPropertyUi(property: String, value: Long) {
@ -310,4 +366,9 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
override fun eventProperty(property: String, value: String) {}
override fun event(eventId: Int) {}
override fun onStop() {
player.paused = true
super.onStop()
}
}

View file

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.player
import android.os.Bundle
import android.webkit.WebSettings
import eu.kanade.tachiyomi.animesource.AnimeSource
import eu.kanade.tachiyomi.animesource.AnimeSourceManager
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
@ -40,6 +41,8 @@ class NewPlayerPresenter(
*/
private var episodeId = -1L
private var source: AnimeSource? = null
var currentEpisode: Episode? = null
private var currentVideoList: List<Video>? = null
@ -174,18 +177,20 @@ class NewPlayerPresenter(
checkTrackers(anime)
val source = sourceManager.getOrStub(anime.source)
source = sourceManager.getOrStub(anime.source)
currentEpisode = episodeList.first { initialEpisodeId == it.id }
launchIO {
try {
val currentEpisode = currentEpisode ?: throw Exception("bruh")
EpisodeLoader.getLinks(currentEpisode, anime, source)
EpisodeLoader.getLinks(currentEpisode, anime, source!!)
.subscribeFirst(
{ activity, it ->
currentVideoList = it
if (source is AnimeHttpSource) {
activity.setHttpOptions(getHeaders(it, source, activity))
if (source is AnimeHttpSource &&
!EpisodeLoader.isDownloaded(currentEpisode, anime)
) {
activity.setHttpOptions(getHeaders(it, source as AnimeHttpSource, activity))
}
activity.setVideoList(it)
},

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M7,14L5,14v5h5v-2L7,17v-3zM5,10h2L7,7h3L10,5L5,5v5zM17,17h-3v2h5v-5h-2v3zM14,5v2h3v3h2L19,5h-5z"/>
</vector>

View file

@ -74,12 +74,14 @@
<ImageButton
android:id="@+id/prevBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:background="#00000000"
android:src="@drawable/ic_skip_previous_black_24dp"
app:tint="@color/tint_normal" />
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
android:contentDescription="@string/action_previous_chapter"
android:padding="@dimen/screen_edge_margin"
app:srcCompat="@drawable/ic_skip_previous_24dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />
<TextView
android:id="@+id/playbackPositionTxt"
@ -107,16 +109,19 @@
<ImageButton
android:id="@+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:background="#00000000"
android:src="@drawable/ic_skip_next_black_24dp"
app:tint="@color/tint_normal" />
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
android:contentDescription="@string/action_previous_chapter"
android:padding="@dimen/screen_edge_margin"
app:srcCompat="@drawable/ic_skip_next_24dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />
</LinearLayout>
<LinearLayout
android:dividerPadding="47dp"
android:id="@+id/controls_button_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -124,54 +129,76 @@
android:orientation="horizontal">
<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/playBtn"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="48dp"
android:layout_height="match_parent"
android:onClick="playPause"
android:text="play"
android:textColor="@android:color/white"
app:tint="@color/tint_normal" />
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface"
tools:src="@drawable/ic_play_arrow_black_24dp"/>
<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/cycleAudioBtn"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="48dp"
android:layout_height="match_parent"
android:onClick="cycleAudio"
android:src="@drawable/ic_audiotrack_black_24dp"
android:text="..."
android:textColor="@android:color/white"
app:tint="@color/tint_normal" />
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />
<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/cycleSubsBtn"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="48dp"
android:layout_height="match_parent"
android:onClick="cycleSub"
android:src="@drawable/ic_subtitles_black_24dp"
android:text="..."
android:textColor="@android:color/white"
app:tint="@color/tint_normal" />
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />
<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/cycleViewModeBtn"
android:layout_width="48dp"
android:layout_height="match_parent"
android:onClick="cycleViewMode"
android:src="@drawable/ic_fullscreen_black_24dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface"
android:contentDescription="cycleViewMode">
</ImageButton>
<Button
android:id="@+id/cycleDecoderBtn"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:onClick="switchDecoder"
android:text=".."
android:textColor="@android:color/white" />
android:background="?attr/selectableItemBackgroundBorderless"
android:textColor="?attr/colorOnPrimarySurface" />
<Button
android:id="@+id/cycleSpeedBtn"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:onClick="cycleSpeed"
android:text=".."
android:textColor="@android:color/white" />
android:background="?attr/selectableItemBackgroundBorderless"
android:textColor="?attr/colorOnPrimarySurface" />
<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/settingsBtn"
android:layout_width="48dp"
android:layout_height="match_parent"
android:onClick="openSettings"
android:src="@drawable/ic_settings_24dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface"
android:contentDescription="cycleViewMode" />
</LinearLayout>
</LinearLayout>