Commit 41af74c2 authored by Waweic's avatar Waweic 💬
Browse files

Enabled Gemini INPUT requests

parent 7a13bfd9
......@@ -21,6 +21,7 @@ If you want to download the Application without building it yourself, you can do
* Avoiding redirection loops
* The "Back"-button
* An (internal and temporary) browsing history
* Gemini INPUT
## Stuff that doesn't work (aka wishlist for the future)
* Connecting to hosts with self signed certificates
......@@ -32,7 +33,6 @@ If you want to download the Application without building it yourself, you can do
* Graceful error handling
* Markdown
* Code quality / structure
* Gemini INPUT
* Client certificates
* Security
* Preformatted Text in Gemini documents
......
package rocks.ism.decentral.geminiclient
import android.content.Context
import android.view.LayoutInflater
import android.widget.EditText
import android.widget.TextView
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import androidx.appcompat.app.AlertDialog
import kotlinx.coroutines.*
import java.net.URI
class GeminiClient(applicationContext: Context, mainContentView: TextView, val uriField: EditText) {
class GeminiClient(applicationContext: Context, val mainContentView: TextView, val uriField: EditText) {
val connection : GeminiConnection = GeminiConnection()
val renderer : GeminiRenderer = GeminiRenderer(mainContentView, this)
val responseHandler : GeminiResponseHandler = GeminiResponseHandler(renderer, applicationContext, this)
......@@ -27,6 +27,28 @@ class GeminiClient(applicationContext: Context, mainContentView: TextView, val u
//TODO: Do checking and stuff
goToPage(URI.create(uri))
}
fun inputRequest(uri: URI, request: String) {
val alertBuilder = AlertDialog.Builder(mainContentView.context)
val inflater = LayoutInflater.from(mainContentView.context)
alertBuilder.setTitle(R.string.input_request_title)
val dialogLayout = inflater.inflate(R.layout.input_request_dialog, null)
val editText = dialogLayout.findViewById<EditText>(R.id.editText)
editText.hint = request
alertBuilder.setView(dialogLayout)
//alertBuilder.setMessage(request)
alertBuilder.setPositiveButton(R.string.go_button_text) { dialogInterface, i ->
val newURI = URI(uri.scheme, uri.authority, uri.path, editText.text.toString(), uri.fragment) //TODO: User Info?
goToPage(newURI)
}
alertBuilder.setNegativeButton(R.string.back_button_text) { dialogInterface, i ->
goBack()
}
CoroutineScope(Dispatchers.Main).launch {
alertBuilder.show()
}
}
fun removeLastHistoryItem() {
history.removeAt(history.size - 1)
}
......
......@@ -37,6 +37,9 @@ class GeminiResponseHandler (val renderer: GeminiRenderer, private val context:
renderer.renderStream(result.body,"text/plain")
}
}
else if(result.header.startsWith("1")){
geminiClient.connection.currentURI?.let { geminiClient.inputRequest(it, result.meta) }
}
else {
renderer.render(result.header,"text/plain")
}
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the text here"/>
</LinearLayout>
\ No newline at end of file
......@@ -2,7 +2,8 @@
<string name="app_name">Gemini Client</string>
<string name="back_button_text">Back</string>
<string name="go_button_text">Go</string>
<string name="default_url">gemini://gemini.circumlunar.space/</string>
<string name="input_request_title">Input Request</string>
<string name="default_url">gemini://gus.guru/</string>
<string name="text_without_page_loaded">No Gemini page loaded yet</string>
<string name="uri_input_hint">URI of Gemini site to enter</string>
</resources>
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