From a10987d6ec53887b600f74e49fad976b8ab8c0d0 Mon Sep 17 00:00:00 2001 From: Paul Woitaschek Date: Wed, 19 Jul 2017 22:24:05 +0200 Subject: [PATCH] Use lists instead of varargs which have to be spread --- .../features/chapterReader/matroska/MatroskaChapter.kt | 2 +- .../chapterReader/matroska/MatroskaChapterFlattener.kt | 4 ++-- .../chapterReader/matroska/MatroskaChapterReader.kt | 2 +- .../features/chapterReader/MatroskaChapterReadingTest.kt | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapter.kt b/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapter.kt index 76b07ddf71..4c8f1bac2c 100644 --- a/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapter.kt +++ b/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapter.kt @@ -6,7 +6,7 @@ data class MatroskaChapter( val children: List ) { - fun getName(vararg preferredLanguages: String): String? = preferredLanguages + fun getName(preferredLanguages: List = emptyList()): String? = preferredLanguages .mapNotNull { language -> names.find { language in it.languages } ?.name diff --git a/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterFlattener.kt b/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterFlattener.kt index b09e9fcd13..5ef409b9dc 100644 --- a/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterFlattener.kt +++ b/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterFlattener.kt @@ -5,7 +5,7 @@ import android.util.SparseArray object MatroskaChapterFlattener { - fun toSparseArray(list: List, vararg preferredLanguages: String): SparseArray { + fun toSparseArray(list: List, preferredLanguages: List): SparseArray { val res = SparseArray() fun addChapter(chapters: List, depth: Int) { @@ -14,7 +14,7 @@ object MatroskaChapterFlattener { if (i == 0) depth else 0 // Simple hack with adding depth is needed because chapter // and it's first sub-chapter have usually the same starting time. - val name = "+ ".repeat(depth) + (chapter.getName(*preferredLanguages) ?: "Chapter ${i + 1}") + val name = "+ ".repeat(depth) + (chapter.getName(preferredLanguages) ?: "Chapter ${i + 1}") res.put(duration, name) addChapter(chapter.children, depth + 1) } diff --git a/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterReader.kt b/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterReader.kt index 88376c1568..40b3c7d007 100644 --- a/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterReader.kt +++ b/audiobook/src/main/java/de/ph1b/audiobook/features/chapterReader/matroska/MatroskaChapterReader.kt @@ -12,7 +12,7 @@ object MatroskaChapterReader { fun read(file: File): SparseArray { try { val chapters = ReadAsMatroskaChapters.read(file) - return MatroskaChapterFlattener.toSparseArray(chapters, Locale.getDefault().isO3Language, "eng") + return MatroskaChapterFlattener.toSparseArray(chapters, listOf(Locale.getDefault().isO3Language, "eng")) } catch (ex: RuntimeException) { // JEBML documentation just say's that it throws RuntimeException. // For example NullPointerException is thrown if unknown EBML Element diff --git a/audiobook/src/test/java/de/ph1b/audiobook/features/chapterReader/MatroskaChapterReadingTest.kt b/audiobook/src/test/java/de/ph1b/audiobook/features/chapterReader/MatroskaChapterReadingTest.kt index bcc24bc3b4..c280e20826 100644 --- a/audiobook/src/test/java/de/ph1b/audiobook/features/chapterReader/MatroskaChapterReadingTest.kt +++ b/audiobook/src/test/java/de/ph1b/audiobook/features/chapterReader/MatroskaChapterReadingTest.kt @@ -56,13 +56,13 @@ class MatroskaChapterReadingTest { MatroskaChapterName("サブパート1", setOf("jpn")) ), listOf()) assertThat(chapter.getName()).isEqualTo("Podczęść 1") - assertThat(chapter.getName("ger", "jpn")).isEqualTo("Subpart 1") - assertThat(chapter.getName("ind", "kac", "jpn", "eng")).isEqualTo("サブパート1") + assertThat(chapter.getName(listOf("ger", "jpn"))).isEqualTo("Subpart 1") + assertThat(chapter.getName(listOf("ind", "kac", "jpn", "eng"))).isEqualTo("サブパート1") } @Test fun flattenMatroskaChapterListTest() { - assertThat(MatroskaChapterFlattener.toSparseArray(testFileMatroskaChapters, "pol", "eng") + assertThat(MatroskaChapterFlattener.toSparseArray(testFileMatroskaChapters, listOf("pol", "eng")) .toMap()).isEqualTo(testFileChapters) }