diff --git a/app/src/main/java/com/common/commonlibtest/MainActivity.java b/app/src/main/java/com/common/commonlibtest/MainActivity.java index f55c5e1..2b1ee28 100644 --- a/app/src/main/java/com/common/commonlibtest/MainActivity.java +++ b/app/src/main/java/com/common/commonlibtest/MainActivity.java @@ -6,12 +6,18 @@ import android.os.Bundle; import android.util.Log; import com.common.commonlib.net.RequestCallBack; +import com.common.commonlib.net.interceptor.HttpCommonInterceptor; import com.common.commonlibtest.bean.ArticlesResponse; +import com.common.commonlibtest.bean.CollectionResponse; +import com.common.commonlibtest.manager.CollectionLoader; import com.common.commonlibtest.manager.InternetLoader; import com.yinuo.commonlibtest.databinding.ActivityMainBinding; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; + public class MainActivity extends AppCompatActivity { private static final String TAG = MainActivity.class.getSimpleName(); ActivityMainBinding binding; @@ -44,5 +50,29 @@ public class MainActivity extends AppCompatActivity { } }); }); + + binding.btn.setOnClickListener(l -> { + List interceptors = new ArrayList<>(); + HttpCommonInterceptor.Builder builder = new HttpCommonInterceptor.Builder(); + builder.addHeadParams("Cookie", "loginUserName_wanandroid_com=wang11;token_pass_wanandroid_com=6fbec4fe15d69af8b4531171798f3926;loginUserName=wang11;token_pass=6fbec4fe15d69af8b4531171798f3926"); + interceptors.add(builder.build()); + CollectionLoader loader = new CollectionLoader(interceptors); + loader.getCollections(0, new RequestCallBack() { + @Override + public void onResult(CollectionResponse result) { + Log.d(TAG, "onResult"); + } + + @Override + public void onError(@Nullable String error) { + Log.d(TAG, "onError"); + } + + @Override + public void onComplete() { + Log.d(TAG, "onComplete"); + } + }); + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/common/commonlibtest/bean/CollectionData.kt b/app/src/main/java/com/common/commonlibtest/bean/CollectionData.kt new file mode 100644 index 0000000..6abcdb5 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/bean/CollectionData.kt @@ -0,0 +1,15 @@ +package com.common.commonlibtest.bean + +import android.os.Parcelable +import com.common.commonlib.net.bean.BaseResponse +import kotlinx.android.parcel.Parcelize + +@Parcelize +data class CollectionData(var curPage: Int = 0) : Parcelable { + var datas: List
? = null + var offset: Int = 0 + var over: Boolean = false + var pageCount: Int = 0 + var size: Int = 0 + var total: Int = 0 +} diff --git a/app/src/main/java/com/common/commonlibtest/bean/CollectionResponse.kt b/app/src/main/java/com/common/commonlibtest/bean/CollectionResponse.kt new file mode 100644 index 0000000..89a9934 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/bean/CollectionResponse.kt @@ -0,0 +1,8 @@ +package com.common.commonlibtest.bean + +import android.os.Parcelable +import com.common.commonlib.net.bean.BaseResponse +import kotlinx.android.parcel.Parcelize + +@Parcelize +data class CollectionResponse(var data: CollectionData) : BaseResponse(), Parcelable diff --git a/app/src/main/java/com/common/commonlibtest/manager/CollectionLoader.kt b/app/src/main/java/com/common/commonlibtest/manager/CollectionLoader.kt new file mode 100644 index 0000000..8d51636 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/manager/CollectionLoader.kt @@ -0,0 +1,29 @@ +package com.common.commonlibtest.manager + +import com.common.commonlib.net.BaseObserve +import com.common.commonlib.net.RequestCallBack +import com.common.commonlibtest.bean.CollectionResponse +import io.reactivex.Observable +import okhttp3.Interceptor +import retrofit2.http.GET +import retrofit2.http.Headers +import retrofit2.http.Path + +class CollectionLoader(interceptors: List) : + BaseObserve() { + private val api: CollectionApi + + init { + api = initService(CollectionApi::class.java, interceptors) + } + + fun getCollections(pageName: Int, callBack: RequestCallBack) { + observe(api.getCollections(pageName), callBack) + } + + interface CollectionApi { + @Headers("baseurl:debug1") + @GET("/lg/collect/list/{pageNum}/json") + fun getCollections(@Path("pageNum") pageNum: Int): Observable + } +} \ No newline at end of file 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 1e74af8..c88a652 100644 --- a/app/src/main/java/com/common/commonlibtest/manager/InternetLoader.kt +++ b/app/src/main/java/com/common/commonlibtest/manager/InternetLoader.kt @@ -8,6 +8,9 @@ import retrofit2.http.GET import retrofit2.http.Headers import retrofit2.http.Path +/** + * 网络请求样例 + */ class InternetLoader : BaseObserve() { var homeApi: HomeApi diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7b64f39..0e19d78 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - tools:context=".MainActivity"> + android:layout_height="match_parent"> +