Skip to content

Commit

Permalink
Replaced full-screen query dialog with AlertDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Corewala committed Feb 17, 2022
1 parent a78d11b commit 8c0bfd0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 88 deletions.
25 changes: 22 additions & 3 deletions app/src/main/java/corewala/buran/ui/GemActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 -> {
Expand Down

This file was deleted.

54 changes: 2 additions & 52 deletions app/src/main/res/layout/dialog_input_query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 8c0bfd0

Please sign in to comment.