Improved the updating bookmark list when saving/removing the bookmarks.

This commit is contained in:
MohitMaliFtechiz 2025-08-07 00:01:06 +05:30
parent 4f1a442854
commit b12b654c6a
2 changed files with 34 additions and 23 deletions

View File

@ -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,14 +86,18 @@ class NavigationHistoryTest : BaseActivityTest() {
System.currentTimeMillis() System.currentTimeMillis()
) )
} }
kiwixMainActivity = composeTestRule.activity activityScenario =
composeTestRule.runOnUiThread { ActivityScenario.launch(KiwixMainActivity::class.java).apply {
handleLocaleChange( moveToState(Lifecycle.State.RESUMED)
kiwixMainActivity, onActivity {
"en", kiwixMainActivity = it
SharedPreferenceUtil(context) handleLocaleChange(
) it,
} "en",
SharedPreferenceUtil(context)
)
}
}
} }
init { init {
@ -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
) )

View File

@ -301,17 +301,19 @@ 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 =
if (isBookAlreadyExistInLibrary(bookmark.bookId)) { runCatching {
library.getBookById(bookmark.bookId) if (isBookAlreadyExistInLibrary(bookmark.bookId)) {
} else { library.getBookById(bookmark.bookId)
Log.d( } else {
TAG, Log.d(
"Library does not contain the book for this bookmark:\n" + TAG,
"Book Title: ${bookmark.bookTitle}\n" + "Library does not contain the book for this bookmark:\n" +
"Bookmark URL: ${bookmark.url}" "Book Title: ${bookmark.bookTitle}\n" +
) "Bookmark URL: ${bookmark.url}"
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()