Link buttons

This commit is contained in:
Corewala 2022-01-26 20:21:43 -05:00
parent 9ed4c057b1
commit 2ee80fadd9
10 changed files with 152 additions and 98 deletions

View File

@ -286,6 +286,13 @@ class GemActivity : AppCompatActivity() {
)
adapter.inlineIcons(showInlineIcons)
val showLinkButtons = prefs.getBoolean(
"show_link_buttons",
true
)
adapter.linkButtons(showLinkButtons)
val showInlineImages = prefs.getBoolean(
"show_inline_images",
true

View File

@ -11,6 +11,7 @@ abstract class AbstractGemtextAdapter(
var showInlineIcons: Boolean = false
var hideCodeBlocks: Boolean = false
var showLinkButtons: Boolean = false
var showInlineImages: Boolean = false
abstract fun render(lines: List<String>)
@ -18,6 +19,7 @@ abstract class AbstractGemtextAdapter(
abstract fun inlineIcons(visible: Boolean)
abstract fun inlineImages(visible: Boolean)
abstract fun hideCodeBlocks(hideCodeBlocks: Boolean)
abstract fun linkButtons(visible: Boolean)
abstract fun inferTitle(): String?

View File

@ -142,8 +142,30 @@ 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)
}
}
when {
showInlineIcons && linkParts.first().startsWith("http") -> holder.itemView.gemtext_text_link.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.vector_open_browser, 0)
@ -154,7 +176,6 @@ class GemtextAdapter(
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])
@ -162,6 +183,17 @@ 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 -> {
@ -171,8 +203,20 @@ 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
}
}
holder.itemView.gemtext_text_link.setOnClickListener {
val uri = getUri(lines[holder.adapterPosition])
println("User clicked link: $uri")
@ -184,6 +228,17 @@ 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")
@ -213,8 +268,14 @@ class GemtextAdapter(
}
when {
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)
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)
}
}
}
}
@ -268,6 +329,11 @@ class GemtextAdapter(
notifyDataSetChanged()
}
override fun linkButtons(visible: Boolean){
this.showLinkButtons = visible
notifyDataSetChanged()
}
override fun inlineImages(visible: Boolean){
this.showInlineImages = visible
notifyDataSetChanged()

View File

@ -197,6 +197,13 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
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 = (R.string.show_link_buttons.toString())
accessibilityCategory.addPreference(showLinkButtonsPreference)
}
private fun buildClientCertificateSection(context: Context?, appCategory: PreferenceCategory) {

View File

@ -1,46 +0,0 @@
<?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

@ -5,20 +5,45 @@
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.LinearLayoutCompat
android:id="@+id/link_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:layout_width="match_parent"
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.appcompat.widget.LinearLayoutCompat>
<androidx.cardview.widget.CardView
android:id="@+id/rounded_image_frame"
@ -30,7 +55,7 @@
android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:visibility="gone"
android:layout_below="@+id/gemtext_text_link">
android:layout_below="@+id/link_frame">
<ImageView
android:id="@+id/gemtext_inline_image"

View File

@ -3,7 +3,27 @@
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: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_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:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/gemtext_text_link"

View File

@ -1,29 +0,0 @@
<?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,6 +68,7 @@
<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">Boutons de lien</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>

View File

@ -68,6 +68,7 @@
<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>