PageFragment: show the URL being loaded

The URL is shown in italic to distinguish between the current URL and
the URL that is currently being loaded. Unsure that it is enough, it
does not look very good to me anyway.
This commit is contained in:
dece 2022-01-26 20:01:18 +01:00
parent e8283d2ed4
commit 9c0603cf67
2 changed files with 8 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package dev.lowrespalmtree.comet
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.graphics.Typeface
import android.net.Uri
import android.os.Bundle
import android.text.InputType
@ -136,9 +137,13 @@ class PageFragment : Fragment(), ContentAdapterListener {
PageViewModel.State.IDLE -> {
binding.contentProgressBar.hide()
binding.contentSwipeLayout.isRefreshing = false
binding.addressBar.setText(vm.currentUrl)
binding.addressBar.setTypeface(null, Typeface.NORMAL)
}
PageViewModel.State.CONNECTING -> {
binding.contentProgressBar.show()
binding.addressBar.setText(vm.loadingUrl?.toString() ?: "")
binding.addressBar.setTypeface(null, Typeface.ITALIC)
}
PageViewModel.State.RECEIVING -> {
binding.appBarLayout.setExpanded(true, true)

View file

@ -18,6 +18,8 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
ViewModel() {
/** Currently viewed page URL. */
var currentUrl: String = ""
/** Latest Uri requested using `sendGeminiRequest`. */
var loadingUrl: Uri? = null
/** Observable page viewer state. */
val state: MutableLiveData<State> by lazy { MutableLiveData<State>(State.IDLE) }
/** Observable page viewer lines (backed up by `linesList` but updated less often). */
@ -52,6 +54,7 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
*/
fun sendGeminiRequest(uri: Uri, connectionTimeout: Int, readTimeout: Int, redirects: Int = 0) {
Log.d(TAG, "sendRequest: URI \"$uri\"")
loadingUrl = uri
state.postValue(State.CONNECTING)
requestJob?.apply { if (isActive) cancel() }
requestJob = viewModelScope.launch(Dispatchers.IO) {