mirror of https://git.sr.ht/~oppen/ariane
lots of cosmetic improvements
This commit is contained in:
parent
9114f69ec2
commit
328ace5d27
|
@ -2,10 +2,21 @@ package oppen
|
|||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
|
||||
fun String.alert(context: Context){
|
||||
AlertDialog.Builder(context)
|
||||
.setMessage(this)
|
||||
.setPositiveButton("OK"){_, _ ->}
|
||||
.show()
|
||||
}
|
||||
|
||||
fun View.visible(visible: Boolean) = when {
|
||||
visible -> this.visibility = View.VISIBLE
|
||||
else -> this.visibility = View.GONE
|
||||
}
|
||||
|
||||
fun View.visibleRetainingSpace(visible: Boolean) = when {
|
||||
visible -> this.visibility = View.VISIBLE
|
||||
else -> this.visibility = View.INVISIBLE
|
||||
}
|
|
@ -35,12 +35,14 @@ class GeminiDatasource: Datasource{
|
|||
when {
|
||||
address.startsWith("//") -> {
|
||||
//just missing protocol
|
||||
onUpdate(TvaState.Requesting(uri))
|
||||
request(URI.create("gemini:$address"), onUpdate)
|
||||
return
|
||||
}
|
||||
address.startsWith("/") -> {
|
||||
//internal navigation
|
||||
val internalNav = "gemini://${last?.host}$address"
|
||||
onUpdate(TvaState.Requesting(uri))
|
||||
request(URI.create(internalNav), onUpdate)
|
||||
return
|
||||
}
|
||||
|
@ -48,6 +50,7 @@ class GeminiDatasource: Datasource{
|
|||
//looks like a relative link
|
||||
val lastAddress = last.toString()
|
||||
val relAddress = "${lastAddress.substring(0, lastAddress.lastIndexOf("/") + 1)}$address"
|
||||
onUpdate(TvaState.Requesting(uri))
|
||||
request(URI.create(relAddress), onUpdate)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import oppen.tva.R
|
|||
import oppen.tva.databinding.ActivityTvaBinding
|
||||
import oppen.tva.io.TvaState
|
||||
import oppen.tva.io.history.CacheInterface
|
||||
import oppen.visibleRetainingSpace
|
||||
|
||||
|
||||
class TvaActivity : AppCompatActivity() {
|
||||
|
@ -35,7 +36,7 @@ class TvaActivity : AppCompatActivity() {
|
|||
model.initialise(CacheInterface.default(this)){ state ->
|
||||
when(state){
|
||||
is TvaState.AppQuery -> TODO()
|
||||
is TvaState.Requesting -> TODO()
|
||||
is TvaState.Requesting -> loadingView(true)
|
||||
is TvaState.NotGeminiRequest -> externalProtocol(state)
|
||||
is TvaState.GeminiResponse -> renderGemtext(state)
|
||||
TvaState.GeminiPrintWriterError -> TODO()
|
||||
|
@ -58,19 +59,26 @@ class TvaActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun externalProtocol(state: TvaState.NotGeminiRequest) {
|
||||
loadingView(false)
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(state.uri.toString()))
|
||||
startActivity(browserIntent)
|
||||
}
|
||||
|
||||
private fun renderGemtext(state: TvaState.GeminiResponse) = runOnUiThread {
|
||||
loadingView(false)
|
||||
if(state.header.startsWith("2") && state.header.contains("text/gemini")) {
|
||||
binding.addressEdit.setText(state.uri.toString())
|
||||
adapter.render(state.lines)
|
||||
}else{
|
||||
println("Server returned an error - or non gemtext mimetype: ${state.header}")
|
||||
"Server returned an error - or non gemtext mimetype not implemented yet: ${state.header}".alert(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadingView(visible: Boolean) = runOnUiThread {
|
||||
binding.progressBar.visibleRetainingSpace(visible)
|
||||
if(visible) binding.appBar.setExpanded(true)
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
override fun onBackPressed() {
|
||||
if(model.canGoBack()){
|
||||
|
|
|
@ -41,11 +41,11 @@ class TvaViewModel: ViewModel() {
|
|||
fun request(uri: URI){
|
||||
gemini.request(uri){ state ->
|
||||
when(state){
|
||||
is TvaState.Requesting -> {}
|
||||
is TvaState.Requesting -> onState(state)
|
||||
is TvaState.AppQuery -> {}
|
||||
is TvaState.NotGeminiRequest -> onState(state)
|
||||
is TvaState.GeminiResponse -> renderGemini(state)
|
||||
TvaState.GeminiPrintWriterError -> {}
|
||||
TvaState.GeminiPrintWriterError -> onState(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,53 +28,72 @@
|
|||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/default_margin"
|
||||
android:paddingBottom="@dimen/default_margin">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/home"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/vector_home" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/address_edit"
|
||||
android:layout_height="wrap_content">
|
||||
<RelativeLayout
|
||||
android:id="@+id/address_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@+id/home"
|
||||
android:layout_toLeftOf="@+id/tabs"
|
||||
android:singleLine="true"
|
||||
android:textSize="14sp"
|
||||
android:imeOptions="actionGo"
|
||||
android:hint="@string/gemini_protocol"/>
|
||||
android:paddingTop="@dimen/default_margin"
|
||||
android:paddingBottom="@dimen/default_margin">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/tabs"
|
||||
android:layout_toLeftOf="@+id/more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/vector_tab" />
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/home"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/vector_home" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/vector_overflow" />
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/address_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@+id/home"
|
||||
android:layout_toLeftOf="@+id/tabs"
|
||||
android:inputType="textNoSuggestions|textUri"
|
||||
android:singleLine="true"
|
||||
android:textSize="14sp"
|
||||
android:imeOptions="actionGo"
|
||||
android:hint="@string/gemini_protocol"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/tabs"
|
||||
android:layout_toLeftOf="@+id/more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/vector_tab" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/vector_overflow" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:indeterminateTint="#ffffff"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_below="@+id/address_bar"
|
||||
android:indeterminate="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
|
Loading…
Reference in New Issue