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

Fixed: Mul file not recognized as such and listing pretty much all languages. #3915

Merged
merged 1 commit into from
Jul 19, 2024
Merged
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
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 = [email protected]
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
}
}
}
}
Loading