From c4d0e66322416a810c72ecdf58535129d6487387 Mon Sep 17 00:00:00 2001 From: dece Date: Sun, 13 Feb 2022 18:14:24 +0100 Subject: [PATCH] PageAdapter: show URL schemes on links Currently only show them on absolute URLs and if they are not Gemini links (https, gopher, etc). --- .../dev/lowrespalmtree/comet/PageAdapter.kt | 9 +++++++ app/src/main/res/layout/gemtext_link.xml | 27 ++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt b/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt index ac44c1e..44751d7 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt @@ -154,10 +154,19 @@ class PageAdapter(private val listener: Listener) : } } is ContentBlock.Link -> { + val uri = Uri.parse(block.url) val label = block.label.ifBlank { block.url } (holder as ContentViewHolder.Link).binding.textView.text = label holder.binding.root.setOnClickListener { listener.onLinkClick(block.url) } + // Add the protocol on the right view if available and necessary (i.e. not Gemini). + if (uri.isAbsolute && uri.scheme != null && uri.scheme != "gemini") { + holder.binding.protocolView.text = uri.scheme + holder.binding.protocolView.visibility = View.VISIBLE + } else { + holder.binding.protocolView.visibility = View.GONE + } + // Color links differently if it has been already visited or not. val resources = holder.binding.root.context.resources holder.binding.textView.setTextColor( diff --git a/app/src/main/res/layout/gemtext_link.xml b/app/src/main/res/layout/gemtext_link.xml index a87096a..13a4b5f 100644 --- a/app/src/main/res/layout/gemtext_link.xml +++ b/app/src/main/res/layout/gemtext_link.xml @@ -1,6 +1,25 @@ - \ No newline at end of file + android:layout_height="wrap_content"> + + + + + +