|
@@ -5,6 +5,12 @@ import android.util.Log
|
|
|
import com.google.gson.Gson
|
|
|
import com.sikey.veryfit.component.network.http.BaseResponse
|
|
|
import com.sikey.veryfit.component.network.http.utils.TypeUtil
|
|
|
+import com.sikey.veryfit.utils.ToastUtils
|
|
|
+import kotlinx.coroutines.DelicateCoroutinesApi
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
+import kotlinx.coroutines.GlobalScope
|
|
|
+import kotlinx.coroutines.launch
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
import okhttp3.ResponseBody
|
|
|
import org.json.JSONObject
|
|
|
import retrofit2.Converter
|
|
@@ -16,6 +22,7 @@ class CustomBodyConverter<T>(private val type: Type) : Converter<ResponseBody, B
|
|
|
const val TAG = "CustomBodyConverter"
|
|
|
}
|
|
|
|
|
|
+ @OptIn(DelicateCoroutinesApi::class)
|
|
|
override fun convert(value: ResponseBody): BaseResponse<T> {
|
|
|
Log.d(TAG, "convert == type: $type; value: $value")
|
|
|
try {
|
|
@@ -28,6 +35,14 @@ class CustomBodyConverter<T>(private val type: Type) : Converter<ResponseBody, B
|
|
|
model.message = jsonObject.getString("message")
|
|
|
jsonObject.remove("message")
|
|
|
|
|
|
+ if (model.code != "200" && model.message != null) {
|
|
|
+ GlobalScope.launch {
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ ToastUtils.showLongToast(model.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
val result = jsonObject.toString()
|
|
|
if (!TextUtils.isEmpty(result) && !"null".equals(result, true)) {
|
|
|
model.mData = Gson().fromJson(result, this.type)
|