mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 12:42:56 -04:00
Improved the updating bookmark list when saving/removing the bookmarks.
This commit is contained in:
parent
4f1a442854
commit
b12b654c6a
@ -19,11 +19,13 @@
|
|||||||
package org.kiwix.kiwixmobile.page.history
|
package org.kiwix.kiwixmobile.page.history
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.navigation.NavOptions
|
import androidx.navigation.NavOptions
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import androidx.test.core.app.ActivityScenario
|
||||||
import androidx.test.espresso.accessibility.AccessibilityChecks
|
import androidx.test.espresso.accessibility.AccessibilityChecks
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
@ -62,7 +64,7 @@ class NavigationHistoryTest : BaseActivityTest() {
|
|||||||
val retryRule = RetryRule()
|
val retryRule = RetryRule()
|
||||||
|
|
||||||
@get:Rule(order = COMPOSE_TEST_RULE_ORDER)
|
@get:Rule(order = COMPOSE_TEST_RULE_ORDER)
|
||||||
val composeTestRule = createAndroidComposeRule<KiwixMainActivity>()
|
val composeTestRule = createComposeRule()
|
||||||
|
|
||||||
private lateinit var kiwixMainActivity: KiwixMainActivity
|
private lateinit var kiwixMainActivity: KiwixMainActivity
|
||||||
|
|
||||||
@ -84,15 +86,19 @@ class NavigationHistoryTest : BaseActivityTest() {
|
|||||||
System.currentTimeMillis()
|
System.currentTimeMillis()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
kiwixMainActivity = composeTestRule.activity
|
activityScenario =
|
||||||
composeTestRule.runOnUiThread {
|
ActivityScenario.launch(KiwixMainActivity::class.java).apply {
|
||||||
|
moveToState(Lifecycle.State.RESUMED)
|
||||||
|
onActivity {
|
||||||
|
kiwixMainActivity = it
|
||||||
handleLocaleChange(
|
handleLocaleChange(
|
||||||
kiwixMainActivity,
|
it,
|
||||||
"en",
|
"en",
|
||||||
SharedPreferenceUtil(context)
|
SharedPreferenceUtil(context)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
AccessibilityChecks.enable().apply {
|
AccessibilityChecks.enable().apply {
|
||||||
@ -111,10 +117,13 @@ class NavigationHistoryTest : BaseActivityTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun navigationHistoryDialogTest() {
|
fun navigationHistoryDialogTest() {
|
||||||
|
activityScenario.onActivity {
|
||||||
|
kiwixMainActivity = it
|
||||||
|
}
|
||||||
composeTestRule.apply {
|
composeTestRule.apply {
|
||||||
waitForIdle()
|
waitForIdle()
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
activity.navigate(KiwixDestination.Library.route)
|
kiwixMainActivity.navigate(KiwixDestination.Library.route)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val loadFileStream =
|
val loadFileStream =
|
||||||
@ -142,7 +151,7 @@ class NavigationHistoryTest : BaseActivityTest() {
|
|||||||
val navOptions = NavOptions.Builder()
|
val navOptions = NavOptions.Builder()
|
||||||
.setPopUpTo(KiwixDestination.Reader.route, false)
|
.setPopUpTo(KiwixDestination.Reader.route, false)
|
||||||
.build()
|
.build()
|
||||||
activity.navigate(
|
kiwixMainActivity.navigate(
|
||||||
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()),
|
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()),
|
||||||
navOptions
|
navOptions
|
||||||
)
|
)
|
||||||
|
@ -301,6 +301,7 @@ class LibkiwixBookmarks @Inject constructor(
|
|||||||
bookmarkArray.mapNotNull { bookmark ->
|
bookmarkArray.mapNotNull { bookmark ->
|
||||||
// Check if the library contains the book associated with the bookmark.
|
// Check if the library contains the book associated with the bookmark.
|
||||||
val book =
|
val book =
|
||||||
|
runCatching {
|
||||||
if (isBookAlreadyExistInLibrary(bookmark.bookId)) {
|
if (isBookAlreadyExistInLibrary(bookmark.bookId)) {
|
||||||
library.getBookById(bookmark.bookId)
|
library.getBookById(bookmark.bookId)
|
||||||
} else {
|
} else {
|
||||||
@ -312,6 +313,7 @@ class LibkiwixBookmarks @Inject constructor(
|
|||||||
)
|
)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
}.getOrNull()
|
||||||
|
|
||||||
// Check if the book has an illustration of the specified size and encode it to Base64.
|
// Check if the book has an illustration of the specified size and encode it to Base64.
|
||||||
val favicon = book?.getFavicon()
|
val favicon = book?.getFavicon()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user