From 398266034008f0662fcef4730c477a31f55a6960 Mon Sep 17 00:00:00 2001 From: yimiao Date: Tue, 3 Aug 2021 10:01:51 +0800 Subject: [PATCH] =?UTF-8?q?desc:Loader=E7=9A=84=E6=89=80=E6=9C=89=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=A0=B7=E4=BE=8B=20author:wangyimiao?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commonlibtest/manager/CollectionLoader.kt | 14 +++++++++++++- .../common/commonlibtest/manager/InternetLoader.kt | 2 +- .../common/commonlibtest/manager/LoginLoader.kt | 2 +- .../java/com/common/commonlib/net/BaseObserve.kt | 6 ++---- 4 files changed, 17 insertions(+), 7 deletions(-) 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 }