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

Keeping the downloading books always at the top. #4211

Merged
merged 4 commits into from
Feb 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class ZimManageViewModelTest {
url = ""
)
val bookWithInactiveLanguage = book(
id = "3",
id = "4",
language = "inactiveLanguage",
url = ""
)
Expand Down Expand Up @@ -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)
)
)
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down