mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Fixed: Online library was not retrieving after clicking “Allow downloading via mobile network” in the confirmation dialog.
* Cause: The request object emitted after user confirmation was identical to the previous one, so the flow collector skipped it and the fetch was never triggered. * Solution: Added a `System.nanoTime()` field to the request to ensure a unique emission while still preserving existing values. * Refactored the `updateOnlineLibraryFilters updates onlineLibraryRequest` according to this new change.
This commit is contained in:
parent
26cc6faec8
commit
3b4a5d29fa
@ -155,7 +155,9 @@ class ZimManageViewModel @Inject constructor(
|
||||
val category: String? = null,
|
||||
val lang: String? = null,
|
||||
val isLoadMoreItem: Boolean,
|
||||
val page: Int
|
||||
val page: Int,
|
||||
// Bug Fix #4381
|
||||
val version: Long = System.nanoTime()
|
||||
)
|
||||
|
||||
data class OnlineLibraryResult(
|
||||
@ -371,7 +373,20 @@ class ZimManageViewModel @Inject constructor(
|
||||
category = newRequest.category ?: current.category,
|
||||
lang = newRequest.lang ?: current.lang,
|
||||
page = newRequest.page,
|
||||
isLoadMoreItem = newRequest.isLoadMoreItem
|
||||
isLoadMoreItem = newRequest.isLoadMoreItem,
|
||||
version = if (isUnitTestCase) {
|
||||
// In unit tests, we want predictable and testable values,
|
||||
// so use the provided version instead of a dynamic timestamp.
|
||||
newRequest.version
|
||||
} else {
|
||||
// Bug Fix #4381:
|
||||
// Force StateFlow to emit even if all other fields are unchanged.
|
||||
// Without this, identical requests may not trigger observers,
|
||||
// causing the UI not to refresh.
|
||||
// Using System.nanoTime() ensures a unique value each time,
|
||||
// guaranteeing that collectors receive an update.
|
||||
System.nanoTime()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -302,18 +302,22 @@ class ZimManageViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `updateOnlineLibraryFilters updates onlineLibraryRequest`() = runTest {
|
||||
val newRequest = ZimManageViewModel.OnlineLibraryRequest(
|
||||
query = "test",
|
||||
category = "cat",
|
||||
lang = "en",
|
||||
page = 2,
|
||||
isLoadMoreItem = true
|
||||
)
|
||||
viewModel.onlineLibraryRequest.test {
|
||||
skipItems(1)
|
||||
viewModel.updateOnlineLibraryFilters(newRequest)
|
||||
assertThat(awaitItem()).isEqualTo(newRequest)
|
||||
fun `updateOnlineLibraryFilters updates onlineLibraryRequest`() = flakyTest {
|
||||
runTest {
|
||||
viewModel.setIsUnitTestCase()
|
||||
val newRequest = ZimManageViewModel.OnlineLibraryRequest(
|
||||
query = "test",
|
||||
category = "cat",
|
||||
lang = "en",
|
||||
page = 2,
|
||||
isLoadMoreItem = true,
|
||||
version = 100L
|
||||
)
|
||||
viewModel.onlineLibraryRequest.test {
|
||||
skipItems(1)
|
||||
viewModel.updateOnlineLibraryFilters(newRequest)
|
||||
assertThat(awaitItem()).isEqualTo(newRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user