Reverted link buttons. They broke too many things.

This commit is contained in:
Corewala 2022-01-18 14:34:37 -05:00
parent 52f8dfcc72
commit 441aff3c98
12 changed files with 212 additions and 172 deletions

View File

@ -15,7 +15,7 @@ Buran is a simple Gemini protocol browser for Android.
- [ ] Keystore generator and catalog
- [ ] Option to require password or biometric authentication
- [ ] Color palette interface for picking background and accent colors
- [X] Option to render links as buttons
- [ ] Option to render links as buttons
- [X] Inline rendering of images
- [ ] Page navigation feature
- [ ] Update notifier

View File

@ -274,19 +274,18 @@ class GemActivity : AppCompatActivity() {
else -> hideClientCertShield()
}
val hideCodeBlocks = prefs.getBoolean(
"collapse_code_blocks",
false
)
adapter.hideCodeBlocks(hideCodeBlocks)
val showInlineIcons = prefs.getBoolean(
"show_inline_icons",
true
)
adapter.inlineIcons(showInlineIcons)
val showLinkButtons = prefs.getBoolean(
"show_link_buttons",
true
)
adapter.linkButtons(showLinkButtons)
val showInlineImages = prefs.getBoolean(
"show_inline_images",
true

View File

@ -10,14 +10,14 @@ abstract class AbstractGemtextAdapter(
): RecyclerView.Adapter<GmiViewHolder>() {
var showInlineIcons: Boolean = false
var showLinkButtons: Boolean = false
var hideCodeBlocks: Boolean = false
var showInlineImages: Boolean = false
abstract fun render(lines: List<String>)
abstract fun loadImage(position: Int, cacheUri: Uri)
abstract fun inlineIcons(visible: Boolean)
abstract fun inlineImages(visible: Boolean)
abstract fun linkButtons(visible: Boolean)
abstract fun hideCodeBlocks(hideCodeBlocks: Boolean)
abstract fun inferTitle(): String?

View File

@ -8,13 +8,11 @@ import android.view.ViewGroup
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.gemtext_code_block.view.*
import kotlinx.android.synthetic.main.gemtext_image_link.view.*
import kotlinx.android.synthetic.main.gemtext_link.view.gemtext_text_link
import kotlinx.android.synthetic.main.gemtext_text.view.*
import corewala.buran.R
import corewala.endsWithImage
import corewala.visible
import kotlinx.android.synthetic.main.gemtext_image_link.view.gemtext_link_button
import kotlinx.android.synthetic.main.gemtext_link.view.*
import kotlinx.android.synthetic.main.gemtext_link.view.gemtext_text_link
import java.net.URI
class GemtextAdapter(
@ -95,6 +93,27 @@ class GemtextAdapter(
}else{
holder.itemView.gemtext_text_monospace_textview.text = line.substring(3)
}
if(hideCodeBlocks){
holder.itemView.show_code_block.setText(R.string.show_code)//reset for recycling
altText?.let{
holder.itemView.show_code_block.append(": $altText")
}
holder.itemView.show_code_block.visible(true)
holder.itemView.show_code_block.paint.isUnderlineText = true
holder.itemView.show_code_block.setOnClickListener {
setupCodeBlockToggle(holder, altText)
}
holder.itemView.gemtext_text_monospace_textview.visible(false)
when {
showInlineIcons -> holder.itemView.show_code_block.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.vector_code, 0)
else -> holder.itemView.show_code_block.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
}
}else{
holder.itemView.show_code_block.visible(false)
holder.itemView.gemtext_text_monospace_textview.visible(true)
}
}
is GmiViewHolder.Quote -> holder.itemView.gemtext_text_monospace_textview.text = line.substring(1).trim()
is GmiViewHolder.H1 -> {
@ -123,35 +142,19 @@ class GemtextAdapter(
if(linkParts.size > 1) linkName = linkParts[1]
val displayText = linkName
holder.itemView.gemtext_text_link.text = displayText
holder.itemView.gemtext_text_link.paint.isUnderlineText = true
when {
showLinkButtons -> {
holder.itemView.gemtext_text_link.visible(false)
holder.itemView.gemtext_link_button.visible(true)
holder.itemView.gemtext_link_button.text = displayText
} else -> {
holder.itemView.gemtext_link_button.visible(false)
holder.itemView.gemtext_text_link.visible(true)
holder.itemView.gemtext_text_link.text = displayText
holder.itemView.gemtext_text_link.paint.isUnderlineText = true
}
}
when {
showInlineIcons && linkParts.first().startsWith("http") -> {
holder.itemView.gemtext_text_link.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.vector_open_browser, 0)
holder.itemView.gemtext_link_button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.vector_open_browser, 0)
}
else -> {
holder.itemView.gemtext_text_link.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
holder.itemView.gemtext_link_button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
}
showInlineIcons && linkParts.first().startsWith("http") -> holder.itemView.gemtext_text_link.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.vector_open_browser, 0)
else -> holder.itemView.gemtext_text_link.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
}
holder.itemView.gemtext_text_link.setOnClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User clicked link: $uri")
onLink(uri, false, holder.adapterPosition)
}
holder.itemView.gemtext_text_link.setOnLongClickListener {
val uri = getUri(lines[holder.adapterPosition])
@ -159,17 +162,6 @@ class GemtextAdapter(
onLink(uri, true, holder.adapterPosition)
true
}
holder.itemView.gemtext_link_button.setOnClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User clicked link: $uri")
onLink(uri, false, holder.adapterPosition)
}
holder.itemView.gemtext_link_button.setOnLongClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User long-clicked link: $uri")
onLink(uri, true, holder.adapterPosition)
true
}
}
is GmiViewHolder.ImageLink -> {
@ -179,20 +171,8 @@ class GemtextAdapter(
if(linkParts.size > 1) linkName = linkParts[1]
val displayText = linkName
when {
showLinkButtons -> {
holder.itemView.gemtext_text_link.visible(false)
holder.itemView.gemtext_link_button.visible(true)
holder.itemView.gemtext_link_button.text = displayText
} else -> {
holder.itemView.gemtext_link_button.visible(false)
holder.itemView.gemtext_text_link.visible(true)
holder.itemView.gemtext_text_link.text = displayText
holder.itemView.gemtext_text_link.paint.isUnderlineText = true
}
}
holder.itemView.gemtext_text_link.text = displayText
holder.itemView.gemtext_text_link.paint.isUnderlineText = true
holder.itemView.gemtext_text_link.setOnClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User clicked link: $uri")
@ -204,17 +184,6 @@ class GemtextAdapter(
onLink(uri, true, holder.adapterPosition)
true
}
holder.itemView.gemtext_link_button.setOnClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User clicked link: $uri")
onLink(uri, false, holder.adapterPosition)
}
holder.itemView.gemtext_link_button.setOnLongClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User long-clicked link: $uri")
onLink(uri, true, holder.adapterPosition)
true
}
holder.itemView.gemtext_inline_image.setOnClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User clicked image: $uri")
@ -246,14 +215,28 @@ class GemtextAdapter(
}
when {
showInlineIcons -> {
holder.itemView.gemtext_text_link.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.vector_photo, 0)
holder.itemView.gemtext_link_button.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.vector_photo, 0)
}
else -> {
holder.itemView.gemtext_text_link.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
holder.itemView.gemtext_link_button.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
}
showInlineIcons -> holder.itemView.gemtext_text_link.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.vector_photo, 0)
else -> holder.itemView.gemtext_text_link.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
}
}
}
}
private fun setupCodeBlockToggle(holder: GmiViewHolder.Code, altText: String?) {
//val adapterPosition = holder.adapterPosition
when {
holder.itemView.gemtext_text_monospace_textview.isVisible -> {
holder.itemView.show_code_block.setText(R.string.show_code)
holder.itemView.gemtext_text_monospace_textview.visible(false)
altText?.let{
holder.itemView.show_code_block.append(": $altText")
}
}
else -> {
holder.itemView.show_code_block.setText(R.string.hide_code)
holder.itemView.gemtext_text_monospace_textview.visible(true)
altText?.let{
holder.itemView.show_code_block.append(": $altText")
}
}
}
@ -287,13 +270,13 @@ class GemtextAdapter(
notifyDataSetChanged()
}
override fun linkButtons(visible: Boolean){
this.showLinkButtons = visible
notifyDataSetChanged()
}
override fun inlineImages(visible: Boolean){
this.showInlineImages = visible
notifyDataSetChanged()
}
override fun hideCodeBlocks(hideCodeBlocks: Boolean) {
this.hideCodeBlocks = hideCodeBlocks
notifyDataSetChanged()
}
}

View File

@ -179,19 +179,24 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
accessibilityCategory.title = getString(R.string.accessibility)
screen.addPreference(accessibilityCategory)
//Accessibility - code blocks
val aboutCodeBlocksPref = Preference(context)
aboutCodeBlocksPref.summary = getString(R.string.collapse_code_blocks_about)
aboutCodeBlocksPref.isPersistent = false
aboutCodeBlocksPref.isSelectable = false
accessibilityCategory.addPreference(aboutCodeBlocksPref)
val collapseCodeBlocksPreference = SwitchPreferenceCompat(context)
collapseCodeBlocksPreference.key = "collapse_code_blocks"
collapseCodeBlocksPreference.title = getString(R.string.collapse_code_blocks)
accessibilityCategory.addPreference(collapseCodeBlocksPreference)
//Accessibility - inline icons
val showInlineIconsPreference = SwitchPreferenceCompat(context)
showInlineIconsPreference.setDefaultValue(true)
showInlineIconsPreference.key = "show_inline_icons"
showInlineIconsPreference.title = getString(R.string.show_inline_icons)
accessibilityCategory.addPreference(showInlineIconsPreference)
//Accessibility - full-width buttons
val showLinkButtonsPreference = SwitchPreferenceCompat(context)
showLinkButtonsPreference.setDefaultValue(false)
showLinkButtonsPreference.key = "show_link_buttons"
showLinkButtonsPreference.title = getString(R.string.show_link_buttons)
accessibilityCategory.addPreference(showLinkButtonsPreference)
}
private fun buildClientCertificateSection(context: Context?, appCategory: PreferenceCategory) {

View File

@ -9,12 +9,27 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.appcompat.widget.AppCompatTextView
android:textSize="@dimen/default_text_size"
android:textColor="@color/stroke"
android:id="@+id/show_code_block"
android:background="?android:selectableItemBackground"
android:focusable="true" android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_small"
android:layout_marginBottom="@dimen/default_margin_small"
android:text="@string/show_code"
android:drawablePadding="4.0dip"
/>
<HorizontalScrollView
android:background="@drawable/block_background"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/def_quarter"
android:layout_marginBottom="@dimen/def_quarter">
android:layout_marginBottom="@dimen/def_quarter"
android:layout_below="@id/show_code_block">
<androidx.appcompat.widget.AppCompatTextView
android:scrollbarStyle="insideOverlay"

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.button.MaterialButton
android:id="@+id/gemtext_text_link"
android:textColor="@color/stroke"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:drawableEnd="@drawable/vector_photo"
android:drawablePadding="4dp"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:padding="@dimen/accessibility_button_padding"
app:cornerRadius="@dimen/default_margin_big"
android:textAllCaps="false"
tools:text="an image"
android:backgroundTint="@color/accessibility_button_background"
android:textAlignment="viewStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.cardview.widget.CardView
android:id="@+id/rounded_image_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="@dimen/default_margin_big"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:visibility="gone"
android:layout_below="@+id/gemtext_text_link">
<ImageView
android:id="@+id/gemtext_inline_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>
</androidx.cardview.widget.CardView>
</RelativeLayout>

View File

@ -1,24 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/gemtext_text_link"
android:textColor="@color/stroke"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:drawableEnd="@drawable/vector_photo"
android:drawablePadding="4dp"
android:background="?android:attr/selectableItemBackground"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
tools:text="an image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/gemtext_text_link"
android:textColor="@color/stroke"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:drawableEnd="@drawable/vector_photo"
android:drawablePadding="4dp"
android:background="?android:attr/selectableItemBackground"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
tools:text="an image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<androidx.cardview.widget.CardView
android:id="@+id/rounded_image_frame"
@ -39,25 +39,4 @@
android:adjustViewBounds="true"/>
</androidx.cardview.widget.CardView>
<com.google.android.material.button.MaterialButton
android:id="@+id/gemtext_link_button"
android:textColor="@color/stroke"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:drawableEnd="@drawable/vector_photo"
android:drawablePadding="4dp"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:padding="@dimen/accessibility_button_padding"
app:cornerRadius="@dimen/default_margin_big"
android:textAllCaps="false"
tools:text="an image"
android:backgroundTint="@color/accessibility_button_background"
android:textAlignment="viewStart"
android:visibility="gone"
android:layout_above="@id/rounded_image_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>

View File

@ -1,45 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/gemtext_text_link"
android:textColor="@color/stroke"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
tools:text="a link"
android:layout_marginTop="@dimen/default_margin_small"
android:layout_marginBottom="@dimen/default_margin_small"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:drawablePadding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/gemtext_link_button"
android:textColor="@color/stroke"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin_small"
android:layout_marginBottom="@dimen/default_margin_small"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:textAlignment="viewStart"
android:padding="@dimen/accessibility_button_padding"
app:cornerRadius="@dimen/default_margin_big"
android:textAllCaps="false"
tools:text="a link"
android:backgroundTint="@color/accessibility_button_background"
android:drawablePadding="4dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:id="@+id/gemtext_text_link"
android:textColor="@color/stroke"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin_small"
android:layout_marginBottom="@dimen/default_margin_small"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:drawablePadding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.button.MaterialButton
android:id="@+id/gemtext_text_link"
android:textColor="@color/stroke"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin_small"
android:layout_marginBottom="@dimen/default_margin_small"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:textAlignment="viewStart"
android:padding="@dimen/accessibility_button_padding"
app:cornerRadius="@dimen/default_margin_big"
android:textAllCaps="false"
tools:text="a link"
android:backgroundTint="@color/accessibility_button_background"
android:drawablePadding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>

View File

@ -68,11 +68,14 @@
<string name="history_cleared">Historique vidé</string>
<string name="runtime_cache_cleared">Cache d\'exécution vidé</string>
<string name="show_inline_icons">Icônes de lien en ligne</string>
<string name="show_link_buttons">Afficher boutons de liens</string>
<string name="bookmarks_empty">Vous n\'avez encore aucun marque-pages</string>
<string name="import_bookmarks">Importer des marque-pages</string>
<string name="export_bookmarks">Exporter des marque-pages</string>
<string name="accessibility">Accessibilité</string>
<string name="collapse_code_blocks">Cacher les rectangles pleins</string>
<string name="show_code">Montrer le code</string>
<string name="hide_code">Cacher le code</string>
<string name="collapse_code_blocks_about">Les capsules Gemini utilisent malheureusement souvent des en-têtes en ascii-art rendus avec des rectangles pleins à largeur fixe. Quand les rectangles pleins sont cachés, ils nécessitent un clic pour être affichés, ce qui améliore l\'ergonomie en cas d\'utilisation d\'un lecteur d\'écran.</string>
<string name="prefs_override_page_background">Utiliser une couleur d\'arrière-plan personnalisée</string>
<string name="prefs_override_page_background_dialog_title">Couleur d\'arrière-plan</string>
<string name="prefs_override_page_background_title">Couleur d\'arrière-plan</string>

View File

@ -68,11 +68,14 @@
<string name="history_cleared">History cleared</string>
<string name="runtime_cache_cleared">Runtime cache cleared</string>
<string name="show_inline_icons">Inline link icons</string>
<string name="show_link_buttons">Show link buttons</string>
<string name="bookmarks_empty">You don\'t have any bookmarks yet</string>
<string name="import_bookmarks">Import bookmarks</string>
<string name="export_bookmarks">Export bookmarks</string>
<string name="accessibility">Accessibility</string>
<string name="collapse_code_blocks">Hide code blocks</string>
<string name="show_code">Show code</string>
<string name="hide_code">Hide code</string>
<string name="collapse_code_blocks_about">Gemini capsules unfortunately often use ascii-art headers rendered in monospaced code blocks. When code blocks are hidden they require a tap to expand which improves usability when using a screen reader.</string>
<string name="prefs_override_page_background">Use custom page background colour</string>
<string name="prefs_override_page_background_dialog_title">Page Background Colour</string>
<string name="prefs_override_page_background_title">Page Background Colour</string>