Commit 0d8d9f2a authored by Waweic's avatar Waweic 💬
Browse files

Some cleanups

parent b691e4ae
<component name="ProjectDictionaryState">
<dictionary name="Anonymous">
<words>
<w>decentral</w>
<w>geminiclient</w>
</words>
</dictionary>
</component>
\ No newline at end of file
......@@ -12,11 +12,11 @@ class GeminiClient(applicationContext: Context, mainContentView: TextView, val u
val renderer : GeminiRenderer = GeminiRenderer(mainContentView, this)
val responseHandler : GeminiResponseHandler = GeminiResponseHandler(renderer, applicationContext, this)
private val history = mutableListOf<URI>()
private val history: MutableList<URI> = mutableListOf()
fun goToPage(uri: URI) {
if(history.size == 0 || history[history.size - 1] != uri) {
history.add(uri) //No double entries. Useful for reloading and going back //TODO: Make prooisbly make this comparison more reproducible
history.add(uri) //No double entries. Useful for reloading and going back //TODO: Make this comparison more reproducible
}
uriField.setText(uri.toString())
val deferredResult = GlobalScope.async { connection.request(uri) }
......
package rocks.ism.decentral.geminiclient
import android.graphics.Bitmap
import android.os.AsyncTask
import java.io.*
import java.net.URI
import javax.net.ssl.SSLSocket
......@@ -42,14 +40,14 @@ class GeminiConnection {
return GeminiResult(this, GeminiConnectionState.FAILED_PRINTER_WRITER)
}
var inReader = BufferedReader(
val inReader = BufferedReader(
InputStreamReader(
socket.inputStream
)
)
var responseHeader: String = inReader.readLine()
var responseBody: String = inReader.readText()
val responseHeader: String = inReader.readLine()
val responseBody: String = inReader.readText()
inReader.close()
outWriter.close()
......
package rocks.ism.decentral.geminiclient
import android.text.Html
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.URLSpan
import android.widget.TextView
import android.widget.Toast
import kotlinx.coroutines.*
import java.io.BufferedReader
import java.io.StringReader
......@@ -36,23 +33,26 @@ class GeminiRenderer (val textView: TextView, val geminiClient: GeminiClient) {
}
fun renderGeminiLine (line: String) {
if(line.startsWith("=>")) {
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
val linkUrl = geminiClient.connection.currentURI?.resolve(linkParts[0]).toString()
var linkName = linkParts[0]
if(linkParts.size > 1) {
linkName = linkParts[1]
when {
line.startsWith("=>") -> {
val linkParts = line.substring(2).trim().split("\\s+".toRegex(), 2)
val linkUrl = geminiClient.connection.currentURI?.resolve(linkParts[0]).toString()
var linkName = linkParts[0]
if(linkParts.size > 1) {
linkName = linkParts[1]
}
val spannable = SpannableString(linkName)
spannable.setSpan(URLSpan(linkUrl), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
textView.append(spannable)
}
line.startsWith("*") -> {
val spannable = SpannableString(line.substring(1))
spannable.setSpan(BulletSpan(), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
textView.append(spannable)
}
else -> {
textView.append(line)
}
val spannable = SpannableString(linkName)
spannable.setSpan(URLSpan(linkUrl), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
textView.append(spannable)
} else if(line.startsWith("*")) {
val spannable = SpannableString(line.substring(1))
spannable.setSpan(BulletSpan(), 0, spannable.length, SPAN_EXCLUSIVE_EXCLUSIVE)
textView.append(spannable)
}
else {
textView.append(line)
}
textView.append("\n")
}
......
......@@ -6,7 +6,6 @@ import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import java.net.URI
class MainActivity : AppCompatActivity() {
......
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