Hide edit text cursor on list scroll

This commit is contained in:
Kirill Kamakin
2022-11-20 15:49:14 +01:00
parent cadb762ed4
commit d7c94d29d4
5 changed files with 31 additions and 27 deletions

View File

@@ -20,6 +20,7 @@ import gq.kirmanak.mealient.NavGraphDirections.Companion.actionGlobalBaseURLFrag
import gq.kirmanak.mealient.NavGraphDirections.Companion.actionGlobalRecipesListFragment
import gq.kirmanak.mealient.R
import gq.kirmanak.mealient.databinding.MainActivityBinding
import gq.kirmanak.mealient.extensions.collectWhenResumed
import gq.kirmanak.mealient.extensions.isDarkThemeOn
import gq.kirmanak.mealient.extensions.observeOnce
import gq.kirmanak.mealient.logging.Logger
@@ -69,6 +70,10 @@ class MainActivity : AppCompatActivity(R.layout.main_activity) {
isAppearanceLightStatusBars = isAppearanceLightBars
}
viewModel.uiStateLive.observe(this, ::onUiStateChange)
collectWhenResumed(viewModel.clearSearchViewFocus) {
logger.d { "clearSearchViewFocus(): received event" }
binding.toolbar.clearSearchFocus()
}
}
private fun onNavigationItemSelected(menuItem: MenuItem): Boolean {

View File

@@ -8,8 +8,11 @@ import gq.kirmanak.mealient.data.baseurl.ServerInfoRepo
import gq.kirmanak.mealient.data.disclaimer.DisclaimerStorage
import gq.kirmanak.mealient.data.recipes.RecipeRepo
import gq.kirmanak.mealient.logging.Logger
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import javax.inject.Inject
@@ -32,6 +35,9 @@ class MainActivityViewModel @Inject constructor(
private val _startDestination = MutableLiveData<Int>()
val startDestination: LiveData<Int> = _startDestination
private val _clearSearchViewFocusChannel = Channel<Unit>()
val clearSearchViewFocus: Flow<Unit> = _clearSearchViewFocusChannel.receiveAsFlow()
init {
authRepo.isAuthorizedFlow
.onEach { isAuthorized -> updateUiState { it.copy(isAuthorized = isAuthorized) } }
@@ -59,4 +65,9 @@ class MainActivityViewModel @Inject constructor(
logger.v { "onSearchQuery() called with: query = $query" }
recipeRepo.updateNameQuery(query)
}
fun clearSearchViewFocus() {
logger.v { "clearSearchViewFocus() called" }
_clearSearchViewFocusChannel.trySend(Unit)
}
}

View File

@@ -61,8 +61,8 @@ class RecipesListFragment : Fragment(R.layout.fragment_recipes_list) {
@SuppressLint("ClickableViewAccessibility")
private fun hideKeyboardOnScroll() {
binding.recipes.setOnTouchListener { view, _ ->
view?.hideKeyboard()
binding.recipes.setOnTouchListener { _, _ ->
activityViewModel.clearSearchViewFocus()
false
}
}
@@ -155,18 +155,12 @@ private fun Throwable.toLoadErrorReasonText(): Int? = when (this) {
}
private fun <T : Any, VH : RecyclerView.ViewHolder> PagingDataAdapter<T, VH>.refreshErrors(): Flow<Throwable> {
return loadStateFlow
.map { it.refresh }
.valueUpdatesOnly()
.filterIsInstance<LoadState.Error>()
return loadStateFlow.map { it.refresh }.valueUpdatesOnly().filterIsInstance<LoadState.Error>()
.map { it.error }
}
private fun <T : Any, VH : RecyclerView.ViewHolder> PagingDataAdapter<T, VH>.appendPaginationEnd(): Flow<Unit> {
return loadStateFlow
.map { it.append.endOfPaginationReached }
.valueUpdatesOnly()
.filter { it }
return loadStateFlow.map { it.append.endOfPaginationReached }.valueUpdatesOnly().filter { it }
.map { }
}