From 3c89a82c7a7dd2767db6ae603c2a44d7b028a217 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 15 Jul 2024 14:41:42 +0530 Subject: [PATCH] Fixed: Mul file not recognized as such and listing pretty much all languages. * Showing zim files in all available languages. --- .../kiwix/kiwixmobile/core/data/Repository.kt | 18 ++++++++-- .../core/entity/LibraryNetworkEntity.kt | 36 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) 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..bca9ca6111 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,9 +68,21 @@ class Repository @Inject internal constructor( .observeOn(mainThread) override fun booksOnDiskAsListItems(): Flowable> = bookDao.books() - .map { it.sortedBy { bookOnDisk -> bookOnDisk.book.language + bookOnDisk.book.title } } - .map { - HeaderizableList(it).foldOverAddingHeaders( + .map { books -> + books.flatMap { bookOnDisk -> + // Split languages if there are multiple, otherwise return the single book. Bug fix #3892 + if (bookOnDisk.book.language.contains(',')) { + bookOnDisk.book.language.split(',').map { lang -> + bookOnDisk.copy(book = bookOnDisk.book.copy(language = lang.trim())) + } + } else { + listOf(bookOnDisk) + } + }.distinctBy { it.book.language to it.book.title } + .sortedBy { it.book.language + it.book.title } + } + .map { items -> + HeaderizableList(items).foldOverAddingHeaders( { bookOnDisk -> LanguageItem(bookOnDisk.locale) }, { current, next -> current.locale.displayName != next.locale.displayName } ) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt index fe2613f114..05d6a1e019 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt @@ -94,5 +94,41 @@ class LibraryNetworkEntity { // Only use the book's id to generate a hash code override fun hashCode(): Int = id.hashCode() + + @Suppress("LongParameterList") + fun copy( + language: String = this.language, + title: String = this.title, + description: String? = this.description, + creator: String = this.creator, + publisher: String = this.publisher, + favicon: String = this.favicon, + faviconMimeType: String? = this.faviconMimeType, + date: String = this.date, + url: String? = this.url, + articleCount: String? = this.articleCount, + mediaCount: String? = this.mediaCount, + size: String = this.size, + bookName: String? = this.bookName, + tags: String? = this.tags + ): Book { + return Book().apply { + this.id = this@Book.id + this.title = title + this.description = description + this.language = language + this.creator = creator + this.publisher = publisher + this.favicon = favicon + this.faviconMimeType = faviconMimeType + this.date = date + this.url = url + this.articleCount = articleCount + this.mediaCount = mediaCount + this.size = size + this.bookName = bookName + this.tags = tags + } + } } }