From 0f8b5937d0cea18d027aa53ada406334eb13fea3 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Sat, 29 Jun 2024 17:52:50 +0530 Subject: [PATCH] Fixed: Mul file not recognized as such and listing pretty much all languages. * ZIM files that have multiple languages are represented as a single string with comma-separated values (e.g., "eng,fra,vie,ita,ara,por"). We have modified the code to check for these cases and ensure that any ZIM file containing more than one language is shown under the "Multiple languages" section. --- .../kiwix/kiwixmobile/core/data/Repository.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt index 74595f8503..f86650578b 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt @@ -68,8 +68,22 @@ class Repository @Inject internal constructor( .observeOn(mainThread) override fun booksOnDiskAsListItems(): Flowable> = bookDao.books() - .map { it.sortedBy { bookOnDisk -> bookOnDisk.book.language + bookOnDisk.book.title } } .map { + it.map { bookOnDisk -> + // If the book contains more than one language, it comes in a single string with commas. + // e.g., "eng,fra,vie,ita,ara,por". Check if the language contains a comma, + // then move this book to the "Multiple languages" section. + if (bookOnDisk.book.language.contains(',')) { + bookOnDisk.copy().apply { + // Set the language to "mul" for the book so that it is shown + // in the "Multiple languages" section. + book.language = "mul" + } + } else { + bookOnDisk + } + }.sortedBy { bookOnDisk -> bookOnDisk.book.language + bookOnDisk.book.title } + }.map { HeaderizableList(it).foldOverAddingHeaders( { bookOnDisk -> LanguageItem(bookOnDisk.locale) }, { current, next -> current.locale.displayName != next.locale.displayName }