Skip to content

Commit

Permalink
Use custom searchview
Browse files Browse the repository at this point in the history
Closes #2146
  • Loading branch information
kylecorry31 committed Jan 5, 2024
1 parent 07cb018 commit 11de32d
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 55 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.core.view.isVisible
import com.kylecorry.ceres.list.ListItemMapper
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.databinding.ViewGroupableSelectorBinding
import com.kylecorry.trail_sense.shared.extensions.setOnQueryTextListener
import com.kylecorry.trail_sense.shared.grouping.Groupable
import com.kylecorry.trail_sense.shared.lists.GroupListManager

Expand Down Expand Up @@ -36,9 +35,8 @@ class GroupableSelectView<T : Groupable>(

// Search
binding.searchbox.isVisible = searchEnabled
binding.searchbox.setOnQueryTextListener { _, _ ->
binding.searchbox.setOnSearchListener {
manager.search(binding.searchbox.query)
true
}

// List items
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.kylecorry.trail_sense.shared.lists

import android.widget.TextView
import androidx.appcompat.widget.SearchView
import com.kylecorry.andromeda.core.tryOrLog
import com.kylecorry.ceres.list.CeresListView
import com.kylecorry.ceres.list.ListItemMapper
import com.kylecorry.trail_sense.shared.extensions.setOnQueryTextListener
import com.kylecorry.trail_sense.shared.grouping.Groupable

fun <T : Groupable> GroupListManager<T>.bind(view: SearchView) {
view.setOnQueryTextListener { _, _ ->
this.search(view.query)
true
fun <T : Groupable> GroupListManager<T>.bind(view: com.kylecorry.trail_sense.shared.views.SearchView) {
view.setOnSearchListener {
this.search(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.kylecorry.trail_sense.shared.views

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.core.widget.addTextChangedListener
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.databinding.ViewSearchBinding

class SearchView(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
private val binding: ViewSearchBinding
private var onSearch: ((String) -> Unit)? = null

var query: String
get() = binding.searchViewEditText.text.toString()
set(value) {
binding.searchViewEditText.setText(value)
}

init {
inflate(context, R.layout.view_search, this)
binding = ViewSearchBinding.bind(this)
binding.searchViewEditText.addTextChangedListener {
onSearch?.invoke(binding.searchViewEditText.text.toString())
}
}

fun setOnSearchListener(listener: ((String) -> Unit)?) {
onSearch = listener
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.kylecorry.trail_sense.databinding.ListItemToolBinding
import com.kylecorry.trail_sense.quickactions.ToolsQuickActionBinder
import com.kylecorry.trail_sense.shared.CustomUiUtils
import com.kylecorry.trail_sense.shared.UserPreferences
import com.kylecorry.trail_sense.shared.extensions.setOnQueryTextListener
import com.kylecorry.trail_sense.tools.guide.infrastructure.UserGuideUtils
import com.kylecorry.trail_sense.tools.ui.items.ToolListItem
import com.kylecorry.trail_sense.tools.ui.items.ToolListItemStyle
Expand Down Expand Up @@ -87,9 +86,8 @@ class ToolsFragment : BoundFragment<FragmentToolsBinding>() {
findNavController().navigate(R.id.action_settings)
}

binding.searchbox.setOnQueryTextListener { _, _ ->
binding.searchbox.setOnSearchListener {
updateTools()
true
}

CustomUiUtils.oneTimeToast(
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/fragment_beacon_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
app:showSubtitle="false"
app:title="@string/beacons" />

<androidx.appcompat.widget.SearchView
<com.kylecorry.trail_sense.shared.views.SearchView
android:id="@+id/searchbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/beacon_title"
app:queryHint="@string/search" />
app:layout_constraintTop_toBottomOf="@id/beacon_title" />

<com.kylecorry.ceres.list.CeresListView
android:id="@+id/beacon_recycler"
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/layout/fragment_map_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@
app:showSubtitle="false"
app:title="@string/photo_maps" />

<androidx.appcompat.widget.SearchView
<com.kylecorry.trail_sense.shared.views.SearchView
android:id="@+id/searchbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/map_list_title"
app:queryHint="@string/search" />
app:layout_constraintTop_toBottomOf="@id/map_list_title" />

<com.kylecorry.ceres.list.CeresListView
android:id="@+id/map_list"
style="@style/AppTheme.ListViewWithFab"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="16dp"
style="@style/AppTheme.ListViewWithFab"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/fragment_paths.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
app:showSubtitle="false"
app:title="@string/paths" />

<androidx.appcompat.widget.SearchView
<com.kylecorry.trail_sense.shared.views.SearchView
android:id="@+id/searchbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/paths_title"
app:queryHint="@string/search" />
app:layout_constraintTop_toBottomOf="@id/paths_title" />

<com.kylecorry.ceres.list.CeresListView
android:id="@+id/paths_list"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/fragment_tools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.SearchView
<com.kylecorry.trail_sense.shared.views.SearchView
android:id="@+id/searchbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -13,8 +13,7 @@
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toStartOf="@id/settings_btn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:queryHint="@string/search" />
app:layout_constraintTop_toTopOf="parent" />

<ImageButton
android:id="@+id/settings_btn"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/view_groupable_selector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
tools:title="@string/beacons" />

<!--TODO: Make this a searchbox icon-->
<androidx.appcompat.widget.SearchView
<com.kylecorry.trail_sense.shared.views.SearchView
android:id="@+id/searchbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:queryHint="@string/search" />
android:layout_marginEnd="16dp" />

<TextView
android:id="@+id/empty_text"
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/layout/view_search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/rounded_rectangle"
android:backgroundTint="?attr/colorBackgroundFloating"
android:elevation="2dp">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/search_view_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxBackgroundMode="none"
app:endIconMode="clear_text"
app:hintEnabled="false"
app:startIconDrawable="@drawable/ic_search">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/search_view_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/search" />

</com.google.android.material.textfield.TextInputLayout>
</FrameLayout>
10 changes: 0 additions & 10 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<item name="floatingActionButtonStyle">@style/Widget.App.FloatingActionButton</item>
<item name="floatingActionButtonSmallStyle">@style/Widget.App.FloatingActionButtonSmall
</item>
<item name="searchViewStyle">@style/SearchViewTheme</item>
</style>

<!--Override this for other Android versions-->
Expand Down Expand Up @@ -87,15 +86,6 @@
<item name="materialThemeOverlay">@style/ThemeOverlay.App.FloatingActionButton</item>
</style>

<style name="SearchViewTheme" parent="Widget.AppCompat.SearchView">
<item name="android:background">@drawable/rounded_rectangle</item>
<item name="android:backgroundTint">?attr/colorSurface</item>
<item name="android:padding">0dp</item>
<item name="android:elevation">2dp</item>
<item name="queryBackground">@android:color/transparent</item>
<item name="iconifiedByDefault">false</item>
</style>

<style name="ThemeOverlay.App.FloatingActionButton" parent="">
<item name="colorContainer">?attr/colorPrimary</item>
<item name="colorOnContainer">?attr/colorOnPrimary</item>
Expand Down

0 comments on commit 11de32d

Please sign in to comment.