From 7c969fe31d5ab3adf3ce954e898cab535245557e Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 5 Feb 2025 17:14:43 +0530 Subject: [PATCH 1/4] Keeping the downloading books always at the top. * Added a new "Downloading:" section in `OnlineFragment` to display currently downloading books at the top. * The language, and search filter will not affect this meaning if a user selects another language and searches any ZIM file via the search feature, the "Downloading:" section always shows on the top and the filter will be applied to the remaining books. --- .../zimManager/ZimManageViewModel.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt index c31a939fd..c200e8178 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt @@ -488,24 +488,35 @@ class ZimManageViewModel @Inject constructor( ): List { 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 From 079dd2f3c141c0aeea9c85b87993dd236f17ec43 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 5 Feb 2025 17:45:16 +0530 Subject: [PATCH 2/4] Added the "Downloading:" section title in string file. --- core/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 4d1062ace..bfac610fd 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -181,6 +181,7 @@ Do not ask anymore Selected languages: Other languages: + Downloading: No items available Well… This is Embarrassing It looks like we crashed.\n\nWould you mind helping us fix this problem by sending the following information? From a3341fc28003168d6ffb9921f322c0a40e00b6cc Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 6 Feb 2025 11:05:38 +0530 Subject: [PATCH 3/4] Refactored the `ZimManageViewModelTest` according to this new change. --- .../kiwixmobile/zimManager/ZimManageViewModelTest.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt index 333c6b315..02da4d628 100644 --- a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt +++ b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt @@ -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) ) ) } From 08f7751be60fdbba159203c1c367e011df5c5c71 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 6 Feb 2025 12:48:38 +0530 Subject: [PATCH 4/4] Fixed: The `DownloadTest` was failing. --- .../java/org/kiwix/kiwixmobile/download/DownloadTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt index 853474bd6..f9533c500 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt @@ -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()