Commit 40b7e9e7 authored by Waweic's avatar Waweic 💬
Browse files

Minor cleanups

parent 169f57f0
package rocks.ism.decentral.geminiclient
import android.graphics.Typeface
import android.provider.Settings
import android.text.SpannableString
import android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
import android.text.method.LinkMovementMethod
......@@ -9,17 +8,15 @@ import android.text.style.BulletSpan
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import android.text.style.URLSpan
import android.util.Log
import android.widget.TextView
import kotlinx.coroutines.*
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.StringReader
import java.util.*
class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
var preRenderMode = false
class GeminiRenderer (private val textView: TextView, private val geminiClient: GeminiClient) {
private var preRenderMode = false
fun render(resultBody: String, mimetype: String) {
textView.text = ""
......@@ -54,18 +51,18 @@ class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
} while(line != null)
*/
var allLines = GlobalScope.async {
val allLines = GlobalScope.async {
BufferedReader (
inputStream.reader()
).readLines()
}
allLines.await().forEach() {
allLines.await().forEach {
renderLine(it, mimetype)
}
}
}
fun renderLine(line: String, mimetype: String) {
private fun renderLine(line: String, mimetype: String) {
if(mimetype == "text/gemini") {
renderGeminiLine(line)
}
......@@ -73,7 +70,7 @@ class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
textView.append(line + "\n")
}
}
fun renderGemini(resultBody: String) {
private fun renderGemini(resultBody: String) {
val bodyReader = BufferedReader(StringReader(resultBody))
preRenderMode = false
var line: String? = null
......@@ -84,7 +81,7 @@ class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
}
}
fun renderGeminiLine (line: String) {
private fun renderGeminiLine (line: String) {
textView.append(when {
line.startsWith("###") -> {
val spannable = SpannableString(line.substring(3).trim())
......@@ -126,7 +123,7 @@ class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
textView.append("\n")
}
fun renderPlaintext(resultBody: String) {
private fun renderPlaintext(resultBody: String) {
textView.text = resultBody
}
......
......@@ -5,8 +5,8 @@ import android.content.Intent
import android.net.Uri
import kotlinx.coroutines.*
class GeminiResponseHandler (val renderer: GeminiRenderer, private val context: Context, val geminiClient: GeminiClient) {
var numberOfConsecutiveRedirects = 0
class GeminiResponseHandler (private val renderer: GeminiRenderer, private val context: Context, private val geminiClient: GeminiClient) {
private var numberOfConsecutiveRedirects = 0
suspend fun handle (deferredResult: Deferred<GeminiResult>) {
val result = deferredResult.await()
......
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