Не бросает на нужный кусок кода
Я не могу элементарно проверить работу своего кода и я понять не могу почему меня бросает на onFailure. Вот мой код:
private fun initProfileStatus() {
binding.appBarMain.onOffBtn.setOnClickListener {
binding.appBarMain.loader.visibility = View.VISIBLE
val network: MainNetwork =
getNetworkService()
val builder = AlertDialog.Builder(this)
if (i == 0) {
when {
!isConnected() -> {
builder.setTitle("Внимание!")
builder.setMessage("Требуется подключение к интернету")
builder.setNegativeButton("Ок") {dialog, i ->
binding.appBarMain.loader.visibility = View.GONE
return@setNegativeButton
}
builder.show()
}
!isLocationEnabled(this) -> {
builder.setTitle("Внимание!")
builder.setMessage("Требуется подключение к геолокации")
builder.setNegativeButton("Ок") {dialog, i ->
binding.appBarMain.loader.visibility = View.GONE
return@setNegativeButton
}
builder.show()
}
else -> {
lifecycleScope.launch(Dispatchers.Main) {
// Create JSON using JSONObject
val jsonObject = JSONObject()
jsonObject.put("status", "online")
jsonObject.put("track", "")
val jsonObjectString = jsonObject.toString()
val requestBody = jsonObjectString.toRequestBody("application/json".toMediaTypeOrNull())
kotlin.runCatching {
user = network.setProfileStatus(bearerToken,requestBody)
}.onSuccess {
binding.appBarMain.loader.visibility = View.GONE
Log.wtf("ya_user_status", user?.data?.status)
showStatusDialog(user?.data?.status!!)
i = 1
binding.appBarMain.createPosButton.visibility = View.GONE
binding.appBarMain.myRoute.visibility = View.GONE
binding.appBarMain.bottomSheetGrip.visibility = View.GONE
binding.appBarMain.createSupplyButton.visibility = View.VISIBLE
binding.appBarMain.onOffBtn.background.setTint(Color.GREEN)
binding.appBarMain.animationOnline.visibility = View.VISIBLE
isOnline = true
startTrackingLocation()
}.onFailure {
binding.appBarMain.loader.visibility = View.GONE
Log.wtf("ya_user_status", " something wrong")
}
}
}
}
} else {
lifecycleScope.launch(Dispatchers.Main) {
stopTrackingLocation()
// Create JSON using JSONObject
val jsonObject = JSONObject()
jsonObject.put("status", "offline")
jsonObject.put("track", SystemUtils.track)
val jsonObjectString = jsonObject.toString()
val requestBody = jsonObjectString.toRequestBody("application/json".toMediaTypeOrNull())
kotlin.runCatching {
user = network.setProfileStatus(bearerToken,requestBody)
}.onSuccess {
binding.appBarMain.createPosButton.visibility = View.VISIBLE
binding.appBarMain.myRoute.visibility = View.GONE
binding.appBarMain.bottomSheetGrip.visibility = View.GONE
binding.appBarMain.createSupplyButton.visibility = View.GONE
binding.appBarMain.loader.visibility = View.GONE
binding.appBarMain.onOffBtn.background.setTint(Color.RED)
binding.appBarMain.animationOnline.visibility = View.GONE
isOnline = false
Log.wtf("ya_user_status", user?.data?.status)
showStatusDialog(user?.data?.status!!)
i = 0
SystemUtils.track = ""
}.onFailure {
binding.appBarMain.loader.visibility = View.GONE
Log.wtf("ya_user_status", " something wrong")
}
}
}
}
}
В логах мне выводит something wrong при нажатии на кнопку