Skip to content

Commit

Permalink
收藏页继续观看的按钮同时显示 ep 和 sort (follow up of #1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Nov 9, 2024
1 parent 1efaa5e commit 5ab6899
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import me.him188.ani.app.domain.media.cache.EpisodeCacheStatus
import me.him188.ani.app.navigation.LocalNavigator
import me.him188.ani.app.tools.WeekFormatter
import me.him188.ani.app.ui.foundation.stateOf
import me.him188.ani.app.ui.subject.renderEpAndSort
import me.him188.ani.datasources.api.PackedDate
import me.him188.ani.datasources.api.toLocalDateOrNull
import me.him188.ani.utils.platform.annotations.TestOnly
Expand Down Expand Up @@ -119,7 +120,7 @@ class SubjectProgressState(

val buttonText by derivedStateOf {
when (val s = continueWatchingStatus) {
is ContinueWatchingStatus.Continue -> "继续观看 ${s.episodeSort}"
is ContinueWatchingStatus.Continue -> "继续观看 ${renderEpAndSort(s.episodeEp, s.episodeSort)}"
ContinueWatchingStatus.Done -> "已看完"
is ContinueWatchingStatus.NotOnAir -> {
val date = s.airDate.toLocalDateOrNull()
Expand All @@ -138,7 +139,7 @@ class SubjectProgressState(
val week = weekFormatter.format(date)
"${week}更新"
} else {
"看过 ${s.episodeSort}"
"看过 ${renderEpAndSort(s.episodeEp, s.episodeSort)}"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ class AiringProgressTests {
create(ON_AIR, 23, ep = watched22).run {
assertEquals("看过 10 (22) · 预定全 12 话", airingLabel)
assertEquals(false, highlightProgress)
assertEquals("看过 22", buttonText)
assertEquals("看过 10 (22)", buttonText)
assertEquals(false, buttonIsPrimary)
}
}
add("同时显示 ep 和 sort: 看过 22, 全 12 话") {
create(COMPLETED, 23, ep = watched22).run {
assertEquals("看过 10 (22) · 全 12 话", airingLabel)
assertEquals(false, highlightProgress)
assertEquals("看过 22", buttonText)
assertEquals("看过 10 (22)", buttonText)
assertEquals(false, buttonIsPrimary)
}
}
Expand All @@ -316,7 +316,7 @@ class AiringProgressTests {
).run {
assertEquals("连载至 11 (23) · 预定全 12 话", airingLabel)
assertEquals(true, highlightProgress)
assertEquals("继续观看 23", buttonText)
assertEquals("继续观看 11 (23)", buttonText)
assertEquals(true, buttonIsPrimary)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ class AiringLabelState(
}
}

private fun renderEpAndSort(ep: EpisodeSort?, sort: EpisodeSort?) = when {
ep == null -> sort.toString()
sort == null -> ep.toString()
ep != sort -> "$ep ($sort)"
else -> sort.toString()
}

val highlightProgress by derivedStateOf {
val continueWatchingStatus = progressInfo?.continueWatchingStatus
airingInfo?.isOnAir == true
Expand Down Expand Up @@ -173,6 +166,14 @@ fun AiringLabel(
}
}

fun renderEpAndSort(ep: EpisodeSort?, sort: EpisodeSort?) = when {
ep == null -> sort.toString()
sort == null -> ep.toString()
ep != sort -> "$ep ($sort)"
else -> sort.toString()
}


@TestOnly
fun createTestAiringLabelState(
airingInfo: SubjectAiringInfo = TestSubjectAiringInfo,
Expand Down

0 comments on commit 5ab6899

Please sign in to comment.