diff --git a/app/src/main/java/com/common/commonlibtest/manager/CollectionLoader.kt b/app/src/main/java/com/common/commonlibtest/manager/CollectionLoader.kt index 2419757..dbd23e5 100644 --- a/app/src/main/java/com/common/commonlibtest/manager/CollectionLoader.kt +++ b/app/src/main/java/com/common/commonlibtest/manager/CollectionLoader.kt @@ -10,11 +10,23 @@ import retrofit2.http.Headers import retrofit2.http.Path class CollectionLoader : BaseObserve { + var myApi: CollectionApi? = null + var myInterceptorApi : CollectionApi? = null + constructor() : super(CollectionApi::class.java) constructor(interceptors: List) : super(CollectionApi::class.java, interceptors) + init { + myApi = initService(CollectionApi::class.java) + } + + fun init(interceptors: List) { + myApi = initService(CollectionApi::class.java) + myInterceptorApi = initService(CollectionApi::class.java, interceptors) + } + fun getCollections(pageName: Int, callBack: RequestCallBack) { - observe(api?.getCollections(pageName), callBack) + observe(api.getCollections(pageName), callBack) } interface CollectionApi { diff --git a/app/src/main/java/com/common/commonlibtest/manager/InternetLoader.kt b/app/src/main/java/com/common/commonlibtest/manager/InternetLoader.kt index 8536dda..c8ae63d 100644 --- a/app/src/main/java/com/common/commonlibtest/manager/InternetLoader.kt +++ b/app/src/main/java/com/common/commonlibtest/manager/InternetLoader.kt @@ -14,7 +14,7 @@ import retrofit2.http.Path class InternetLoader : BaseObserve(HomeApi::class.java) { fun getHomeArticles(pageName: Int, callBack: RequestCallBack) { - observe(api?.getHomeArticles(pageName), callBack) + observe(api.getHomeArticles(pageName), callBack) } interface HomeApi { diff --git a/app/src/main/java/com/common/commonlibtest/manager/LoginLoader.kt b/app/src/main/java/com/common/commonlibtest/manager/LoginLoader.kt index 812a471..79b7d15 100644 --- a/app/src/main/java/com/common/commonlibtest/manager/LoginLoader.kt +++ b/app/src/main/java/com/common/commonlibtest/manager/LoginLoader.kt @@ -11,7 +11,7 @@ class LoginLoader(interceptors: List) : BaseObserve(LoginApi::class.java, interceptors) { fun login(userName: String, pwd: String, callBack: RequestCallBack) { - observe(api?.login(userName, pwd), callBack) + observe(api.login(userName, pwd), callBack) } interface LoginApi { diff --git a/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt b/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt index 48a85b7..a665033 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt @@ -25,9 +25,7 @@ import javax.net.ssl.SSLHandshakeException * @since 2021/7/28 */ open class BaseObserve { - var api: T? = null - - constructor() + var api: T constructor(clazz: Class) { api = RequestManager.create(clazz) @@ -40,7 +38,7 @@ open class BaseObserve { /** * 提供方法给外部获取API */ - fun getAPI(): T? { + fun getAPI(): T { return api }