Commit 4df49534 authored by Waweic's avatar Waweic 💬
Browse files

Added headings

parent 5e944330
......@@ -12,6 +12,7 @@ If you want to download the Application without building it yourself, you can do
* Viewing formatted text/gemini documents
- Clickable links
- Bullet points
- Headings
* Viewing other text/* documents
* Open application when gemini:// link in other app / browser is clicked
* Open other application when a link is clicked that has a scheme the client can't handle
......@@ -30,11 +31,11 @@ If you want to download the Application without building it yourself, you can do
* Useful error messages
* Graceful error handling
* Markdown
* Headings in text/gemini documents
* Code quality / structure
* Gemini INPUT
* Client certificates
* Security
* Preformatted Text in Gemini documents
## Stuff that probably should be done differently
* Handling other character encodings than utf-8
......
package rocks.ism.decentral.geminiclient
import android.graphics.Typeface
import android.text.SpannableString
import android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
import android.text.method.LinkMovementMethod
import android.text.style.BulletSpan
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import android.text.style.URLSpan
import android.widget.TextView
import java.io.BufferedReader
......@@ -33,7 +36,24 @@ class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
}
fun renderGeminiLine (line: String) {
when {
textView.append(when {
line.startsWith("###") -> {
val spannable = SpannableString(line.substring(3).trim())
spannable.setSpan(StyleSpan(Typeface.BOLD), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
spannable
}
line.startsWith("##") -> {
val spannable = SpannableString(line.substring(2).trim())
spannable.setSpan(StyleSpan(Typeface.BOLD), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
spannable.setSpan(RelativeSizeSpan(1.1f),0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
spannable
}
line.startsWith("#") -> {
val spannable = SpannableString(line.substring(1).trim())
spannable.setSpan(StyleSpan(Typeface.BOLD), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
spannable.setSpan(RelativeSizeSpan(1.2f),0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
spannable
}
line.startsWith("=>") -> {
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
val linkUrl = geminiClient.connection.currentURI?.resolve(linkParts[0]).toString()
......@@ -43,17 +63,17 @@ class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
}
val spannable = SpannableString(linkName)
spannable.setSpan(URLSpan(linkUrl), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
textView.append(spannable)
spannable
}
line.startsWith("*") -> {
val spannable = SpannableString(line.substring(1))
spannable.setSpan(BulletSpan(), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
textView.append(spannable)
spannable
}
else -> {
textView.append(line)
line
}
}
})
textView.append("\n")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment