From 9c0603cf67a5cd6d1071c711b80b9ae2b1a1e0dd Mon Sep 17 00:00:00 2001 From: dece Date: Wed, 26 Jan 2022 20:01:18 +0100 Subject: [PATCH] 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. --- app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt | 5 +++++ app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt | 3 +++ 2 files changed, 8 insertions(+) diff --git a/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt b/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt index 9e37ed3..9561592 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/PageFragment.kt @@ -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) diff --git a/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt b/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt index 5034ab9..2288e77 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/PageViewModel.kt @@ -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 by lazy { MutableLiveData(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) {