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

handle unsupported url schemes

This commit is contained in:
Jonathan Fisher 2020-11-07 23:03:53 +00:00
parent c35d4241e0
commit a67c249c9e

View file

@ -2,6 +2,7 @@ package oppen.ariane.ui
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.media.MediaPlayer
import android.net.Uri
import android.os.Bundle
@ -12,8 +13,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import oppen.ariane.R
import oppen.ariane.Ariane
import oppen.ariane.R
import oppen.ariane.databinding.ActivityGemBinding
import oppen.ariane.io.GemState
import oppen.ariane.io.bookmarks.BookmarksDatasource
@ -26,12 +27,12 @@ import oppen.ariane.ui.bookmarks.BookmarkDialog
import oppen.ariane.ui.bookmarks.BookmarksDialog
import oppen.ariane.ui.content_image.ImageDialog
import oppen.ariane.ui.content_text.TextDialog
import oppen.ariane.ui.modals_menus.LinkPopup
import oppen.ariane.ui.modals_menus.about.AboutDialog
import oppen.ariane.ui.modals_menus.history.HistoryDialog
import oppen.ariane.ui.modals_menus.input.InputDialog
import oppen.ariane.ui.modals_menus.overflow.OverflowPopup
import oppen.ariane.ui.modals_menus.set_home.SetHomeDialog
import oppen.ariane.ui.modals_menus.LinkPopup
import oppen.hideKeyboard
import oppen.visibleRetainingSpace
import java.io.File
@ -39,6 +40,7 @@ import java.io.FileInputStream
import java.io.FileOutputStream
import java.net.URLEncoder
const val CREATE_IMAGE_FILE_REQ = 628
const val CREATE_AUDIO_FILE_REQ = 629
@ -92,15 +94,18 @@ class GemActivity : AppCompatActivity() {
history = HistoryInterface.default(this)
model.initialise(Datasource.factory(this), BookmarksDatasource.getDefault(applicationContext)){ state ->
model.initialise(
Datasource.factory(this),
BookmarksDatasource.getDefault(applicationContext)
){ state ->
binding.pullToRefresh.isRefreshing = false
when(state){
is GemState.AppQuery -> runOnUiThread{ showAlert("App backdoor/query not implemented yet") }
is GemState.AppQuery -> runOnUiThread { showAlert("App backdoor/query not implemented yet") }
is GemState.ResponseInput -> runOnUiThread {
loadingView(false)
InputDialog.show(this, state){ queryAddress ->
InputDialog.show(this, state) { queryAddress ->
model.request(queryAddress)
}
}
@ -123,10 +128,17 @@ class GemActivity : AppCompatActivity() {
EditorInfo.IME_ACTION_GO -> {
val input = binding.addressEdit.text.toString()
if(input.startsWith("gemini://")){
if (input.startsWith("gemini://")) {
model.request(input)
}else{
model.request("${Ariane.GEMINI_USER_SEARCH_BASE}${URLEncoder.encode(input, "UTF-8")}")
} else {
model.request(
"${Ariane.GEMINI_USER_SEARCH_BASE}${
URLEncoder.encode(
input,
"UTF-8"
)
}"
)
}
binding.addressEdit.hideKeyboard()
@ -138,7 +150,7 @@ class GemActivity : AppCompatActivity() {
}
binding.more.setOnClickListener {
OverflowPopup.show(binding.more){menuId ->
OverflowPopup.show(binding.more){ menuId ->
when (menuId) {
R.id.overflow_menu_search -> {
binding.addressEdit.hint = getString(R.string.main_input_search_hint)
@ -149,9 +161,15 @@ class GemActivity : AppCompatActivity() {
R.id.overflow_menu_bookmark -> {
println("Bookmark: ---------------------------")
val name = adapter.inferTitle()
BookmarkDialog(this, BookmarkDialog.mode_new, bookmarkDatasource, binding.addressEdit.text.toString(), name ?: ""){ _, _ ->
BookmarkDialog(
this,
BookmarkDialog.mode_new,
bookmarkDatasource,
binding.addressEdit.text.toString(),
name ?: ""
) { _, _ ->
bookmarkDatasource.get { bookmarks ->
bookmarks.forEach {bookmark ->
bookmarks.forEach { bookmark ->
println("Bookmark: ${bookmark.label}: ${bookmark.uri}")
}
}
@ -159,7 +177,7 @@ class GemActivity : AppCompatActivity() {
}
R.id.overflow_menu_bookmarks -> {
println("Bookmarks: --------------------------")
BookmarksDialog(this, bookmarkDatasource){ bookmark ->
BookmarksDialog(this, bookmarkDatasource) { bookmark ->
model.request(bookmark.uri)
}.show()
}
@ -176,12 +194,12 @@ class GemActivity : AppCompatActivity() {
startActivity(Intent.createChooser(this, null))
}
}
R.id.overflow_menu_history -> HistoryDialog.show(this){ historyAddress ->
R.id.overflow_menu_history -> HistoryDialog.show(this) { historyAddress ->
model.request(historyAddress)
}
R.id.overflow_menu_about -> AboutDialog.show(this)
R.id.overflow_menu_set_home -> {
SetHomeDialog.show(this, binding.addressEdit.text.toString()){
SetHomeDialog.show(this, binding.addressEdit.text.toString()) {
showAlert("Home capsule updated")
}
}
@ -222,7 +240,12 @@ class GemActivity : AppCompatActivity() {
private fun externalProtocol(state: GemState.NotGeminiRequest) = runOnUiThread {
loadingView(false)
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(state.uri.toString()))
startActivity(browserIntent)
if (browserIntent.resolveActivity(packageManager) != null) {
startActivity(browserIntent)
} else {
showAlert("No app installed that can open ${state.uri}")
}
}
private fun renderGemtext(state: GemState.ResponseGemtext) = runOnUiThread {