Merge pull request #4211 from kiwix/Fixes#4206

Keeping the downloading books always at the top.
This commit is contained in:
Kelson 2025-02-07 01:15:52 +01:00 committed by GitHub
commit 549bb5afb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 8 deletions

View File

@ -140,6 +140,8 @@ class DownloadTest : BaseActivityTest() {
stopDownloadIfAlreadyStarted()
downloadZimFile(smallestZimFileIndex)
try {
// Scroll to the top because now the downloading ZIM files are showing on the top.
scrollToZimFileIndex(0)
assertDownloadStart()
pauseDownload()
assertDownloadPaused()

View File

@ -488,24 +488,35 @@ class ZimManageViewModel @Inject constructor(
): List<LibraryListItem> {
val activeLanguageCodes = allLanguages.filter(Language::active)
.map(Language::languageCode)
val allBooks = libraryNetworkEntity.book!! - booksOnFileSystem.map(BookOnDisk::book).toSet()
val downloadingBooks = activeDownloads.mapNotNull { download ->
allBooks.firstOrNull { it.id == download.book.id }
}
val booksUnfilteredByLanguage =
applySearchFilter(
libraryNetworkEntity.book!! - booksOnFileSystem.map(BookOnDisk::book),
allBooks - downloadingBooks.toSet(),
filter
)
val booksWithActiveLanguages =
booksUnfilteredByLanguage.filter { activeLanguageCodes.contains(it.language) }
val booksWithoutActiveLanguages = booksUnfilteredByLanguage - booksWithActiveLanguages.toSet()
return createLibrarySection(
booksWithActiveLanguages,
downloadingBooks,
activeDownloads,
fileSystemState,
R.string.your_languages,
R.string.downloading,
Long.MAX_VALUE
) + createLibrarySection(
booksWithActiveLanguages,
emptyList(),
fileSystemState,
R.string.your_languages,
Long.MAX_VALUE - 1
) +
createLibrarySection(
booksUnfilteredByLanguage - booksWithActiveLanguages,
activeDownloads,
booksWithoutActiveLanguages,
emptyList(),
fileSystemState,
R.string.other_languages,
Long.MIN_VALUE

View File

@ -384,7 +384,7 @@ class ZimManageViewModelTest {
url = ""
)
val bookWithInactiveLanguage = book(
id = "3",
id = "4",
language = "inactiveLanguage",
url = ""
)
@ -415,10 +415,12 @@ class ZimManageViewModelTest {
viewModel.libraryItems.test()
.assertValue(
listOf(
LibraryListItem.DividerItem(Long.MAX_VALUE, R.string.your_languages),
LibraryListItem.DividerItem(Long.MAX_VALUE, R.string.downloading),
LibraryListItem.LibraryDownloadItem(downloadModel(book = bookDownloading)),
LibraryListItem.DividerItem(Long.MAX_VALUE - 1, R.string.your_languages),
LibraryListItem.BookItem(bookWithActiveLanguage, CanWrite4GbFile),
LibraryListItem.DividerItem(Long.MIN_VALUE, R.string.other_languages),
LibraryListItem.LibraryDownloadItem(downloadModel(book = bookDownloading))
LibraryListItem.BookItem(bookWithInactiveLanguage, CanWrite4GbFile)
)
)
}

View File

@ -181,6 +181,7 @@
<string name="do_not_ask_anymore">Do not ask anymore</string>
<string name="your_languages" tools:keep="@string/your_languages">Selected languages:</string>
<string name="other_languages" tools:keep="@string/other_languages">Other languages:</string>
<string name="downloading" tools:keep="@string/no_items_msg">Downloading:</string>
<string name="no_items_msg" tools:keep="@string/no_items_msg">No items available</string>
<string name="crash_title">Well… This is Embarrassing</string>
<string name="crash_description">It looks like we crashed.\n\nWould you mind helping us fix this problem by sending the following information?</string>