Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save the last search term and added a button to clear text #2004

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/src/main/java/net/bible/android/view/activity/search/Search.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.util.Log
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.Button
import android.widget.RadioButton
import android.widget.RadioGroup

Expand Down Expand Up @@ -129,13 +130,20 @@ class Search : CustomTitlebarActivityBase(R.menu.search_actionbar_menu) {
// false
//})

binding.rememberSearchText.setOnClickListener {
CommonUtils.settings.setBoolean("search_remember_search_text", binding.rememberSearchText.isChecked)
}

// pre-load search string if passed in
val extras = intent.extras
if (extras != null) {
val text = extras.getString(SEARCH_TEXT_SAVE)
if (StringUtils.isNotEmpty(text)) {
binding.searchText.setText(text)
}
} else {
binding.rememberSearchText.isChecked = CommonUtils.settings.getBoolean("search_remember_search_text", false)
if (binding.rememberSearchText.isChecked) binding.searchText.setText(CommonUtils.settings.getString("search_text", ""))
}

val wordsRadioGroup = findViewById<View>(R.id.wordsGroup) as RadioGroup
Expand Down Expand Up @@ -169,6 +177,8 @@ class Search : CustomTitlebarActivityBase(R.menu.search_actionbar_menu) {
}
currentBookRadioButton.text = currentBookName

binding.textClear.setOnClickListener({binding.searchText.setText("")})

Log.i(TAG, "Finished displaying Search view")
}

Expand Down Expand Up @@ -204,6 +214,7 @@ class Search : CustomTitlebarActivityBase(R.menu.search_actionbar_menu) {
var text = binding.searchText.text.toString()
if (!StringUtils.isEmpty(text)) {

CommonUtils.settings.setString("search_text", text)
// update current intent so search is restored if we return here via history/back
// the current intent is saved by HistoryManager
intent.putExtra(SEARCH_TEXT_SAVE, text)
Expand Down
164 changes: 110 additions & 54 deletions app/src/main/res/layout/search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -24,65 +25,109 @@
app:layout_constraintTop_toBottomOf="@id/searchText"
app:layout_constraintBottom_toTopOf="@id/submit"
>

<!-- horizontal container to force each pair of controls to use half of screen each -->
<LinearLayout android:id="@+id/centreAreaContainer"
android:orientation="horizontal"

<LinearLayout android:id="@+id/rowAreaContainer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

<RadioGroup android:id="@+id/bibleSectionGroup"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:padding="5dip">
<TextView android:id="@+id/sectionGroupPrompt"
android:text="@string/search_bible_section_group_prompt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<RadioButton android:id="@+id/searchAllBible"
android:text="@string/search_all_bible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"/>
<RadioButton android:id="@+id/searchOldTestament"
android:text="@string/search_old_testament"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/searchNewTestament"
android:text="@string/search_new_testament"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/searchCurrentBook"
android:text="@string/search_current_book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/centreAreaContainer1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<CheckBox
android:id="@+id/includeAllEndings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:text="@string/search_include_all_endings"
android:visibility="invisible" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<CheckBox
android:id="@+id/rememberSearchText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/search_remember_search_text" />

<RadioGroup android:id="@+id/wordsGroup"
</LinearLayout>

</LinearLayout>
<!-- horizontal container to force each pair of controls to use half of screen each -->

<LinearLayout android:id="@+id/centreAreaContainer"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:padding="5dip">
<TextView
android:text="@string/search_words_group_prompt"
>

<RadioGroup android:id="@+id/bibleSectionGroup"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<RadioButton android:id="@+id/allWords"
android:layout_width="wrap_content"
android:text="@string/search_all_words"
android:layout_width="0dip"
android:layout_weight="1"
android:padding="5dip">

<TextView android:id="@+id/sectionGroupPrompt"
android:text="@string/search_bible_section_group_prompt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<RadioButton android:id="@+id/searchAllBible"
android:text="@string/search_all_bible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"/>
<RadioButton android:id="@+id/searchOldTestament"
android:text="@string/search_old_testament"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/searchNewTestament"
android:text="@string/search_new_testament"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/searchCurrentBook"
android:text="@string/search_current_book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>

<RadioGroup android:id="@+id/wordsGroup"
android:layout_height="wrap_content"
android:checked="true"/>
<RadioButton android:id="@+id/anyWord"
android:layout_width="wrap_content"
android:text="@string/search_any_word"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/phrase"
android:layout_width="wrap_content"
android:text="@string/search_phrase"
android:layout_height="wrap_content"/>
</RadioGroup>
android:layout_width="0dip"
android:layout_weight="1"
android:padding="5dip">

<TextView
android:text="@string/search_words_group_prompt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<RadioButton android:id="@+id/allWords"
android:layout_width="wrap_content"
android:text="@string/search_all_words"
android:layout_height="wrap_content"
android:checked="true"/>
<RadioButton android:id="@+id/anyWord"
android:layout_width="wrap_content"
android:text="@string/search_any_word"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/phrase"
android:layout_width="wrap_content"
android:text="@string/search_phrase"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
</LinearLayout>
</ScrollView>

Expand All @@ -95,4 +140,15 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/textClear"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="-35dp"
android:layout_marginBottom="-35dp"
android:text="X"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/searchText"
app:layout_constraintStart_toEndOf="@+id/searchText" />
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<string name="search_old_testament">Old Testament</string>
<string name="search_current_book">Current book</string>
<string name="error_executing_search">Invalid search query</string>
<string name="search_remember_search_text">Remember search text</string>
<string name="search_include_all_endings">All endings</string>

<!-- Preferences -->
<string name="prefs_show_verseno_title">Chapter &amp; verse numbers</string>
Expand Down