Replaced full-screen query dialog with AlertDialog

This commit is contained in:
Corewala 2022-02-16 20:02:27 -05:00
parent a78d11bf5a
commit 8c0bfd04db
3 changed files with 24 additions and 88 deletions

View File

@ -9,8 +9,11 @@ import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
@ -36,7 +39,6 @@ import corewala.buran.ui.content_text.TextDialog
import corewala.buran.ui.gemtext_adapter.*
import corewala.buran.ui.modals_menus.about.AboutDialog
import corewala.buran.ui.modals_menus.history.HistoryDialog
import corewala.buran.ui.modals_menus.input.InputDialog
import corewala.buran.ui.modals_menus.overflow.OverflowPopup
import corewala.buran.ui.settings.SettingsActivity
import java.io.File
@ -314,12 +316,29 @@ class GemActivity : AppCompatActivity() {
when (state) {
is GemState.AppQuery -> runOnUiThread { showAlert("App backdoor/query not implemented yet") }
is GemState.ResponseInput -> runOnUiThread {
val builder = AlertDialog.Builder(this)
val inflater: LayoutInflater = layoutInflater
val dialogLayout: View = inflater.inflate(R.layout.dialog_input_query, null)
val editText: EditText = dialogLayout.findViewById(R.id.query_input)
editText.requestFocus()
editText.showKeyboard()
loadingView(false)
InputDialog.show(this, state) { queryAddress ->
model.request(queryAddress)
with(builder) {
setTitle(state.header.meta)
setPositiveButton("Ok"){ dialog, which ->
model.request("${state.uri}?${Uri.encode(editText.text.toString())}")
editText.hideKeyboard()
}
setNegativeButton(R.string.cancel){ dialog, which ->
editText.hideKeyboard()
}
setView(dialogLayout)
show()
}
}
is GemState.Requesting -> loadingView(true)
is GemState.NotGeminiRequest -> externalProtocol(state)
is GemState.ResponseError -> {

View File

@ -1,33 +0,0 @@
package corewala.buran.ui.modals_menus.input
import android.content.Context
import android.view.View
import androidx.appcompat.app.AppCompatDialog
import kotlinx.android.synthetic.main.dialog_input_query.view.*
import corewala.buran.R
import corewala.buran.io.GemState
import java.net.URLEncoder
object InputDialog {
fun show(context: Context, state: GemState.ResponseInput, onQuery: (queryAddress: String) -> Unit) {
val dialog = AppCompatDialog(context, R.style.AppTheme)
val view = View.inflate(context, R.layout.dialog_input_query, null)
dialog.setContentView(view)
view.close_input_query_dialog.setOnClickListener {
dialog.dismiss()
}
view.query_text.text = state.header.meta
view.query_submit_button.setOnClickListener {
val encoded = URLEncoder.encode(view.query_input.text.toString(), "UTF-8")
onQuery("${state.uri}?$encoded")
dialog.dismiss()
}
dialog.show()
}
}

View File

@ -2,61 +2,11 @@
<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_input_query_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" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/default_margin_big"
android:paddingRight="@dimen/default_margin_big"
android:paddingBottom="@dimen/default_margin_big"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/query_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/default_margin"
tools:text="Type your query"/>
android:paddingHorizontal="@dimen/default_margin_big">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/query_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/default_margin"/>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/query_submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/submit"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
android:layout_height="wrap_content"/>
</RelativeLayout>