diff --git a/app/src/main/java/app/opendocument/droid/ui/widget/PageView.kt b/app/src/main/java/app/opendocument/droid/ui/widget/PageView.kt index 0000a585c450..eabdd06b4c52 100644 --- a/app/src/main/java/app/opendocument/droid/ui/widget/PageView.kt +++ b/app/src/main/java/app/opendocument/droid/ui/widget/PageView.kt @@ -53,6 +53,9 @@ constructor(context: Context, attributeSet: AttributeSet?) : private var wasCommitCalled = false + /** What [loadUrl] was last given: the only page whose failure is this document's. */ + private var loadedUrl: String? = null + private var isBridgeAttached = false init { @@ -79,7 +82,12 @@ constructor(context: Context, attributeSet: AttributeSet?) : buggyWebViewHandler.postDelayed( { - if (!wasCommitCalled) { + // [url] and not whatever is loaded now: this callback can arrive after + // another page was asked for, which cancels the retries queued until + // then but not the one queued here. wasCommitCalled is about the page + // being waited on, so on its own it would answer for that other page + // and put this one back over it + if (!wasCommitCalled && url == loadedUrl) { crashManager.log(RuntimeException("commit was not called")) loadUrl(url) @@ -316,6 +324,14 @@ constructor(context: Context, attributeSet: AttributeSet?) : // the third party viewers an ONLINE result loads here. takes effect on the next load if (!url.startsWith(JAVASCRIPT_SCHEME)) { attachBridge(isOwnContent(url)) + + // a page that never committed left a retry waiting in onPageFinished. Now that another + // page has been asked for, that retry would load the old one back over it - and the + // document it belonged to has taken its server with it, so what it would find there is + // a 404 this page is then given up on for + buggyWebViewHandler.removeCallbacksAndMessages(null) + + loadedUrl = url } super.loadUrl(url) @@ -339,6 +355,13 @@ constructor(context: Context, attributeSet: AttributeSet?) : return } + // and only the page being shown. A request made for a document already closed can still be + // answered here, long after the page moved on, and the document on screen is not the one + // that failed + if (loadedUrl != null && url.toString() != loadedUrl) { + return + } + documentFragment.onPageFailed() }