1
0
Fork 0
mirror of https://git.sr.ht/~oppen/ariane synced 2024-12-26 17:59:30 +00:00

display non-gemtext txt files

This commit is contained in:
Öppen 2020-08-20 18:40:54 +01:00
parent b0e8f30ddf
commit d2011e0d0c
4 changed files with 84 additions and 1 deletions

View file

@ -163,5 +163,7 @@ class GeminiDatasource: Datasource{
val content = socket?.inputStream?.bufferedReader().use { reader -> reader?.readText() }
socket?.close()
onUpdate(TvaState.ResponseText(uri, header, content ?: "Error fetching content"))
}
}

View file

@ -23,6 +23,7 @@ import oppen.tva.io.RuntimeCache
import oppen.tva.io.TvaState
import oppen.tva.io.history.tabs.TabHistoryInterface
import oppen.tva.io.history.uris.HistoryInterface
import oppen.tva.ui.content_text.TextDialog
import oppen.tva.ui.modals_menus.about.AboutDialog
import oppen.tva.ui.modals_menus.history.HistoryDialog
import oppen.tva.ui.modals_menus.input.InputDialog
@ -84,7 +85,7 @@ class TvaActivity : AppCompatActivity() {
is TvaState.NotGeminiRequest -> externalProtocol(state)
is TvaState.ResponseError -> showAlert("${GeminiResponse.getCodeString(state.header.code)}: ${state.header.meta}")
is TvaState.ResponseGemtext -> renderGemtext(state)
is TvaState.ResponseText -> runOnUiThread{ showAlert("Plain text display not implemented") }
is TvaState.ResponseText -> renderText(state)
is TvaState.TabChange -> binding.tabCount.text = "${state.count}"
is TvaState.Blank -> {
binding.addressEdit.setText("")
@ -201,6 +202,11 @@ class TvaActivity : AppCompatActivity() {
history.add(state.uri.toString())
}
private fun renderText(state: TvaState.ResponseText) = runOnUiThread {
loadingView(false)
TextDialog.show(this, state)
}
private fun loadingView(visible: Boolean) = runOnUiThread {
binding.progressBar.visibleRetainingSpace(visible)
if(visible) binding.appBar.setExpanded(true)

View file

@ -0,0 +1,27 @@
package oppen.tva.ui.content_text
import android.content.Context
import android.view.View
import androidx.appcompat.app.AppCompatDialog
import kotlinx.android.synthetic.main.dialog_content_text.view.*
import oppen.tva.R
import oppen.tva.io.TvaState
object TextDialog {
fun show(context: Context, state: TvaState.ResponseText){
val dialog = AppCompatDialog(context, R.style.AppTheme)
val view = View.inflate(context, R.layout.dialog_content_text, null)
dialog.setContentView(view)
view.text_content.text = state.content
view.close_text_content_dialog.setOnClickListener {
dialog.dismiss()
}
dialog.show()
}
}

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_margin">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/close_text_content_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_margin="@dimen/button_margin"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_close" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/history_overflow"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/button_margin"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_overflow" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/default_margin"
android:layout_below="@+id/header">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
</RelativeLayout>