From b12b654c6a7bb2820fefe8c0e4d6562fee003d2d Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 7 Aug 2025 00:01:06 +0530 Subject: [PATCH] Improved the updating bookmark list when saving/removing the bookmarks. --- .../page/history/NavigationHistoryTest.kt | 33 ++++++++++++------- .../kiwixmobile/core/dao/LibkiwixBookmarks.kt | 24 +++++++------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt index 75364b5ab..2e0f7b79f 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt @@ -19,11 +19,13 @@ package org.kiwix.kiwixmobile.page.history 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.net.toUri +import androidx.lifecycle.Lifecycle import androidx.navigation.NavOptions import androidx.preference.PreferenceManager +import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.platform.app.InstrumentationRegistry @@ -62,7 +64,7 @@ class NavigationHistoryTest : BaseActivityTest() { val retryRule = RetryRule() @get:Rule(order = COMPOSE_TEST_RULE_ORDER) - val composeTestRule = createAndroidComposeRule() + val composeTestRule = createComposeRule() private lateinit var kiwixMainActivity: KiwixMainActivity @@ -84,14 +86,18 @@ class NavigationHistoryTest : BaseActivityTest() { System.currentTimeMillis() ) } - kiwixMainActivity = composeTestRule.activity - composeTestRule.runOnUiThread { - handleLocaleChange( - kiwixMainActivity, - "en", - SharedPreferenceUtil(context) - ) - } + activityScenario = + ActivityScenario.launch(KiwixMainActivity::class.java).apply { + moveToState(Lifecycle.State.RESUMED) + onActivity { + kiwixMainActivity = it + handleLocaleChange( + it, + "en", + SharedPreferenceUtil(context) + ) + } + } } init { @@ -111,10 +117,13 @@ class NavigationHistoryTest : BaseActivityTest() { @Test fun navigationHistoryDialogTest() { + activityScenario.onActivity { + kiwixMainActivity = it + } composeTestRule.apply { waitForIdle() runOnUiThread { - activity.navigate(KiwixDestination.Library.route) + kiwixMainActivity.navigate(KiwixDestination.Library.route) } } val loadFileStream = @@ -142,7 +151,7 @@ class NavigationHistoryTest : BaseActivityTest() { val navOptions = NavOptions.Builder() .setPopUpTo(KiwixDestination.Reader.route, false) .build() - activity.navigate( + kiwixMainActivity.navigate( KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), navOptions ) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt index 6310ce7b9..12e2ed305 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt @@ -301,17 +301,19 @@ class LibkiwixBookmarks @Inject constructor( bookmarkArray.mapNotNull { bookmark -> // Check if the library contains the book associated with the bookmark. val book = - if (isBookAlreadyExistInLibrary(bookmark.bookId)) { - library.getBookById(bookmark.bookId) - } else { - Log.d( - TAG, - "Library does not contain the book for this bookmark:\n" + - "Book Title: ${bookmark.bookTitle}\n" + - "Bookmark URL: ${bookmark.url}" - ) - null - } + runCatching { + if (isBookAlreadyExistInLibrary(bookmark.bookId)) { + library.getBookById(bookmark.bookId) + } else { + Log.d( + TAG, + "Library does not contain the book for this bookmark:\n" + + "Book Title: ${bookmark.bookTitle}\n" + + "Bookmark URL: ${bookmark.url}" + ) + null + } + }.getOrNull() // Check if the book has an illustration of the specified size and encode it to Base64. val favicon = book?.getFavicon()