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

Filter out non-toc chapters #3556

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Bug Fixes
* Fix missing episodes with unfollowed podcasts
([#3546](https://github.com/Automattic/pocket-casts-android/pull/3546))
* Updates
* Filter out chapters that do not belong in table of contents. See [the specification](https://github.com/Podcastindex-org/podcast-namespace/blob/main/chapters/jsonChapters.md) for more details.
([#3556](https://github.com/Automattic/pocket-casts-android/pull/3556))

7.82
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class AppDatabaseTest {
AppDatabase.MIGRATION_103_104,
AppDatabase.MIGRATION_104_105,
AppDatabase.MIGRATION_105_106,
AppDatabase.MIGRATION_106_107,
)
.build()
// close the database and release any stream resources when the test finishes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ChapterDaoTest {
@Test
fun insertSingleChapter() = runBlocking {
val chapter = Chapter(
index = 0,
episodeUuid = "episode-id",
startTimeMs = 0L,
)
Expand All @@ -51,6 +52,7 @@ class ChapterDaoTest {
@Test
fun doNotInsertTheSameChapterTwice() = runBlocking {
val chapter = Chapter(
index = 0,
episodeUuid = "episode-id",
startTimeMs = 0L,
)
Expand All @@ -65,6 +67,7 @@ class ChapterDaoTest {
fun insertMultipleChapters() = runBlocking {
val chapters = List(10) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
)
Expand All @@ -83,14 +86,17 @@ class ChapterDaoTest {

val chapters = listOf(
Chapter(
index = 0,
episodeUuid = id1,
startTimeMs = 0L,
),
Chapter(
index = 1,
episodeUuid = id1,
startTimeMs = 1L,
),
Chapter(
index = 0,
episodeUuid = id2,
startTimeMs = 0L,
),
Expand All @@ -106,6 +112,7 @@ class ChapterDaoTest {
fun replaceAllEmbeddedChapters() = runBlocking {
val chapters1 = List(10) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
isEmbedded = true,
Expand All @@ -115,6 +122,7 @@ class ChapterDaoTest {

val chapters2 = List(5) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
isEmbedded = true,
Expand All @@ -130,6 +138,7 @@ class ChapterDaoTest {
fun doNotReplaceEmptyEmbeddedChapters() = runBlocking {
val chapters = List(10) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
isEmbedded = true,
Expand All @@ -147,6 +156,7 @@ class ChapterDaoTest {
fun replaceNotEmbeddedWithEmbeddedChapters() = runBlocking {
val chapters1 = List(10) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
isEmbedded = false,
Expand All @@ -156,6 +166,7 @@ class ChapterDaoTest {

val chapters2 = List(5) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
isEmbedded = true,
Expand All @@ -171,6 +182,7 @@ class ChapterDaoTest {
fun doNotReplaceEmbeddedWithNotEmbeddedChapters() = runBlocking {
val chapters1 = List(5) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
isEmbedded = true,
Expand All @@ -180,6 +192,7 @@ class ChapterDaoTest {

val chapters2 = List(10) { index ->
Chapter(
index = index,
episodeUuid = "episode-id",
startTimeMs = 0L + index,
isEmbedded = false,
Expand All @@ -195,6 +208,7 @@ class ChapterDaoTest {
fun replaceNotEmbeddedChaptersIfExistingCountIsSmaller() = runBlocking {
val chapters1 = List(5) { index ->
Chapter(
index = index,
title = "$index-0",
episodeUuid = "episode-id",
startTimeMs = 0L + index,
Expand All @@ -204,6 +218,7 @@ class ChapterDaoTest {

val chapters2 = List(6) { index ->
Chapter(
index = index,
title = "$index-1",
episodeUuid = "episode-id",
startTimeMs = 0L + index,
Expand All @@ -219,6 +234,7 @@ class ChapterDaoTest {
fun replaceNotEmbeddedChaptersIfExistingCountIsEqual() = runBlocking {
val chapters1 = List(5) { index ->
Chapter(
index = index,
title = "$index-0",
episodeUuid = "episode-id",
startTimeMs = 0L + index,
Expand All @@ -228,6 +244,7 @@ class ChapterDaoTest {

val chapters2 = List(5) { index ->
Chapter(
index = index,
title = "$index-1",
episodeUuid = "episode-id",
startTimeMs = 0L + index,
Expand All @@ -243,6 +260,7 @@ class ChapterDaoTest {
fun doNotReplaceNotEmbeddedChaptersIfExistingCountIsLarger() = runBlocking {
val chapters1 = List(6) { index ->
Chapter(
index = index,
title = "$index-0",
episodeUuid = "episode-id",
startTimeMs = 0L + index,
Expand All @@ -252,6 +270,7 @@ class ChapterDaoTest {

val chapters2 = List(5) { index ->
Chapter(
index = index,
title = "$index-1",
episodeUuid = "episode-id",
startTimeMs = 0L + index,
Expand All @@ -270,20 +289,24 @@ class ChapterDaoTest {

val chapters1 = listOf(
Chapter(
index = 0,
episodeUuid = id1,
startTimeMs = 0L,
),
Chapter(
index = 1,
episodeUuid = id1,
startTimeMs = 1L,
),
)
val chapters2 = listOf(
Chapter(
index = 0,
episodeUuid = id2,
startTimeMs = 0L,
),
Chapter(
index = 1,
episodeUuid = id2,
startTimeMs = 1L,
),
Expand All @@ -305,6 +328,7 @@ class ChapterDaoTest {

val chaptersEpisode1 = List(3) { index ->
Chapter(
index = index,
episodeUuid = id1,
startTimeMs = 10L + index,
)
Expand All @@ -313,13 +337,15 @@ class ChapterDaoTest {
assertEquals(chaptersEpisode1, awaitItem())

val chapterEpisode2 = Chapter(
index = 0,
episodeUuid = id2,
startTimeMs = 0L,
)
chapterDao.replaceAllChapters(id2, listOf(chapterEpisode2))
expectNoEvents()

val chapterEpisode1 = Chapter(
index = 3,
episodeUuid = id1,
startTimeMs = 0L,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fun ChapterRow(
Spacer(Modifier.width(8.dp))
}
TextH50(
text = (chapter.index + 1).toString(),
text = (chapter.uiIndex).toString(),
color = textColor,
modifier = Modifier
.padding(horizontal = 12.dp),
Expand Down Expand Up @@ -247,7 +247,8 @@ private fun ChapterRowPreview(theme: Theme.ThemeType) {
endTime = 62.seconds,
url = "https://pocketcasts.com".toHttpUrlOrNull(),
imagePath = null,
index = 1,
index = 0,
uiIndex = 5,
)
AppThemeWithBackground(theme) {
ChaptersTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ private fun ArtworkSectionChapterPreview() {
startTime = 0.toDuration(DurationUnit.MINUTES),
imagePath = "",
url = "https://pocketcasts.com".toHttpUrlOrNull(),
index = 0,
uiIndex = 1,
),
isChapterArtworkVisible = true,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class ChaptersViewModelTest {
private val episode = PodcastEpisode(uuid = "id", publishedDate = Date())
private val chapters = Chapters(
listOf(
Chapter("1", 0.milliseconds, 100.milliseconds, selected = true, index = 0),
Chapter("2", 101.milliseconds, 200.milliseconds, selected = true, index = 1),
Chapter("3", 201.milliseconds, 300.milliseconds, selected = true, index = 2),
Chapter("1", 0.milliseconds, 100.milliseconds, selected = true, index = 0, uiIndex = 1),
Chapter("2", 101.milliseconds, 200.milliseconds, selected = true, index = 1, uiIndex = 2),
Chapter("3", 201.milliseconds, 300.milliseconds, selected = true, index = 2, uiIndex = 3),
),
)

Expand Down Expand Up @@ -267,7 +267,7 @@ class ChaptersViewModelTest {
)

val episode = PodcastEpisode(uuid = "id2", publishedDate = Date())
val chapter = Chapter("Chapter", startTime = 2.seconds, endTime = 3.seconds)
val chapter = Chapter("Chapter", startTime = 2.seconds, endTime = 3.seconds, index = 0, uiIndex = 1)
whenever(episodeManager.findEpisodeByUuid("id2")).thenReturn(episode)

chaptersViewModel.playChapter(chapter)
Expand Down
Loading