Minimizes keyboard on search screen (#4633)

Adds feature if user clicks on toolbar, on the pages box, or on the tabs
buttons that the keyboard will minimize and focus will be taken off of
search bar.

Further addresses issue #4573
This commit is contained in:
andrewhamilton0 2024-09-01 07:28:55 -04:00 committed by GitHub
parent da54cda88e
commit 49fbe1f408
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -22,9 +22,11 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.MotionEvent
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuProvider
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.keylesspalace.tusky.BottomSheetActivity
import com.keylesspalace.tusky.R
@ -82,6 +84,7 @@ class SearchActivity : BottomSheetActivity(), MenuProvider, SearchView.OnQueryTe
searchViewMenuItem.expandActionView()
searchView = searchViewMenuItem.actionView as SearchView
setupSearchView()
setupClearFocusOnClickListeners()
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
@ -105,6 +108,30 @@ class SearchActivity : BottomSheetActivity(), MenuProvider, SearchView.OnQueryTe
}
}
private fun setupClearFocusOnClickListeners() {
binding.overlayPagesClickView.setOnTouchListener { view, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
searchView.clearFocus()
view.performClick()
}
false
}
binding.toolbar.setOnClickListener {
searchView.clearFocus()
}
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(p0: TabLayout.Tab?) {
searchView.clearFocus()
}
override fun onTabUnselected(p0: TabLayout.Tab?) {}
override fun onTabReselected(p0: TabLayout.Tab?) {
searchView.clearFocus()
}
})
}
private fun setupSearchView() {
searchView.setIconifiedByDefault(false)
searchView.setSearchableInfo(

View File

@ -38,6 +38,12 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<View
android:id="@+id/overlayPagesClickView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent" />
<include layout="@layout/item_status_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>