Skip to content

Commit

Permalink
fix: Issues with skip intro length disabling the +85s button
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Jan 18, 2025
1 parent af35c56 commit 9773a91
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.kanade.domain.entries.anime.interactor

import tachiyomi.core.common.util.lang.toLong
import tachiyomi.domain.entries.anime.model.Anime
import tachiyomi.domain.entries.anime.model.AnimeUpdate
import tachiyomi.domain.entries.anime.repository.AnimeRepository
Expand All @@ -14,7 +15,10 @@ class SetAnimeViewerFlags(
animeRepository.updateAnime(
AnimeUpdate(
id = id,
viewerFlags = anime.viewerFlags.setFlag(flag, Anime.ANIME_INTRO_MASK),
viewerFlags = anime.viewerFlags
.setFlag(flag, Anime.ANIME_INTRO_MASK)
// Disable skip intro button if length is set to 0
.setFlag((flag == 0L).toLong(), Anime.ANIME_INTRO_DISABLE_MASK),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,6 @@ class AnimeScreenModel(
}
}

// Set default intro length
setAnimeViewerFlags.awaitSetSkipIntroLength(
anime.id,
gesturePreferences.defaultIntroLength().get().toLong(),
)

// Finally match with enhanced tracking when available
addTracks.bindEnhancedTrackers(anime, state.source)
if (autoOpenTrack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ class PlayerViewModel @JvmOverloads constructor(

// Write to mpv table
MPVLib.setPropertyString("user-data/current-anime/anime-title", anime.title)
MPVLib.setPropertyInt("user-data/current-anime/intro-length", anime.skipIntroLength)
MPVLib.setPropertyInt("user-data/current-anime/intro-length", getAnimeSkipIntroLength())
MPVLib.setPropertyString(
"user-data/current-anime/category",
getAnimeCategories.await(anime.id).joinToString {
Expand Down Expand Up @@ -1482,11 +1482,27 @@ class PlayerViewModel @JvmOverloads constructor(
}
}

/**
* Returns the skipIntroLength used by this anime or the default one.
*/
fun getAnimeSkipIntroLength(): Int {
val default = gesturePreferences.defaultIntroLength().get()
val anime = currentAnime.value ?: return default
val skipIntroLength = anime.skipIntroLength
val skipIntroDisable = anime.skipIntroDisable
return when {
skipIntroDisable -> 0
skipIntroLength <= 0 -> default
else -> anime.skipIntroLength
}
}

/**
* Updates the skipIntroLength for the open anime.
*/
fun setAnimeSkipIntroLength(skipIntroLength: Long) {
val anime = currentAnime.value ?: return
if (!anime.favorite) return
viewModelScope.launchIO {
setAnimeViewerFlags.awaitSetSkipIntroLength(anime.id, skipIntroLength)
logcat(LogPriority.INFO) { "New Skip Intro Length is ${anime.skipIntroLength}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ data class Anime(
val skipIntroLength: Int
get() = (viewerFlags and ANIME_INTRO_MASK).toInt()

val skipIntroDisable: Boolean
get() = (viewerFlags and ANIME_INTRO_DISABLE_MASK) == ANIME_INTRO_DISABLE_MASK

val nextEpisodeToAir: Int
get() = (viewerFlags and ANIME_AIRING_EPISODE_MASK).removeHexZeros(zeros = 2).toInt()

Expand Down Expand Up @@ -117,9 +120,10 @@ data class Anime(
const val EPISODE_DISPLAY_NUMBER = 0x00100000L
const val EPISODE_DISPLAY_MASK = 0x00100000L

const val ANIME_INTRO_MASK = 0x000000000000FFL
const val ANIME_AIRING_EPISODE_MASK = 0x00000000FFFF00L
const val ANIME_AIRING_TIME_MASK = 0xFFFFFFFF000000L
const val ANIME_INTRO_MASK = 0x0000000000000FFL
const val ANIME_INTRO_DISABLE_MASK = 0x100000000000000L
const val ANIME_AIRING_EPISODE_MASK = 0x000000000FFFF00L
const val ANIME_AIRING_TIME_MASK = 0x0FFFFFFFF000000L

fun create() = Anime(
id = -1L,
Expand Down

0 comments on commit 9773a91

Please sign in to comment.