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 category: String? = null,
|
||||||
val lang: String? = null,
|
val lang: String? = null,
|
||||||
val isLoadMoreItem: Boolean,
|
val isLoadMoreItem: Boolean,
|
||||||
val page: Int
|
val page: Int,
|
||||||
|
// Bug Fix #4381
|
||||||
|
val version: Long = System.nanoTime()
|
||||||
)
|
)
|
||||||
|
|
||||||
data class OnlineLibraryResult(
|
data class OnlineLibraryResult(
|
||||||
@ -371,7 +373,20 @@ class ZimManageViewModel @Inject constructor(
|
|||||||
category = newRequest.category ?: current.category,
|
category = newRequest.category ?: current.category,
|
||||||
lang = newRequest.lang ?: current.lang,
|
lang = newRequest.lang ?: current.lang,
|
||||||
page = newRequest.page,
|
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
|
@Test
|
||||||
fun `updateOnlineLibraryFilters updates onlineLibraryRequest`() = runTest {
|
fun `updateOnlineLibraryFilters updates onlineLibraryRequest`() = flakyTest {
|
||||||
val newRequest = ZimManageViewModel.OnlineLibraryRequest(
|
runTest {
|
||||||
query = "test",
|
viewModel.setIsUnitTestCase()
|
||||||
category = "cat",
|
val newRequest = ZimManageViewModel.OnlineLibraryRequest(
|
||||||
lang = "en",
|
query = "test",
|
||||||
page = 2,
|
category = "cat",
|
||||||
isLoadMoreItem = true
|
lang = "en",
|
||||||
)
|
page = 2,
|
||||||
viewModel.onlineLibraryRequest.test {
|
isLoadMoreItem = true,
|
||||||
skipItems(1)
|
version = 100L
|
||||||
viewModel.updateOnlineLibraryFilters(newRequest)
|
)
|
||||||
assertThat(awaitItem()).isEqualTo(newRequest)
|
viewModel.onlineLibraryRequest.test {
|
||||||
|
skipItems(1)
|
||||||
|
viewModel.updateOnlineLibraryFilters(newRequest)
|
||||||
|
assertThat(awaitItem()).isEqualTo(newRequest)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user