PageViewModel: fix redirections w/o current URL

This commit is contained in:
dece 2022-02-17 17:57:46 +01:00
parent 2f2a70040f
commit 7658212a76
2 changed files with 9 additions and 5 deletions

View file

@ -185,7 +185,11 @@ class PageFragment : Fragment(), PageAdapter.Listener {
vm.visitedUrls.add(event.uri.toString()) vm.visitedUrls.add(event.uri.toString())
} }
is PageViewModel.RedirectEvent -> { is PageViewModel.RedirectEvent -> {
openUrl(event.uri, base = vm.currentUrl, redirections = event.redirects) openUrl(
event.uri,
base = vm.currentUrl.ifEmpty { event.sourceUri },
redirections = event.redirects
)
} }
is PageViewModel.FailureEvent -> { is PageViewModel.FailureEvent -> {
var message = event.details var message = event.details

View file

@ -74,7 +74,7 @@ class PageViewModel(
) : Event() ) : Event()
/** The server is redirecting us. */ /** The server is redirecting us. */
data class RedirectEvent(val uri: String, val redirects: Int) : Event() data class RedirectEvent(val uri: String, val sourceUri: String, val redirects: Int) : Event()
/** The server responded with a failure code or we encountered a local issue. */ /** The server responded with a failure code or we encountered a local issue. */
data class FailureEvent( data class FailureEvent(
@ -156,7 +156,7 @@ class PageViewModel(
Response.Code.Category.SUCCESS -> Response.Code.Category.SUCCESS ->
handleSuccessResponse(response, uri) handleSuccessResponse(response, uri)
Response.Code.Category.REDIRECT -> Response.Code.Category.REDIRECT ->
handleRedirectResponse(response, redirects = redirects + 1) handleRedirectResponse(response, uri, redirects = redirects + 1)
Response.Code.Category.SERVER_ERROR, Response.Code.Category.CLIENT_ERROR -> Response.Code.Category.SERVER_ERROR, Response.Code.Category.CLIENT_ERROR ->
handleErrorResponse(response) handleErrorResponse(response)
else -> else ->
@ -253,8 +253,8 @@ class PageViewModel(
handleSuccessGemtextResponse(response, uri) // TODO render plain text as... something else? handleSuccessGemtextResponse(response, uri) // TODO render plain text as... something else?
/** Notify observers that a redirect has been returned. */ /** Notify observers that a redirect has been returned. */
private fun handleRedirectResponse(response: Response, redirects: Int) { private fun handleRedirectResponse(response: Response, uri: Uri, redirects: Int) {
event.postValue(RedirectEvent(response.meta, redirects)) event.postValue(RedirectEvent(response.meta, uri.toString(), redirects))
} }
/** /**