Handle search action
This commit is contained in:
@@ -141,7 +141,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
||||
searchSuggestionViewModel.isIncognitoModeEnabled.observe(this, this::onIncognitoModeChanged)
|
||||
viewBinding.bottomNav?.addOnLayoutChangeListener(this)
|
||||
viewBinding.searchView.addTransitionListener(this)
|
||||
initSearchSuggestions()
|
||||
initSearch()
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
@@ -351,7 +351,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
||||
viewBinding.recyclerViewSearch.setPadding(barsInsets.left, 0, barsInsets.right, barsInsets.bottom)
|
||||
}
|
||||
|
||||
private fun initSearchSuggestions() {
|
||||
private fun initSearch() {
|
||||
val listener = SearchSuggestionListenerImpl(router, viewBinding.searchView, searchSuggestionViewModel)
|
||||
val adapter = SearchSuggestionAdapter(listener)
|
||||
viewBinding.searchView.toolbar.addMenuProvider(
|
||||
@@ -359,6 +359,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
||||
)
|
||||
viewBinding.searchView.editText.addTextChangedListener(listener)
|
||||
viewBinding.recyclerViewSearch.adapter = adapter
|
||||
viewBinding.searchView.editText.setOnEditorActionListener(listener)
|
||||
|
||||
viewBinding.searchView.observeState()
|
||||
.map { it >= SearchView.TransitionState.SHOWING }
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package org.koitharu.kotatsu.search.ui.suggestion
|
||||
|
||||
import android.text.TextWatcher
|
||||
import android.widget.TextView
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.search.domain.SearchKind
|
||||
|
||||
interface SearchSuggestionListener : TextWatcher {
|
||||
interface SearchSuggestionListener : TextWatcher, TextView.OnEditorActionListener {
|
||||
|
||||
fun onMangaClick(manga: Manga)
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.koitharu.kotatsu.search.ui.suggestion
|
||||
|
||||
import android.text.Editable
|
||||
import android.view.KeyEvent
|
||||
import android.widget.TextView
|
||||
import androidx.core.net.toUri
|
||||
import com.google.android.material.search.SearchView
|
||||
import org.koitharu.kotatsu.core.nav.AppRouter
|
||||
@@ -30,6 +32,7 @@ class SearchSuggestionListenerImpl(
|
||||
viewModel.saveQuery(query)
|
||||
}
|
||||
}
|
||||
searchView.hide()
|
||||
} else {
|
||||
searchView.setText(query)
|
||||
}
|
||||
@@ -54,4 +57,17 @@ class SearchSuggestionListenerImpl(
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
viewModel.onQueryChanged(s?.toString().orEmpty())
|
||||
}
|
||||
|
||||
override fun onEditorAction(
|
||||
v: TextView?,
|
||||
actionId: Int,
|
||||
event: KeyEvent?
|
||||
): Boolean {
|
||||
val query = v?.text?.toString()
|
||||
if (query.isNullOrEmpty()) {
|
||||
return false
|
||||
}
|
||||
onQueryClick(query, SearchKind.SIMPLE, true)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.koitharu.kotatsu.search.domain.MangaSearchRepository
|
||||
import org.koitharu.kotatsu.search.ui.suggestion.model.SearchSuggestionItem
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val DEBOUNCE_TIMEOUT = 500L
|
||||
private const val DEBOUNCE_TIMEOUT = 300L
|
||||
private const val MAX_MANGA_ITEMS = 12
|
||||
private const val MAX_QUERY_ITEMS = 16
|
||||
private const val MAX_HINTS_ITEMS = 3
|
||||
|
||||
Reference in New Issue
Block a user