mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Restoring the internal webbackforwardlist
This commit is contained in:
parent
64f1bc47e0
commit
5a7dc92e2c
19
.idea/codeStyles/Project.xml
generated
19
.idea/codeStyles/Project.xml
generated
@ -1,7 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<option name="USE_SAME_INDENTS" value="true" />
|
||||
<option name="IGNORE_SAME_INDENTS_FOR_LANGUAGES" value="true" />
|
||||
<option name="OTHER_INDENT_OPTIONS">
|
||||
<value>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
@ -34,25 +32,8 @@
|
||||
<option name="JD_PRESERVE_LINE_FEEDS" value="true" />
|
||||
</JavaCodeStyleSettings>
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value />
|
||||
</option>
|
||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||
<value>
|
||||
<package name="" alias="false" withSubpackages="true" />
|
||||
<package name="java" alias="false" withSubpackages="true" />
|
||||
<package name="javax" alias="false" withSubpackages="true" />
|
||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||
<package name="" alias="true" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
<ADDITIONAL_INDENT_OPTIONS fileType="php">
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
|
@ -29,7 +29,7 @@ abstract class PageHistoryRoomDao {
|
||||
@Insert
|
||||
abstract fun insertPageHistoryItem(pageHistoryRoomEntity: PageHistoryRoomEntity)
|
||||
|
||||
@Query("SELECT * FROM PageHistoryRoomEntity ORDER BY isForward ASC,timestamp DESC")
|
||||
@Query("SELECT * FROM PageHistoryRoomEntity ORDER BY isForward ASC,timestamp ASC")
|
||||
abstract fun getAllPageHistory(): Flowable<List<PageHistoryRoomEntity>>
|
||||
|
||||
@Query("Delete from PageHistoryRoomEntity")
|
||||
|
@ -1977,26 +1977,57 @@ abstract class CoreReaderFragment :
|
||||
private fun loadWebViewHistory(pageHistory: List<PageHistoryItem>) {
|
||||
val backStack = pageHistory.filter { !it.isForward }
|
||||
val forwardStack = pageHistory.filter(PageHistoryItem::isForward)
|
||||
activity.toast("${pageHistory.size} ${backStack.size}", Toast.LENGTH_LONG)
|
||||
val currentPage = getCurrentWebView()?.copyBackForwardList()?.currentItem?.url
|
||||
val currentWebView = getCurrentWebView() ?: return
|
||||
val currentPageUrl = currentWebView.copyBackForwardList().currentItem?.url
|
||||
|
||||
// Now, restore the back and forward history manually
|
||||
// First restore back history
|
||||
backStack.indices.reversed()
|
||||
.asSequence()
|
||||
.map { backStack[it] }
|
||||
.forEach { url -> loadUrlWithCurrentWebview(url.pageUrl) }
|
||||
// If backStack and forwardStack are empty, return
|
||||
if (backStack.isEmpty() && forwardStack.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
loadUrlWithCurrentWebview(currentPage)
|
||||
// Debug info: Toast to check the size of back and forward stack
|
||||
activity.toast(
|
||||
"${pageHistory.size} items loaded. Back stack size: ${backStack.size}",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
|
||||
forwardStack.indices.reversed()
|
||||
.asSequence()
|
||||
.map { forwardStack[it] }
|
||||
.forEach { url -> loadUrlWithCurrentWebview(url.pageUrl) }
|
||||
if (backStack.isNotEmpty()) {
|
||||
// Step 1: Load the first item immediately (0th index)
|
||||
currentWebView.loadUrl(backStack[0].pageUrl)
|
||||
}
|
||||
|
||||
repeat(
|
||||
forwardStack.indices.count()
|
||||
) { getCurrentWebView()?.goBack() }
|
||||
currentWebView.postDelayed({
|
||||
// Step 2: Clear WebView history after loading the first page
|
||||
currentWebView.clearHistory()
|
||||
|
||||
// Step 3: Load the remaining items from the backStack (starting from index 1)
|
||||
backStack.drop(1).forEachIndexed { index, page ->
|
||||
currentWebView.postDelayed({
|
||||
currentWebView.loadUrl(page.pageUrl)
|
||||
}, index * 500L) // Delay to load each page sequentially
|
||||
}
|
||||
|
||||
// Step 4: After loading the back stack, load the current page
|
||||
currentWebView.postDelayed({
|
||||
currentPageUrl?.let(::loadUrlWithCurrentWebview)
|
||||
}, backStack.size * 500L)
|
||||
|
||||
// Step 5: Load forward stack URLs sequentially
|
||||
currentWebView.postDelayed({
|
||||
forwardStack.forEachIndexed { index, page ->
|
||||
currentWebView.postDelayed({
|
||||
currentWebView.loadUrl(page.pageUrl)
|
||||
}, index * 500L) // Delay for loading forward stack
|
||||
}
|
||||
|
||||
// Step 6: After loading forward stack, go back to the current page
|
||||
currentWebView.postDelayed({
|
||||
repeat(forwardStack.size) {
|
||||
currentWebView.goBack()
|
||||
}
|
||||
}, forwardStack.size * 500L) // Delay based on forward stack size
|
||||
}, (backStack.size + 1) * 500L) // Delay based on the back stack size
|
||||
}, 500L) // Initial delay to allow the first page to load
|
||||
}
|
||||
|
||||
override fun onDataFetched(pageHistory: List<PageHistoryItem>) {
|
||||
@ -2009,9 +2040,9 @@ abstract class CoreReaderFragment :
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
repositoryActions?.loadPageHistory(this)
|
||||
updateBottomToolbarVisibility()
|
||||
updateNightMode()
|
||||
repositoryActions?.loadPageHistory(this)
|
||||
if (tts == null) {
|
||||
setUpTTS()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user