mirror of https://github.com/Corewala/Buran
Added link buttons
This commit is contained in:
parent
1b829279b9
commit
28c72ce29c
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
||||
|
|
|
@ -8,11 +8,13 @@ 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(
|
||||
|
@ -142,19 +144,35 @@ 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 {
|
||||
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)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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])
|
||||
|
@ -162,6 +180,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 +200,20 @@ 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.setOnClickListener {
|
||||
val uri = getUri(lines[holder.adapterPosition])
|
||||
println("User clicked link: $uri")
|
||||
|
@ -184,6 +225,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")
|
||||
|
@ -215,8 +267,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,6 +328,11 @@ class GemtextAdapter(
|
|||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun linkButtons(visible: Boolean){
|
||||
this.showLinkButtons = visible
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun inlineImages(visible: Boolean){
|
||||
this.showInlineImages = visible
|
||||
notifyDataSetChanged()
|
||||
|
|
|
@ -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 = getString(R.string.show_link_buttons)
|
||||
accessibilityCategory.addPreference(showLinkButtonsPreference)
|
||||
}
|
||||
|
||||
private fun buildClientCertificateSection(context: Context?, appCategory: PreferenceCategory) {
|
||||
|
|
|
@ -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>
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/gemtext_text_link"
|
||||
android:textColor="@color/stroke"
|
||||
android:textSize="@dimen/default_text_size"
|
||||
|
@ -18,7 +18,7 @@
|
|||
android:layout_marginRight="@dimen/screen_margin"
|
||||
tools:text="an image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/rounded_image_frame"
|
||||
|
@ -39,4 +39,25 @@
|
|||
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>
|
|
@ -1,15 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
<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: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: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"
|
||||
|
@ -18,6 +19,27 @@
|
|||
android:background="?android:attr/selectableItemBackground"
|
||||
android:drawablePadding="4dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="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"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -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>
|
Loading…
Reference in New Issue