Properly update search bar content description when icon changes

This commit is contained in:
Ensar Sarajčić 2023-07-18 12:05:59 +02:00
parent b055e0508f
commit 28c43d15e9

View file

@ -58,6 +58,7 @@ class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context
isSearchOpen = true
onSearchOpenListener?.invoke()
top_toolbar_search_icon.setImageResource(R.drawable.ic_arrow_left_vector)
top_toolbar_search_icon.contentDescription = resources.getString(R.string.back)
}
fun closeSearch() {
@ -66,6 +67,7 @@ class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context
top_toolbar_search.setText("")
if (!useArrowIcon) {
top_toolbar_search_icon.setImageResource(R.drawable.ic_search_vector)
top_toolbar_search_icon.contentDescription = resources.getString(R.string.search)
}
(context as? Activity)?.hideKeyboard()
}
@ -87,13 +89,14 @@ class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context
fun toggleForceArrowBackIcon(useArrowBack: Boolean) {
this.useArrowIcon = useArrowBack
val icon = if (useArrowBack) {
R.drawable.ic_arrow_left_vector
val (icon, accessibilityString) = if (useArrowBack) {
Pair(R.drawable.ic_arrow_left_vector, R.string.back)
} else {
R.drawable.ic_search_vector
Pair(R.drawable.ic_search_vector, R.string.search)
}
top_toolbar_search_icon.setImageResource(icon)
top_toolbar_search_icon.contentDescription = resources.getString(accessibilityString)
}
fun updateColors() {