Removed large gemtext

This commit is contained in:
Corewala 2022-01-07 16:26:18 -05:00
parent 36e2151c9f
commit 6d44717ef6
18 changed files with 17 additions and 441 deletions

View File

@ -33,7 +33,7 @@ import corewala.buran.ui.bookmarks.BookmarkDialog
import corewala.buran.ui.bookmarks.BookmarksDialog
import corewala.buran.ui.content_image.ImageDialog
import corewala.buran.ui.content_text.TextDialog
import corewala.buran.ui.gemtext_adapters.*
import corewala.buran.ui.gemtext_adapter.*
import corewala.buran.ui.modals_menus.about.AboutDialog
import corewala.buran.ui.modals_menus.history.HistoryDialog
import corewala.buran.ui.modals_menus.input.InputDialog
@ -117,10 +117,7 @@ class GemActivity : AppCompatActivity() {
prefs = PreferenceManager.getDefaultSharedPreferences(this)
adapter = when {
prefs.getBoolean("use_large_gemtext_adapter", false) -> AbstractGemtextAdapter.getLargeGmi(onLink)
else -> AbstractGemtextAdapter.getDefault(onLink)
}
adapter = AbstractGemtextAdapter.getAdapter(onLink)
binding.gemtextRecycler.adapter = adapter
@ -268,25 +265,10 @@ class GemActivity : AppCompatActivity() {
else -> hideClientCertShield()
}
val useLargeGmiAdapter = prefs.getBoolean("use_large_gemtext_adapter", false)
when {
useLargeGmiAdapter -> {
if(adapter.typeId != GEMTEXT_ADAPTER_LARGE){
gemtext_recycler.adapter = null
adapter = AbstractGemtextAdapter.getLargeGmi(onLink)
gemtext_recycler.adapter = adapter
refresh()
}
}
else -> {
if(adapter.typeId != GEMTEXT_ADAPTER_DEFAULT) {
gemtext_recycler.adapter = null
adapter = AbstractGemtextAdapter.getDefault(onLink)
gemtext_recycler.adapter = adapter
refresh()
}
}
}
gemtext_recycler.adapter = null
adapter = AbstractGemtextAdapter.getAdapter(onLink)
gemtext_recycler.adapter = adapter
refresh()
val hideCodeBlocks = prefs.getBoolean(
"collapse_code_blocks",

View File

@ -1,14 +1,10 @@
package corewala.buran.ui.gemtext_adapters
package corewala.buran.ui.gemtext_adapter
import android.net.Uri
import androidx.recyclerview.widget.RecyclerView
import java.net.URI
const val GEMTEXT_ADAPTER_DEFAULT = 0
const val GEMTEXT_ADAPTER_LARGE = 1
abstract class AbstractGemtextAdapter(
val typeId: Int,
val onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit
): RecyclerView.Adapter<GmiViewHolder>() {
@ -23,12 +19,8 @@ abstract class AbstractGemtextAdapter(
abstract fun inferTitle(): String?
companion object{
fun getDefault(onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit): AbstractGemtextAdapter {
return DefaultGemtextAdapter(GEMTEXT_ADAPTER_DEFAULT, onLink)
}
fun getLargeGmi(onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit): AbstractGemtextAdapter {
return LargeGemtextAdapter(GEMTEXT_ADAPTER_LARGE, onLink)
fun getAdapter(onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit): AbstractGemtextAdapter {
return GemtextAdapter(onLink)
}
}
}

View File

@ -1,4 +1,4 @@
package corewala.buran.ui.gemtext_adapters
package corewala.buran.ui.gemtext_adapter
import android.annotation.SuppressLint
import android.net.Uri
@ -15,10 +15,9 @@ import corewala.endsWithImage
import corewala.visible
import java.net.URI
class DefaultGemtextAdapter(
typeId: Int,
class GemtextAdapter(
onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit)
: AbstractGemtextAdapter(typeId, onLink) {
: AbstractGemtextAdapter(onLink) {
private var lines = mutableListOf<String>()
private var inlineImages = HashMap<Int, Uri>()

View File

@ -1,4 +1,4 @@
package corewala.buran.ui.gemtext_adapters
package corewala.buran.ui.gemtext_adapter
import android.view.View
import androidx.recyclerview.widget.RecyclerView

View File

@ -1,253 +0,0 @@
package corewala.buran.ui.gemtext_adapters
import android.annotation.SuppressLint
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.gemtext_large_code_block.view.*
import kotlinx.android.synthetic.main.gemtext_large_image_link.view.*
import kotlinx.android.synthetic.main.gemtext_large_link.view.gemtext_text_link
import kotlinx.android.synthetic.main.gemtext_large_text.view.*
import corewala.buran.R
import corewala.endsWithImage
import corewala.visible
import java.net.URI
class LargeGemtextAdapter(
typeId: Int,
onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit)
: AbstractGemtextAdapter(typeId, onLink) {
private var lines = mutableListOf<String>()
private var inlineImages = HashMap<Int, Uri>()
private val typeText = 0
private val typeH1 = 1
private val typeH2 = 2
private val typeH3 = 3
private val typeListItem = 4
private val typeImageLink = 5
private val typeLink = 6
private val typeCodeBlock = 7
private val typeQuote = 8
override fun render(lines: List<String>){
this.inlineImages.clear()
this.lines.clear()
this.lines.addAll(lines)
notifyDataSetChanged()
}
private fun inflate(parent: ViewGroup, layout: Int): View{
return LayoutInflater.from(parent.context).inflate(layout, parent, false)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GmiViewHolder {
return when(viewType){
typeText -> GmiViewHolder.Text(inflate(parent, R.layout.gemtext_large_text))
typeH1 -> GmiViewHolder.H1(inflate(parent, R.layout.gemtext_large_h1))
typeH2 -> GmiViewHolder.H2(inflate(parent, R.layout.gemtext_large_h2))
typeH3 -> GmiViewHolder.H3(inflate(parent, R.layout.gemtext_large_h3))
typeListItem -> GmiViewHolder.ListItem(inflate(parent, R.layout.gemtext_large_text))
typeImageLink -> GmiViewHolder.ImageLink(inflate(parent, R.layout.gemtext_large_image_link))
typeLink -> GmiViewHolder.Link(inflate(parent, R.layout.gemtext_large_link))
typeCodeBlock-> GmiViewHolder.Code(inflate(parent, R.layout.gemtext_large_code_block))
typeQuote -> GmiViewHolder.Quote(inflate(parent, R.layout.gemtext_large_quote))
else -> GmiViewHolder.Text(inflate(parent, R.layout.gemtext_large_text))
}
}
override fun getItemViewType(position: Int): Int {
val line = lines[position]
return when {
line.startsWith("```") -> typeCodeBlock
line.startsWith("###") -> typeH3
line.startsWith("##") -> typeH2
line.startsWith("#") -> typeH1
line.startsWith("*") -> typeListItem
line.startsWith("=>") && getLink(line).endsWithImage() -> typeImageLink
line.startsWith("=>") -> typeLink
line.startsWith(">") -> typeQuote
else -> typeText
}
}
override fun getItemCount(): Int = lines.size
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: GmiViewHolder, position: Int) {
val line = lines[position]
when(holder){
is GmiViewHolder.Text -> holder.itemView.gemtext_text_textview.text = line
is GmiViewHolder.Code -> {
var altText: String? = null
if(line.startsWith("```<|ALT|>")){
//there's alt text: "```<|ALT|>$alt</|ALT>"
altText = line.substring(10, line.indexOf("</|ALT>"))
holder.itemView.gemtext_text_monospace_textview.text = line.substring(line.indexOf("</|ALT>") + 7)
}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.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 -> {
when {
line.length > 2 -> holder.itemView.gemtext_text_textview.text = line.substring(2).trim()
else -> holder.itemView.gemtext_text_textview.text = ""
}
}
is GmiViewHolder.H2 -> {
when {
line.length > 3 -> holder.itemView.gemtext_text_textview.text = line.substring(3).trim()
else -> holder.itemView.gemtext_text_textview.text = ""
}
}
is GmiViewHolder.H3 -> {
when {
line.length > 4 -> holder.itemView.gemtext_text_textview.text = line.substring(4).trim()
else -> holder.itemView.gemtext_text_textview.text = ""
}
}
is GmiViewHolder.ListItem -> holder.itemView.gemtext_text_textview.text = "${line.substring(1)}".trim()
is GmiViewHolder.Link -> {
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
var linkName = linkParts[0]
if(linkParts.size > 1) linkName = linkParts[1]
val displayText = linkName
holder.itemView.gemtext_text_link.text = displayText
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)
}
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])
println("User long-clicked link: $uri")
onLink(uri, true, holder.adapterPosition)
true
}
}
is GmiViewHolder.ImageLink -> {
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
var linkName = linkParts[0]
if(linkParts.size > 1) linkName = linkParts[1]
val displayText = linkName
holder.itemView.gemtext_text_link.text = displayText
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])
println("User long-clicked link: $uri")
onLink(uri, true, holder.adapterPosition)
true
}
when {
inlineImages.containsKey(position) -> {
holder.itemView.gemtext_inline_image.visible(true)
holder.itemView.gemtext_inline_image.setImageURI(inlineImages[position])
}
else -> holder.itemView.gemtext_inline_image.visible(false)
}
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)
}
}
}
}
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")
}
}
}
}
private fun getLink(line: String): String{
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
return linkParts[0]
}
private fun getUri(linkLine: String): URI{
val linkParts = linkLine.substring(2).trim().split("\\s+".toRegex(), 2)
return URI.create(linkParts.first())
}
override fun inferTitle(): String? {
lines.forEach { line ->
if(line.startsWith("#")) return line.replace("#", "").trim()
}
return null
}
override fun loadImage(position: Int, cacheUri: Uri){
inlineImages[position] = cacheUri
notifyItemChanged(position)
}
override fun inlineIcons(visible: Boolean){
this.showInlineIcons = visible
notifyDataSetChanged()
}
override fun hideCodeBlocks(hideCodeBlocks: Boolean) {
this.hideCodeBlocks = hideCodeBlocks
notifyDataSetChanged()
}
}

View File

@ -185,12 +185,6 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
collapseCodeBlocksPreference.title = getString(R.string.collapse_code_blocks)
accessibilityCategory.addPreference(collapseCodeBlocksPreference)
//Accessibility - large text and buttons
val largeGemtextPreference = SwitchPreferenceCompat(context)
largeGemtextPreference.key = "use_large_gemtext_adapter"
largeGemtextPreference.title = getString(R.string.large_gemtext_and_button)
accessibilityCategory.addPreference(largeGemtextPreference)
//Accessibility - inline icons
val showInlineIconsPreference = SwitchPreferenceCompat(context)
showInlineIconsPreference.setDefaultValue(true)

View File

@ -12,7 +12,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:textSize="@dimen/default_text_size"
android:textColor="@color/stroke"
android:id="@id/show_code_block"
android:id="@+id/show_code_block"
android:background="?android:selectableItemBackground"
android:focusable="true" android:clickable="true"
android:layout_width="wrap_content"

View File

@ -7,7 +7,7 @@
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/gemtext_text_link"
android:textColor="@color/stroke"
android:textSize="@dimen/large_text_size"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:drawableEnd="@drawable/vector_photo"

View File

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/show_code_block"
android:textColor="@color/stroke"
android:layout_marginTop="@dimen/default_margin_small"
android:layout_marginBottom="@dimen/default_margin_small"
android:textSize="@dimen/large_text_size"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/accessibility_button_padding"
android:textAllCaps="false"
android:backgroundTint="@color/accessibility_button_background"
android:textAlignment="viewStart"
android:drawablePadding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/show_code"
tools:text="Show code: Ascii art banner: Spacewalk - Updates from around geminispace"
/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/show_code_block">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/gemtext_text_monospace_textview"
android:textSize="@dimen/code_text_size"
app:lineHeight="@dimen/code_text_size"
app:fontFamily="@font/code_font"
android:fontFamily="@font/code_font"
android:typeface="monospace"
android:textColor="@color/stroke"
android:textIsSelectable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/default_margin"
android:paddingRight="@dimen/default_margin"
android:paddingTop="@dimen/default_margin"
android:paddingBottom="@dimen/default_margin"
android:isScrollContainer="true"
android:overScrollMode="ifContentScrolls"
android:scrollHorizontally="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|horizontal"/>
</HorizontalScrollView>
</RelativeLayout>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gemtext_text_textview"
android:textSize="@dimen/large_h1_text_size"
android:textColor="@color/stroke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin_tiny" />

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gemtext_text_textview"
android:textSize="@dimen/large_h2_text_size"
android:textColor="@color/stroke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin_tiny" />

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gemtext_text_textview"
android:textSize="@dimen/large_h3_text_size"
android:textColor="@color/stroke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin_tiny" />

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gemtext_text_monospace_textview"
android:textSize="@dimen/large_text_size"
android:textColor="@color/stroke"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:paddingLeft="@dimen/default_margin"
android:paddingRight="@dimen/default_margin"
android:paddingTop="@dimen/default_margin"
android:paddingBottom="@dimen/default_margin"
android:textStyle="italic"
android:background="@color/code_background"
android:textIsSelectable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineHeight="@dimen/large_line_height"/>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gemtext_text_textview"
android:textSize="@dimen/large_text_size"
android:layout_marginLeft="@dimen/screen_margin"
android:layout_marginRight="@dimen/screen_margin"
android:textColor="@color/stroke"
android:textIsSelectable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineHeight="@dimen/large_line_height"/>

View File

@ -12,7 +12,7 @@
android:layout_marginRight="@dimen/screen_margin"
android:layout_marginTop="@dimen/default_margin_small"
android:layout_marginBottom="@dimen/default_margin_small"
android:textSize="@dimen/large_text_size"
android:textSize="@dimen/default_text_size"
android:clickable="true"
android:focusable="true"
android:textAllCaps="false"

View File

@ -72,7 +72,6 @@
<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="large_gemtext_and_button">Gemtexte large</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>

View File

@ -7,7 +7,7 @@
<dimen name="screen_margin">20dp</dimen>
<dimen name="button_margin">12dp</dimen>
<!-- Default Adapter-->
<!-- Gemtext Adapter-->
<dimen name="default_text_size">16sp</dimen>
<dimen name="default_line_height">20sp</dimen>
<dimen name="code_text_size">14sp</dimen>
@ -15,15 +15,6 @@
<dimen name="h2_text_size">26sp</dimen>
<dimen name="h3_text_size">22sp</dimen>
<!-- Large Adapter -->
<dimen name="large_text_size">22sp</dimen>
<dimen name="large_line_height">28sp</dimen>
<dimen name="large_code_text_size">18sp</dimen>
<dimen name="large_h1_text_size">40sp</dimen>
<dimen name="large_h2_text_size">34sp</dimen>
<dimen name="large_h3_text_size">30sp</dimen>
<dimen name="button_size">32dp</dimen>
<dimen name="bar_height">50dp</dimen>
<dimen name="menu_item_icon_size">20dp</dimen>

View File

@ -72,7 +72,6 @@
<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="large_gemtext_and_button">Large Gemtext</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>