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:
parent
da54cda88e
commit
49fbe1f408
|
@ -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(
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue