desc:Loader的所有实现样例

author:wangyimiao
master
yimiao 3 years ago
parent 72f4d5a2be
commit 3982660340

@ -10,11 +10,23 @@ import retrofit2.http.Headers
import retrofit2.http.Path
class CollectionLoader : BaseObserve<CollectionLoader.CollectionApi> {
var myApi: CollectionApi? = null
var myInterceptorApi : CollectionApi? = null
constructor() : super(CollectionApi::class.java)
constructor(interceptors: List<Interceptor>) : super(CollectionApi::class.java, interceptors)
init {
myApi = initService(CollectionApi::class.java)
}
fun init(interceptors: List<Interceptor>) {
myApi = initService(CollectionApi::class.java)
myInterceptorApi = initService(CollectionApi::class.java, interceptors)
}
fun getCollections(pageName: Int, callBack: RequestCallBack<CollectionResponse>) {
observe(api?.getCollections(pageName), callBack)
observe(api.getCollections(pageName), callBack)
}
interface CollectionApi {

@ -14,7 +14,7 @@ import retrofit2.http.Path
class InternetLoader : BaseObserve<InternetLoader.HomeApi>(HomeApi::class.java) {
fun getHomeArticles(pageName: Int, callBack: RequestCallBack<ArticlesResponse>) {
observe(api?.getHomeArticles(pageName), callBack)
observe(api.getHomeArticles(pageName), callBack)
}
interface HomeApi {

@ -11,7 +11,7 @@ class LoginLoader(interceptors: List<Interceptor>) :
BaseObserve<LoginLoader.LoginApi>(LoginApi::class.java, interceptors) {
fun login(userName: String, pwd: String, callBack: RequestCallBack<LoginResponse>) {
observe(api?.login(userName, pwd), callBack)
observe(api.login(userName, pwd), callBack)
}
interface LoginApi {

@ -25,9 +25,7 @@ import javax.net.ssl.SSLHandshakeException
* @since 2021/7/28
*/
open class BaseObserve<T> {
var api: T? = null
constructor()
var api: T
constructor(clazz: Class<T>) {
api = RequestManager.create(clazz)
@ -40,7 +38,7 @@ open class BaseObserve<T> {
/**
* 提供方法给外部获取API
*/
fun getAPI(): T? {
fun getAPI(): T {
return api
}

Loading…
Cancel
Save