
com.caldremch.http.CoroutineHandler.kt Maven / Gradle / Ivy
The newest version!
package com.caldremch.http
import com.caldremch.http.core.abs.AbsCallback
import com.caldremch.http.core.abs.ICommonRequestEventCallback
import com.caldremch.http.core.framework.handle.IDialogHandle
import com.caldremch.http.core.framework.handle.IRequestHandle
/**
*
* @author Caldremch
*
* @date 2020-01-09 15:38
*
* @email [email protected]
*
* @describe handle data
*
**/
class CoroutineHandler(
private val callback: AbsCallback?,
private val commonRequestEvent: ICommonRequestEventCallback?,
private val dialogEvent: IDialogHandle?,
private val showDialog: Boolean,
private val dialogTips: String,
private val requestHandleEvent: IRequestHandle?,
private val showToast: Boolean
) {
init {
commonRequestEvent?.onStart()
if (showDialog) {
dialogEvent?.dialogShowTiming(dialogTips)
}
}
fun onSuccess(t: T) {
commonRequestEvent?.onSuccess(t)
callback?.onSuccess(t)
if (showDialog) {
dialogEvent?.dialogDismissTiming()
}
commonRequestEvent?.onEnd()
}
fun onError(e: Throwable) {
if (showDialog) {
dialogEvent?.dialogDismissTiming()
}
// /**
// * code is 200, but null T ,[AbsCallback.onSuccess] callback
// */
// if (e is NullDataSuccessException) {
// callback?.onSuccess(null)
// commonRequestEvent?.onEnd()
// return
// }
callback?.onError(e)
commonRequestEvent?.onError(e, showToast)
commonRequestEvent?.onEnd()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy