Fix Custom Location bug

This commit is contained in:
Tommaso Berlose
2017-10-22 21:34:48 +02:00
parent a97aa24ff7
commit c8dd8f711e
8 changed files with 27 additions and 23 deletions

View File

@ -51,7 +51,7 @@ class ChooseApplicationActivity : AppCompatActivity() {
location.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(text: Editable?) {
Thread().run {
val appsFiltered = appList.filter { pm.getApplicationLabel(it).toString().contains(text.toString(), true) }
val appsFiltered = if (text == null || text.equals("")) appList else appList.filter { pm.getApplicationLabel(it).toString().contains(text.toString(), true) }
EventBus.getDefault().post(ApplicationListEvent(appsFiltered, true))
}
}

View File

@ -70,14 +70,18 @@ class CustomLocationActivity : AppCompatActivity() {
location.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(text: Editable?) {
Thread().run {
val coder = Geocoder(this@CustomLocationActivity)
try {
val addresses = coder.getFromLocationName(text.toString(), 10) as ArrayList<Address>
EventBus.getDefault().post(CustomLocationEvent(addresses))
} catch (ignored: Exception) {
EventBus.getDefault().post(CustomLocationEvent(ArrayList<Address>()))
if (text != null && !text.equals("")) {
Thread().run {
val coder = Geocoder(this@CustomLocationActivity)
try {
val addresses = coder.getFromLocationName(text.toString(), 10) as ArrayList<Address>
EventBus.getDefault().post(CustomLocationEvent(addresses))
} catch (ignored: Exception) {
EventBus.getDefault().post(CustomLocationEvent(ArrayList<Address>()))
}
}
} else {
EventBus.getDefault().post(CustomLocationEvent(ArrayList<Address>()))
}
}