Skip to content

Commit

Permalink
Fixed: Mul file not recognized as such and listing pretty much all la…
Browse files Browse the repository at this point in the history
…nguages.

* Showing zim files in all available languages.
  • Loading branch information
MohitMaliDeveloper authored and kelson42 committed Jul 19, 2024
1 parent ca19ec2 commit 3c89a82
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,21 @@ class Repository @Inject internal constructor(
.observeOn(mainThread)

override fun booksOnDiskAsListItems(): Flowable<List<BooksOnDiskListItem>> = bookDao.books()
.map { it.sortedBy { bookOnDisk -> bookOnDisk.book.language + bookOnDisk.book.title } }
.map {
HeaderizableList<BooksOnDiskListItem, BookOnDisk, LanguageItem>(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<BooksOnDiskListItem, BookOnDisk, LanguageItem>(items).foldOverAddingHeaders(
{ bookOnDisk -> LanguageItem(bookOnDisk.locale) },
{ current, next -> current.locale.displayName != next.locale.displayName }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

0 comments on commit 3c89a82

Please sign in to comment.