Fixed the close tab icon size issue.

* Created an extension function to set up the SearchView. It now configures the toolTipText and width for the close icon of the SearchView.
* With this extension function, we have applied these properties to every SearchView used in the application, such as in LanguageFragment, SearchFragment, (History/Bookmark/Notes), and OnlineLibraryFragment.
This commit is contained in:
MohitMaliFtechiz 2024-02-15 14:55:50 +05:30
parent e860cf9aa0
commit 211056c4ff
7 changed files with 111 additions and 30 deletions

View File

@ -43,6 +43,7 @@ import org.kiwix.kiwixmobile.core.base.BaseFragment
import org.kiwix.kiwixmobile.core.extensions.closeKeyboard import org.kiwix.kiwixmobile.core.extensions.closeKeyboard
import org.kiwix.kiwixmobile.core.extensions.getToolbarNavigationIcon import org.kiwix.kiwixmobile.core.extensions.getToolbarNavigationIcon
import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription
import org.kiwix.kiwixmobile.core.extensions.setUpSearchView
import org.kiwix.kiwixmobile.core.extensions.viewModel import org.kiwix.kiwixmobile.core.extensions.viewModel
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.utils.SimpleTextListener import org.kiwix.kiwixmobile.core.utils.SimpleTextListener
@ -125,12 +126,15 @@ class LanguageFragment : BaseFragment() {
object : MenuProvider { object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.menu_language, menu) menuInflater.inflate(R.menu.menu_language, menu)
val search = menu.findItem(R.id.menu_language_search) val search = menu.findItem(R.id.menu_language_search).actionView as SearchView
(search.actionView as SearchView).setOnQueryTextListener( search.apply {
SimpleTextListener { query, _ -> setUpSearchView(requireActivity())
languageViewModel.actions.offer(Filter(query)) setOnQueryTextListener(
} SimpleTextListener { query, _ ->
) languageViewModel.actions.offer(Filter(query))
}
)
}
} }
override fun onMenuItemSelected(menuItem: MenuItem): Boolean { override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
@ -140,6 +144,7 @@ class LanguageFragment : BaseFragment() {
closeKeyboard() closeKeyboard()
true true
} }
else -> false else -> false
} }
} }
@ -160,6 +165,7 @@ class LanguageFragment : BaseFragment() {
activityLanguageBinding?.languageProgressbar?.hide() activityLanguageBinding?.languageProgressbar?.hide()
languageAdapter.items = state.viewItems languageAdapter.items = state.viewItems
} }
Saving -> Unit Saving -> Unit
} }

View File

@ -67,6 +67,7 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel
import org.kiwix.kiwixmobile.core.extensions.closeKeyboard import org.kiwix.kiwixmobile.core.extensions.closeKeyboard
import org.kiwix.kiwixmobile.core.extensions.coreMainActivity import org.kiwix.kiwixmobile.core.extensions.coreMainActivity
import org.kiwix.kiwixmobile.core.extensions.setBottomMarginToFragmentContainerView import org.kiwix.kiwixmobile.core.extensions.setBottomMarginToFragmentContainerView
import org.kiwix.kiwixmobile.core.extensions.setUpSearchView
import org.kiwix.kiwixmobile.core.extensions.snack import org.kiwix.kiwixmobile.core.extensions.snack
import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
@ -219,11 +220,14 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
val getZimItem = menu.findItem(R.id.get_zim_nearby_device) val getZimItem = menu.findItem(R.id.get_zim_nearby_device)
getZimItem?.isVisible = false getZimItem?.isVisible = false
(searchItem?.actionView as? SearchView)?.setOnQueryTextListener( (searchItem?.actionView as? SearchView)?.apply {
SimpleTextListener { query, _ -> setUpSearchView(requireActivity())
zimManageViewModel.requestFiltering.onNext(query) setOnQueryTextListener(
} SimpleTextListener { query, _ ->
) zimManageViewModel.requestFiltering.onNext(query)
}
)
}
zimManageViewModel.requestFiltering.onNext("") zimManageViewModel.requestFiltering.onNext("")
} }
@ -307,9 +311,11 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
hideRecyclerviewAndShowSwipeDownForLibraryErrorText() hideRecyclerviewAndShowSwipeDownForLibraryErrorText()
} }
} }
NetworkState.NOT_CONNECTED -> { NetworkState.NOT_CONNECTED -> {
showNoInternetConnectionError() showNoInternetConnectionError()
} }
else -> {} else -> {}
} }
} }
@ -519,6 +525,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
noInternetSnackbar() noInternetSnackbar()
return return
} }
noWifiWithWifiOnlyPreferenceSet -> { noWifiWithWifiOnlyPreferenceSet -> {
dialogShower.show(WifiOnly, { dialogShower.show(WifiOnly, {
sharedPreferenceUtil.putPrefWifiOnly(false) sharedPreferenceUtil.putPrefWifiOnly(false)
@ -526,6 +533,7 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
}) })
return return
} }
else -> if (sharedPreferenceUtil.showStorageOption) { else -> if (sharedPreferenceUtil.showStorageOption) {
showStorageConfigureDialog() showStorageConfigureDialog()
} else if (!requireActivity().isManageExternalStoragePermissionGranted( } else if (!requireActivity().isManageExternalStoragePermissionGranted(

View File

@ -0,0 +1,56 @@
/*
* Kiwix Android
* Copyright (c) 2024 Kiwix <android.kiwix.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.core.extensions
import android.content.Context
import android.widget.ImageView
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.setPadding
import org.kiwix.kiwixmobile.core.R
const val CLOSE_ICON_PADDING = 30
fun SearchView.setUpSearchView(context: Context) {
val heightAndWidth = context.resources.getDimensionPixelSize(
R.dimen.material_minimum_height_and_width
)
val closeImageButton = findViewById<ImageView>(R.id.search_close_btn)
// set the tooltip on close button to show the description if user long clicks on it.
TooltipCompat.setTooltipText(
closeImageButton,
context.getString(R.string.abc_searchview_description_clear)
)
// override the default width of close image button.
// by default it is 40dp, and the default accessibility width is 48dp
setWidthWithPadding(
closeImageButton,
heightAndWidth,
CLOSE_ICON_PADDING
)
}
fun setWidthWithPadding(imageView: ImageView, width: Int, padding: Int) {
imageView.apply {
val params = layoutParams
params?.width = width
setPadding(padding)
requestLayout()
}
}

View File

@ -64,7 +64,7 @@ class TabsAdapter internal constructor(
val context = parent.context val context = parent.context
val margin16 = context.resources.getDimensionPixelSize(R.dimen.activity_horizontal_margin) val margin16 = context.resources.getDimensionPixelSize(R.dimen.activity_horizontal_margin)
val closeImageWidthAndHeight = val closeImageWidthAndHeight =
context.resources.getDimensionPixelSize(R.dimen.material_minimum_height_and_width) context.resources.getDimensionPixelSize(R.dimen.close_tab_button_size)
val close = ImageView(context) val close = ImageView(context)
.apply { .apply {
id = R.id.tabsAdapterCloseImageView id = R.id.tabsAdapterCloseImageView

View File

@ -46,6 +46,7 @@ import org.kiwix.kiwixmobile.core.databinding.FragmentPageBinding
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isCustomApp import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isCustomApp
import org.kiwix.kiwixmobile.core.extensions.closeKeyboard import org.kiwix.kiwixmobile.core.extensions.closeKeyboard
import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription import org.kiwix.kiwixmobile.core.extensions.setToolTipWithContentDescription
import org.kiwix.kiwixmobile.core.extensions.setUpSearchView
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
import org.kiwix.kiwixmobile.core.page.adapter.Page import org.kiwix.kiwixmobile.core.page.adapter.Page
@ -106,12 +107,15 @@ abstract class PageFragment : OnItemClickListener, BaseFragment(), FragmentActiv
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.menu_page, menu) menuInflater.inflate(R.menu.menu_page, menu)
val search = menu.findItem(R.id.menu_page_search).actionView as SearchView val search = menu.findItem(R.id.menu_page_search).actionView as SearchView
search.queryHint = searchQueryHint search.apply {
search.setOnQueryTextListener( setUpSearchView(requireActivity())
SimpleTextListener { query, _ -> queryHint = searchQueryHint
pageViewModel.actions.offer(Action.Filter(query)) setOnQueryTextListener(
} SimpleTextListener { query, _ ->
) pageViewModel.actions.offer(Action.Filter(query))
}
)
}
} }
@Suppress("ReturnCount") @Suppress("ReturnCount")
@ -121,6 +125,7 @@ abstract class PageFragment : OnItemClickListener, BaseFragment(), FragmentActiv
pageViewModel.actions.offer(Action.Exit) pageViewModel.actions.offer(Action.Exit)
return true return true
} }
R.id.menu_pages_clear -> { R.id.menu_pages_clear -> {
pageViewModel.actions.offer(Action.UserClickedDeleteButton) pageViewModel.actions.offer(Action.UserClickedDeleteButton)
return true return true

View File

@ -54,6 +54,7 @@ import org.kiwix.kiwixmobile.core.base.BaseFragment
import org.kiwix.kiwixmobile.core.databinding.FragmentSearchBinding import org.kiwix.kiwixmobile.core.databinding.FragmentSearchBinding
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.cachedComponent import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.cachedComponent
import org.kiwix.kiwixmobile.core.extensions.coreMainActivity import org.kiwix.kiwixmobile.core.extensions.coreMainActivity
import org.kiwix.kiwixmobile.core.extensions.setUpSearchView
import org.kiwix.kiwixmobile.core.extensions.viewModel import org.kiwix.kiwixmobile.core.extensions.viewModel
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.search.adapter.SearchAdapter import org.kiwix.kiwixmobile.core.search.adapter.SearchAdapter
@ -220,21 +221,25 @@ class SearchFragment : BaseFragment() {
val searchMenuItem = menu.findItem(R.id.menu_search) val searchMenuItem = menu.findItem(R.id.menu_search)
searchMenuItem.expandActionView() searchMenuItem.expandActionView()
searchView = searchMenuItem.actionView as SearchView searchView = searchMenuItem.actionView as SearchView
searchView?.setOnQueryTextListener( searchView?.apply {
SimpleTextListener { query, isSubmit -> setUpSearchView(requireActivity())
if (query.isNotEmpty()) { searchView?.setOnQueryTextListener(
when { SimpleTextListener { query, isSubmit ->
isSubmit -> { if (query.isNotEmpty()) {
// if user press the search/enter button on keyboard, when {
// try to open the article if present isSubmit -> {
getSearchListItemForQuery(query)?.let(::onItemClick) // if user press the search/enter button on keyboard,
} // try to open the article if present
getSearchListItemForQuery(query)?.let(::onItemClick)
}
else -> searchViewModel.actions.trySend(Filter(query)).isSuccess else -> searchViewModel.actions.trySend(Filter(query)).isSuccess
}
} }
} }
} )
) }
searchMenuItem.setOnActionExpandListener(object : OnActionExpandListener { searchMenuItem.setOnActionExpandListener(object : OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem) = false override fun onMenuItemActionExpand(item: MenuItem) = false

View File

@ -22,4 +22,5 @@
<dimen name="material_design_appbar_size">48dp</dimen> <dimen name="material_design_appbar_size">48dp</dimen>
<dimen name="hamburger_icon_size">36dp</dimen> <dimen name="hamburger_icon_size">36dp</dimen>
<dimen name="material_minimum_height_and_width">48dp</dimen> <dimen name="material_minimum_height_and_width">48dp</dimen>
<dimen name="close_tab_button_size">24dp</dimen>
</resources> </resources>