Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up master #14

Merged
merged 10 commits into from
Dec 8, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ object SettingsPlayerScreen : SearchableSettings {
val enablePip = playerPreferences.enablePip()
val pipEpisodeToasts = playerPreferences.pipEpisodeToasts()
val pipOnExit = playerPreferences.pipOnExit()
val pipReplaceWithPrevious = playerPreferences.pipReplaceWithPrevious()

val isPipEnabled by enablePip.collectAsState()

Expand All @@ -333,6 +334,11 @@ object SettingsPlayerScreen : SearchableSettings {
title = stringResource(MR.strings.pref_pip_on_exit),
enabled = isPipEnabled,
),
Preference.PreferenceItem.SwitchPreference(
pref = pipReplaceWithPrevious,
title = stringResource(MR.strings.pref_pip_replace_with_previous),
enabled = isPipEnabled,
),
),
)
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/Migrations.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.kanade.tachiyomi

import android.content.Context
import android.os.Build
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.domain.base.BasePreferences
Expand All @@ -16,6 +17,7 @@ import eu.kanade.tachiyomi.data.track.TrackerManager
import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import eu.kanade.tachiyomi.ui.player.settings.PlayerPreferences
import eu.kanade.tachiyomi.ui.player.viewer.HwDecState
import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.system.DeviceUtil
Expand Down Expand Up @@ -566,6 +568,10 @@ object Migrations {
filterPredicate = { it.key in prefsToReplace },
newKey = { Preference.appStateKey(it) },
)

if (Build.MODEL == "Subsystem for Android(TM)") {
playerPreferences.hwDec().set(HwDecState.SW.mpvValue)
}
}
return true
}
Expand Down
78 changes: 43 additions & 35 deletions app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ import eu.kanade.tachiyomi.ui.player.settings.sheets.subtitle.SubtitleSettingsSh
import eu.kanade.tachiyomi.ui.player.settings.sheets.subtitle.toHexString
import eu.kanade.tachiyomi.ui.player.viewer.ACTION_MEDIA_CONTROL
import eu.kanade.tachiyomi.ui.player.viewer.AspectState
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_NEXT
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_PAUSE
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_PLAY
import eu.kanade.tachiyomi.ui.player.viewer.CONTROL_TYPE_PREVIOUS
import eu.kanade.tachiyomi.ui.player.viewer.EXTRA_CONTROL_TYPE
import eu.kanade.tachiyomi.ui.player.viewer.GestureHandler
import eu.kanade.tachiyomi.ui.player.viewer.PIP_NEXT
import eu.kanade.tachiyomi.ui.player.viewer.PIP_PAUSE
import eu.kanade.tachiyomi.ui.player.viewer.PIP_PLAY
import eu.kanade.tachiyomi.ui.player.viewer.PIP_PREVIOUS
import eu.kanade.tachiyomi.ui.player.viewer.PIP_SKIP
import eu.kanade.tachiyomi.ui.player.viewer.PictureInPictureHandler
import eu.kanade.tachiyomi.ui.player.viewer.PipState
import eu.kanade.tachiyomi.ui.player.viewer.SeekState
Expand All @@ -86,6 +87,8 @@ import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.setComposeContent
import `is`.xyz.mpv.MPVLib
import `is`.xyz.mpv.Utils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
Expand Down Expand Up @@ -397,7 +400,10 @@ class PlayerActivity : BaseActivity() {
when (state.sheet) {
is PlayerViewModel.Sheet.ScreenshotOptions -> {
ScreenshotOptionsSheet(
screenModel = PlayerSettingsScreenModel(viewModel.playerPreferences),
screenModel = PlayerSettingsScreenModel(
preferences = viewModel.playerPreferences,
hasSubTracks = streams.subtitle.tracks.size > 1,
),
cachePath = cacheDir.path,
onSetAsCover = viewModel::setAsCover,
onShare = { viewModel.shareImage(it, player.timePos) },
Expand Down Expand Up @@ -511,8 +517,8 @@ class PlayerActivity : BaseActivity() {
is PlayerViewModel.Sheet.SubtitleSettings -> {
SubtitleSettingsSheet(
screenModel = PlayerSettingsScreenModel(
viewModel.playerPreferences,
streams.subtitle.tracks.size > 1,
preferences = viewModel.playerPreferences,
hasSubTracks = streams.subtitle.tracks.size > 1,
),
onDismissRequest = pauseForDialogSheet(fadeControls = true),
)
Expand Down Expand Up @@ -621,19 +627,7 @@ class PlayerActivity : BaseActivity() {
MPVLib.setPropertyDouble("sub-delay", subtitlesDelay().get() / 1000.0)
}

// TODO: I think this is a bad hack.
// We need to find a way to let MPV access our fonts directory.
val storageManager: StorageManager = Injekt.get()
storageManager.getFontsDirectory()?.listFiles()?.forEach { font ->
val outFile = UniFile.fromFile(applicationContext.filesDir)?.createFile(font.name)
outFile?.let {
font.openInputStream().copyTo(it.openOutputStream())
}
}
MPVLib.setPropertyString(
"sub-fonts-dir",
applicationContext.filesDir.path,
)
copyFontsDirectory()

if (playerPreferences.subtitleFont().get().trim() != "") {
MPVLib.setPropertyString("sub-font", playerPreferences.subtitleFont().get())
Expand All @@ -653,6 +647,25 @@ class PlayerActivity : BaseActivity() {
}
}

private fun copyFontsDirectory() {
// TODO: I think this is a bad hack.
// We need to find a way to let MPV directly access our fonts directory.
CoroutineScope(Dispatchers.IO).launchIO {
val storageManager: StorageManager = Injekt.get()
storageManager.getFontsDirectory()?.listFiles()?.forEach { font ->
val outFile = UniFile.fromFile(applicationContext.filesDir)?.createFile(font.name)
outFile?.let {
font.openInputStream().copyTo(it.openOutputStream())
}
}
MPVLib.setPropertyString(
"sub-fonts-dir",
applicationContext.filesDir.path,
)
logcat { "FINISHED FONTS" }
}
}

private fun setupPlayerBrightness() {
val useDeviceBrightness =
playerPreferences.playerBrightnessValue().get() == -1.0F ||
Expand Down Expand Up @@ -834,11 +847,7 @@ class PlayerActivity : BaseActivity() {
super.onResume()
refreshUi()
if (pip.supportedAndEnabled && PipState.mode == PipState.ON) {
player.paused?.let {
pip.update(
!it,
)
}
player.paused?.let { pip.update(!it) }
}
}

Expand Down Expand Up @@ -980,12 +989,8 @@ class PlayerActivity : BaseActivity() {
val gestures = GestureHandler(this, deviceWidth.toFloat(), deviceHeight.toFloat())
val mDetector = GestureDetectorCompat(this, gestures)
player.setOnTouchListener { v, event ->
try { // TODO: https://issuetracker.google.com/issues/238920463 is fixed in API 34, but for now this will do
gestures.onTouch(v, event)
mDetector.onTouchEvent(event)
} catch (_: NullPointerException) {
false
}
gestures.onTouch(v, event)
mDetector.onTouchEvent(event)
}
}

Expand Down Expand Up @@ -1447,18 +1452,21 @@ class PlayerActivity : BaseActivity() {
return
}
when (intent.getIntExtra(EXTRA_CONTROL_TYPE, 0)) {
CONTROL_TYPE_PLAY -> {
PIP_PLAY -> {
player.paused = false
}
CONTROL_TYPE_PAUSE -> {
PIP_PAUSE -> {
player.paused = true
}
CONTROL_TYPE_PREVIOUS -> {
PIP_PREVIOUS -> {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = true))
}
CONTROL_TYPE_NEXT -> {
PIP_NEXT -> {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = false))
}
PIP_SKIP -> {
doubleTapSeek(time = 10)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class PlayerViewModel @JvmOverloads constructor(
fun isEpisodeOnline(): Boolean? {
val anime = currentAnime ?: return null
val episode = currentEpisode ?: return null
return currentSource is AnimeHttpSource && !EpisodeLoader.isDownloaded(
return currentSource is AnimeHttpSource && !EpisodeLoader.isDownload(
episode.toDomainEpisode()!!,
anime,
)
Expand Down Expand Up @@ -379,8 +379,8 @@ class PlayerViewModel @JvmOverloads constructor(

val nextEpisode = this.currentPlaylist[getCurrentEpisodeIndex() + 1]
val episodesAreDownloaded =
EpisodeLoader.isDownloaded(currentEpisode.toDomainEpisode()!!, anime) &&
EpisodeLoader.isDownloaded(nextEpisode.toDomainEpisode()!!, anime)
EpisodeLoader.isDownload(currentEpisode.toDomainEpisode()!!, anime) &&
EpisodeLoader.isDownload(nextEpisode.toDomainEpisode()!!, anime)

viewModelScope.launchIO {
if (!episodesAreDownloaded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,9 @@ class EpisodeLoader {
* @param source the source of the anime.
*/
suspend fun getLinks(episode: Episode, anime: Anime, source: AnimeSource): List<Video> {
val downloadManager: AnimeDownloadManager = Injekt.get()
val isDownloaded = downloadManager.isEpisodeDownloaded(
episode.name,
episode.scanlator,
anime.title,
anime.source,
skipCache = true,
)
val isDownloaded = isDownload(episode, anime)
return when {
isDownloaded -> isDownloaded(episode, anime, source, downloadManager)
isDownloaded -> isDownload(episode, anime, source)
source is AnimeHttpSource -> isHttp(episode, source)
source is LocalAnimeSource -> isLocal(episode)
else -> error("source not supported")
Expand All @@ -51,7 +44,7 @@ class EpisodeLoader {
* @param episode the episode being parsed.
* @param anime the anime of the episode.
*/
fun isDownloaded(episode: Episode, anime: Anime): Boolean {
fun isDownload(episode: Episode, anime: Anime): Boolean {
val downloadManager: AnimeDownloadManager = Injekt.get()
return downloadManager.isEpisodeDownloaded(
episode.name,
Expand Down Expand Up @@ -90,14 +83,13 @@ class EpisodeLoader {
* @param episode the episode being parsed.
* @param anime the anime of the episode.
* @param source the source of the anime.
* @param downloadManager the AnimeDownloadManager instance to use.
*/
private fun isDownloaded(
private fun isDownload(
episode: Episode,
anime: Anime,
source: AnimeSource,
downloadManager: AnimeDownloadManager,
): List<Video> {
val downloadManager: AnimeDownloadManager = Injekt.get()
return try {
val video = downloadManager.buildVideo(source, anime, episode)
listOf(video)
Expand All @@ -111,7 +103,7 @@ class EpisodeLoader {
*
* @param episode the episode being parsed.
*/
private suspend fun isLocal(
private fun isLocal(
episode: Episode,
): List<Video> {
return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PlayerPreferences(
fun enablePip() = preferenceStore.getBoolean("pref_enable_pip", true)
fun pipEpisodeToasts() = preferenceStore.getBoolean("pref_pip_episode_toasts", true)
fun pipOnExit() = preferenceStore.getBoolean("pref_pip_on_exit", false)
fun pipReplaceWithPrevious() = preferenceStore.getBoolean("pip_replace_with_previous", false)

fun rememberPlayerBrightness() = preferenceStore.getBoolean("pref_remember_brightness", false)
fun playerBrightnessValue() = preferenceStore.getFloat("player_brightness_value", -1.0F)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ val sheetDialogPadding = PaddingValues(

class PlayerSettingsScreenModel(
val preferences: PlayerPreferences = Injekt.get(),
private val hasSubTracks: Boolean = true,
val hasSubTracks: Boolean = true,
) : ScreenModel {

fun togglePreference(preference: (PlayerPreferences) -> Preference<Boolean>) =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fun PlayerSettingsSheet(
modifier = Modifier.padding(vertical = MaterialTheme.padding.tiny),
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
) {
PlayerStatsPage.values().forEach {
PlayerStatsPage.entries.forEach {
FilterChip(
selected = statisticsPage == it.page,
onClick = { togglePlayerStatsPage(it.page) },
Expand Down
Loading
Loading