Skip to content

Commit

Permalink
Fix crash when mycroft ip is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Dec 1, 2020
1 parent e4ea06a commit 087df31
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,21 @@ class SpeechViewModel(application: Application) : AndroidViewModel(application)

fun sendRequest(requestPhrase: String) {
val mycroftIp = PreferenceManager.getDefaultSharedPreferences(this.getApplication()).getString("mycroft_ip", null)
if(mycroftIp == null){
if(mycroftIp.isNullOrBlank()){
spokenList.postValue(spokenList.value.orEmpty().toMutableList().apply {
this.add(Utterance(UtteranceActor.MYCROFT, "Impostare l'ip di mycroft sulle impostazioni"))
})
}
GlobalScope.launch(Dispatchers.IO) {
MycroftRequestUseCase().postRequest(mycroftIp!!, requestPhrase).consume(onSuccess = {
Log.i("response", "response: " + it)
spokenList.postValue(spokenList.value.orEmpty().toMutableList().apply {
this.add(Utterance(UtteranceActor.MYCROFT, it))
})
}, onError = {
} else {
GlobalScope.launch(Dispatchers.IO) {
MycroftRequestUseCase().postRequest(mycroftIp!!, requestPhrase).consume(onSuccess = {
Log.i("response", "response: " + it)
spokenList.postValue(spokenList.value.orEmpty().toMutableList().apply {
this.add(Utterance(UtteranceActor.MYCROFT, it))
})
}, onError = {

})
})
}
}
}
}

0 comments on commit 087df31

Please sign in to comment.