Compare commits

..

No commits in common. "44aa42e67d1d85ef4abbdca8a3f9b1d079d2b8a8" and "d9802dc44dee8bf98a72882b8dd75f712c1372be" have entirely different histories.

3 changed files with 8 additions and 12 deletions

View file

@ -28,7 +28,7 @@ object History {
suspend fun update(vararg entries: HistoryEntry)
}
suspend fun record(uri: String, title: String? = null) {
suspend fun record(uri: String, title: String?) {
val now = System.currentTimeMillis()
val dao = Database.INSTANCE.historyEntryDao()
val entry = dao.get(uri)

View file

@ -63,7 +63,7 @@ class PageFragment : Fragment(), PageAdapter.Listener {
Log.d(TAG, "onViewCreated: reuse current URL, probably fragment recreation")
} else if (vm.visitedUrls.isEmpty()) {
Log.d(TAG, "onViewCreated: no current URL, open home if configured")
Preferences.getHomeUrl(requireContext())?.let { if (it.isNotBlank()) openUrl(it) }
Preferences.getHomeUrl(requireContext())?.let { openUrl(it) }
}
}
@ -182,13 +182,10 @@ class PageFragment : Fragment(), PageAdapter.Listener {
})
}
.show()
vm.visitedUrls.add(event.uri.toString())
}
is PageViewModel.RedirectEvent -> {
openUrl(
event.uri,
base = vm.currentUrl.ifEmpty { event.sourceUri },
redirections = event.redirects
)
openUrl(event.uri, base = vm.currentUrl, redirections = event.redirects)
}
is PageViewModel.FailureEvent -> {
var message = event.details

View file

@ -74,7 +74,7 @@ class PageViewModel(
) : Event()
/** The server is redirecting us. */
data class RedirectEvent(val uri: String, val sourceUri: String, val redirects: Int) : Event()
data class RedirectEvent(val uri: String, val redirects: Int) : Event()
/** The server responded with a failure code or we encountered a local issue. */
data class FailureEvent(
@ -156,7 +156,7 @@ class PageViewModel(
Response.Code.Category.SUCCESS ->
handleSuccessResponse(response, uri)
Response.Code.Category.REDIRECT ->
handleRedirectResponse(response, uri, redirects = redirects + 1)
handleRedirectResponse(response, redirects = redirects + 1)
Response.Code.Category.SERVER_ERROR, Response.Code.Category.CLIENT_ERROR ->
handleErrorResponse(response)
else ->
@ -253,8 +253,8 @@ class PageViewModel(
handleSuccessGemtextResponse(response, uri) // TODO render plain text as... something else?
/** Notify observers that a redirect has been returned. */
private fun handleRedirectResponse(response: Response, uri: Uri, redirects: Int) {
event.postValue(RedirectEvent(response.meta, uri.toString(), redirects))
private fun handleRedirectResponse(response: Response, redirects: Int) {
event.postValue(RedirectEvent(response.meta, redirects))
}
/**
@ -311,7 +311,6 @@ class PageViewModel(
onSuccess = { mediaUri ->
event.postValue(DownloadCompletedEvent(mediaUri, mimeType))
state.postValue(State.IDLE)
viewModelScope.launch(Dispatchers.IO) { History.record(uri.toString()) }
},
onError = { msg -> signalError("Download failed: $msg") }
)