manage 'submit' in the text search field
This commit is contained in:
parent
b5b1a5ed4d
commit
68fe52d213
|
@ -7,6 +7,7 @@ import android.os.Handler
|
|||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import io.xdrm.lebonprix.anim.HomeFilterAnimation
|
||||
|
@ -93,7 +94,41 @@ class HomeActivity : AppCompatActivity() {
|
|||
|
||||
|
||||
// launch search
|
||||
search_button.setOnClickListener {
|
||||
search.setOnKeyListener { v, keyCode, event ->
|
||||
if( event.action != KeyEvent.ACTION_DOWN || keyCode != KeyEvent.KEYCODE_ENTER )
|
||||
return@setOnKeyListener false
|
||||
|
||||
launch_search()
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
search_button.setOnClickListener { launch_search() }
|
||||
|
||||
updateCategories(JSONArray("[]"))
|
||||
|
||||
}
|
||||
|
||||
private fun categoryCoordinator(keywords: String){
|
||||
val now = System.currentTimeMillis()
|
||||
if( last_search_time > 0 && now-last_search_time < HomeActivity.SEARCH_KEY_TIMEOUT )
|
||||
return
|
||||
|
||||
if( keywords == last_search )
|
||||
return
|
||||
|
||||
last_search_time = now
|
||||
last_search = keywords
|
||||
|
||||
if( httpJob != null && httpJob!!.isActive ) {
|
||||
httpJob!!.cancel()
|
||||
underline_animator.animateContinue(1F).during(0).start()
|
||||
}
|
||||
|
||||
httpJob = GlobalScope.launch {
|
||||
updateCategories( apiCategories.fetch(last_search) )
|
||||
}
|
||||
}
|
||||
|
||||
private fun launch_search(){
|
||||
val selectedCategories = getCategories()
|
||||
|
||||
// (1) Loader
|
||||
|
@ -140,35 +175,8 @@ class HomeActivity : AppCompatActivity() {
|
|||
startActivity(int)
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updateCategories(JSONArray("[]"))
|
||||
|
||||
}
|
||||
|
||||
private fun categoryCoordinator(keywords: String){
|
||||
val now = System.currentTimeMillis()
|
||||
if( last_search_time > 0 && now-last_search_time < HomeActivity.SEARCH_KEY_TIMEOUT )
|
||||
return
|
||||
|
||||
if( keywords == last_search )
|
||||
return
|
||||
|
||||
last_search_time = now
|
||||
last_search = keywords
|
||||
|
||||
if( httpJob != null && httpJob!!.isActive ) {
|
||||
httpJob!!.cancel()
|
||||
underline_animator.animateContinue(1F).during(0).start()
|
||||
}
|
||||
|
||||
httpJob = GlobalScope.launch {
|
||||
updateCategories( apiCategories.fetch(last_search) )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun updateCategories(categories: JSONArray){
|
||||
// 1. Update categories
|
||||
categoryStore.data.clear()
|
||||
|
|
Loading…
Reference in New Issue