1.走读代码
2.获取测试域名 3.确认已调试的接口并调试,部分目前无数据,需后续确认 4.请求拦截器添加回调参数打印
正在显示
10 个修改的文件
包含
57 行增加
和
14 行删除
@@ -10,7 +10,8 @@ import java.io.File | @@ -10,7 +10,8 @@ import java.io.File | ||
10 | */ | 10 | */ |
11 | object Constant { | 11 | object Constant { |
12 | // const val BASE_URL = "https://security.brofirst.cn/" | 12 | // const val BASE_URL = "https://security.brofirst.cn/" |
13 | - const val BASE_URL = "http://admin.anqixing.com" | 13 | + const val BASE_URL = "http://security.brofirst.cn/" |
14 | +// const val BASE_URL = "http://admin.anqixing.com" | ||
14 | const val USERNAME_KEY = "username" | 15 | const val USERNAME_KEY = "username" |
15 | const val USERID_KEY = "userid" | 16 | const val USERID_KEY = "userid" |
16 | const val LOGIN_KEY = "login" | 17 | const val LOGIN_KEY = "login" |
@@ -153,6 +153,7 @@ interface ApiService { | @@ -153,6 +153,7 @@ interface ApiService { | ||
153 | @FormUrlEncoded | 153 | @FormUrlEncoded |
154 | @POST("/api/item/paper_list") | 154 | @POST("/api/item/paper_list") |
155 | fun practiceList( | 155 | fun practiceList( |
156 | + @Field("type") type: Int, //所属类型:1=模拟考试,2=专项练习 | ||
156 | @Field("pos_id") pos_id: Int, | 157 | @Field("pos_id") pos_id: Int, |
157 | @Field("page") page: Int, | 158 | @Field("page") page: Int, |
158 | @Field("page_num") page_num: Int | 159 | @Field("page_num") page_num: Int |
@@ -3,7 +3,6 @@ package com.wjx.android.wanandroidmvvm.network | @@ -3,7 +3,6 @@ package com.wjx.android.wanandroidmvvm.network | ||
3 | import android.util.Log | 3 | import android.util.Log |
4 | import com.br_technology.electricityandroid.util.token | 4 | import com.br_technology.electricityandroid.util.token |
5 | import com.br_technology.securitytrain_master.base.common.Constant | 5 | import com.br_technology.securitytrain_master.base.common.Constant |
6 | -import com.br_technology.securitytrain_master.base.common.StateType | ||
7 | import okhttp3.Interceptor | 6 | import okhttp3.Interceptor |
8 | import okhttp3.OkHttpClient | 7 | import okhttp3.OkHttpClient |
9 | import okhttp3.Request | 8 | import okhttp3.Request |
@@ -11,6 +10,10 @@ import okhttp3.Response | @@ -11,6 +10,10 @@ import okhttp3.Response | ||
11 | import retrofit2.Retrofit | 10 | import retrofit2.Retrofit |
12 | import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory | 11 | import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory |
13 | import retrofit2.converter.gson.GsonConverterFactory | 12 | import retrofit2.converter.gson.GsonConverterFactory |
13 | +import java.io.IOException | ||
14 | +import java.nio.Buffer | ||
15 | +import java.nio.charset.Charset | ||
16 | + | ||
14 | 17 | ||
15 | /** | 18 | /** |
16 | * Time: 7/26/2021 10:11 | 19 | * Time: 7/26/2021 10:11 |
@@ -19,9 +22,9 @@ import retrofit2.converter.gson.GsonConverterFactory | @@ -19,9 +22,9 @@ import retrofit2.converter.gson.GsonConverterFactory | ||
19 | */ | 22 | */ |
20 | 23 | ||
21 | class RetrofitFactory private constructor() { | 24 | class RetrofitFactory private constructor() { |
22 | - private val retrofit : Retrofit | 25 | + private val retrofit: Retrofit |
23 | 26 | ||
24 | - fun <T> create(clazz: Class<T>) : T { | 27 | + fun <T> create(clazz: Class<T>): T { |
25 | return retrofit.create(clazz) | 28 | return retrofit.create(clazz) |
26 | } | 29 | } |
27 | 30 | ||
@@ -41,7 +44,6 @@ class RetrofitFactory private constructor() { | @@ -41,7 +44,6 @@ class RetrofitFactory private constructor() { | ||
41 | } | 44 | } |
42 | 45 | ||
43 | 46 | ||
44 | - | ||
45 | private fun initOkHttpClient(): OkHttpClient { | 47 | private fun initOkHttpClient(): OkHttpClient { |
46 | return OkHttpClient.Builder() | 48 | return OkHttpClient.Builder() |
47 | .addInterceptor(initCookieIntercept()) | 49 | .addInterceptor(initCookieIntercept()) |
@@ -63,7 +65,7 @@ class RetrofitFactory private constructor() { | @@ -63,7 +65,7 @@ class RetrofitFactory private constructor() { | ||
63 | 65 | ||
64 | 66 | ||
65 | //只保存登录或者注册 | 67 | //只保存登录或者注册 |
66 | - if(requestUrl.contains(Constant.SAVE_USER_LOGIN_KEY) || requestUrl.contains(Constant.SAVE_USER_REGISTER_KEY)){ | 68 | + if (requestUrl.contains(Constant.SAVE_USER_LOGIN_KEY) || requestUrl.contains(Constant.SAVE_USER_REGISTER_KEY)) { |
67 | val mCookie = response.headers(Constant.SET_COOKIE_KEY) | 69 | val mCookie = response.headers(Constant.SET_COOKIE_KEY) |
68 | mCookie?.let { | 70 | mCookie?.let { |
69 | // saveCookie(domain,parseCookie(it)) | 71 | // saveCookie(domain,parseCookie(it)) |
@@ -80,7 +82,7 @@ class RetrofitFactory private constructor() { | @@ -80,7 +82,7 @@ class RetrofitFactory private constructor() { | ||
80 | val builder = request.newBuilder() | 82 | val builder = request.newBuilder() |
81 | val domain = request.url().host() | 83 | val domain = request.url().host() |
82 | 84 | ||
83 | - if(domain.isNotEmpty()){ | 85 | + if (domain.isNotEmpty()) { |
84 | // val mCookie by SPreference("cookie","") | 86 | // val mCookie by SPreference("cookie","") |
85 | // if(mCookie.isNotEmpty()){ | 87 | // if(mCookie.isNotEmpty()){ |
86 | // builder.addHeader(Constant.COOKIE_NAME,mCookie) | 88 | // builder.addHeader(Constant.COOKIE_NAME,mCookie) |
@@ -100,12 +102,14 @@ class RetrofitFactory private constructor() { | @@ -100,12 +102,14 @@ class RetrofitFactory private constructor() { | ||
100 | .header("token", token) | 102 | .header("token", token) |
101 | .build() | 103 | .build() |
102 | 104 | ||
103 | - chain.proceed(request) | 105 | + val response = chain.proceed(request) |
106 | + Log.e("response", getResponseInfo(response)) | ||
107 | + response | ||
104 | } | 108 | } |
105 | } | 109 | } |
106 | 110 | ||
107 | private fun parseCookie(it: List<String>): String { | 111 | private fun parseCookie(it: List<String>): String { |
108 | - if(it.isEmpty()){ | 112 | + if (it.isEmpty()) { |
109 | return "" | 113 | return "" |
110 | } | 114 | } |
111 | 115 | ||
@@ -115,7 +119,7 @@ class RetrofitFactory private constructor() { | @@ -115,7 +119,7 @@ class RetrofitFactory private constructor() { | ||
115 | stringBuilder.append(cookie).append(";") | 119 | stringBuilder.append(cookie).append(";") |
116 | } | 120 | } |
117 | 121 | ||
118 | - if(stringBuilder.isEmpty()){ | 122 | + if (stringBuilder.isEmpty()) { |
119 | return "" | 123 | return "" |
120 | } | 124 | } |
121 | //末尾的";"去掉 | 125 | //末尾的";"去掉 |
@@ -128,4 +132,32 @@ class RetrofitFactory private constructor() { | @@ -128,4 +132,32 @@ class RetrofitFactory private constructor() { | ||
128 | // resutl = parseCookie | 132 | // resutl = parseCookie |
129 | // } | 133 | // } |
130 | // } | 134 | // } |
135 | + | ||
136 | + /** | ||
137 | + * 打印返回消息 | ||
138 | + * | ||
139 | + * @param response 返回的对象 | ||
140 | + */ | ||
141 | + private fun getResponseInfo(response: Response?): String { | ||
142 | + var str = "" | ||
143 | + if (response == null || !response.isSuccessful) { | ||
144 | + return str | ||
145 | + } | ||
146 | + val responseBody = response.body() | ||
147 | + val contentLength = responseBody!!.contentLength() | ||
148 | + val source = responseBody.source() | ||
149 | + try { | ||
150 | + source.request(Long.MAX_VALUE) // Buffer the entire body. | ||
151 | + } catch (e: IOException) { | ||
152 | + e.printStackTrace() | ||
153 | + } | ||
154 | + val buffer: okio.Buffer? = source.buffer() | ||
155 | + val charset: Charset = Charset.forName("utf-8") | ||
156 | + if (contentLength != 0L) { | ||
157 | + if (buffer != null) { | ||
158 | + str = buffer.clone().readString(charset) | ||
159 | + } | ||
160 | + } | ||
161 | + return str | ||
162 | + } | ||
131 | } | 163 | } |
@@ -38,7 +38,7 @@ class BankRepository(val loadState: MutableLiveData<State>): ApiRepository() { | @@ -38,7 +38,7 @@ class BankRepository(val loadState: MutableLiveData<State>): ApiRepository() { | ||
38 | page_num : Int, | 38 | page_num : Int, |
39 | liveData: MutableLiveData<BaseResponse<PracticeBean>> | 39 | liveData: MutableLiveData<BaseResponse<PracticeBean>> |
40 | ) { | 40 | ) { |
41 | - apiService.practiceList(pos_id,page, page_num) | 41 | + apiService.practiceList(1,pos_id,page, page_num) |
42 | .subscribeOn(Schedulers.io()) | 42 | .subscribeOn(Schedulers.io()) |
43 | .observeOn(AndroidSchedulers.mainThread()) | 43 | .observeOn(AndroidSchedulers.mainThread()) |
44 | .subscribe( | 44 | .subscribe( |
@@ -23,7 +23,7 @@ class ClassifyPop(context: Activity) : PopupWindow(context) { | @@ -23,7 +23,7 @@ class ClassifyPop(context: Activity) : PopupWindow(context) { | ||
23 | 23 | ||
24 | private var mWorkTypeList: MutableList<WorkTypeBean.ListBean>? = null | 24 | private var mWorkTypeList: MutableList<WorkTypeBean.ListBean>? = null |
25 | private var textCourseTypeAdapter: TextCourseTypeAdapter? = null | 25 | private var textCourseTypeAdapter: TextCourseTypeAdapter? = null |
26 | - private var pos : Int = 0 | 26 | + private var pos: Int = 0 |
27 | private val binding by lazy { | 27 | private val binding by lazy { |
28 | PopClassifyBinding.inflate(LayoutInflater.from(context)) | 28 | PopClassifyBinding.inflate(LayoutInflater.from(context)) |
29 | } | 29 | } |
@@ -58,7 +58,11 @@ class ClassifyPop(context: Activity) : PopupWindow(context) { | @@ -58,7 +58,11 @@ class ClassifyPop(context: Activity) : PopupWindow(context) { | ||
58 | mWorkTypeList?.let { textCourseTypeAdapter?.addList(it) } | 58 | mWorkTypeList?.let { textCourseTypeAdapter?.addList(it) } |
59 | 59 | ||
60 | complete.setOnClickListener { | 60 | complete.setOnClickListener { |
61 | - EventBus.getDefault().post(mWorkTypeList?.get(pos)?.let { it1 -> GetWorkTypeEvent(it1.id,it1.name) }) | 61 | + val index:Int = (mWorkTypeList?.size?:mWorkTypeList?.size) as Int |
62 | + if (index > pos) { | ||
63 | + EventBus.getDefault().post( | ||
64 | + mWorkTypeList?.get(pos)!!.let { it1 -> GetWorkTypeEvent(it1.id, it1.name) }) | ||
65 | + } | ||
62 | dismiss() | 66 | dismiss() |
63 | } | 67 | } |
64 | } | 68 | } |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | android:layout_height="wrap_content" | 15 | android:layout_height="wrap_content" |
16 | android:layout_marginStart="32dp" | 16 | android:layout_marginStart="32dp" |
17 | android:layout_marginTop="36dp" | 17 | android:layout_marginTop="36dp" |
18 | + android:visibility="invisible" | ||
18 | android:contentDescription="@string/logo" | 19 | android:contentDescription="@string/logo" |
19 | android:src="@mipmap/ic_back" /> | 20 | android:src="@mipmap/ic_back" /> |
20 | 21 |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | android:layout_height="wrap_content" | 16 | android:layout_height="wrap_content" |
17 | android:layout_marginStart="32dp" | 17 | android:layout_marginStart="32dp" |
18 | android:layout_marginTop="36dp" | 18 | android:layout_marginTop="36dp" |
19 | + android:visibility="invisible" | ||
19 | android:contentDescription="@string/logo" | 20 | android:contentDescription="@string/logo" |
20 | android:src="@mipmap/ic_back" /> | 21 | android:src="@mipmap/ic_back" /> |
21 | 22 |
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | android:layout_width="wrap_content" | 14 | android:layout_width="wrap_content" |
15 | android:layout_height="wrap_content" | 15 | android:layout_height="wrap_content" |
16 | android:layout_marginStart="32dp" | 16 | android:layout_marginStart="32dp" |
17 | + android:visibility="invisible" | ||
17 | android:layout_marginTop="36dp" | 18 | android:layout_marginTop="36dp" |
18 | android:contentDescription="@string/logo" | 19 | android:contentDescription="@string/logo" |
19 | android:src="@mipmap/ic_back" /> | 20 | android:src="@mipmap/ic_back" /> |
@@ -19,7 +19,8 @@ | @@ -19,7 +19,8 @@ | ||
19 | 19 | ||
20 | <FrameLayout | 20 | <FrameLayout |
21 | android:layout_width="match_parent" | 21 | android:layout_width="match_parent" |
22 | - android:layout_height="476dp" | 22 | + android:layout_height="0dp" |
23 | + android:layout_weight="1" | ||
23 | android:layout_margin="40dp"> | 24 | android:layout_margin="40dp"> |
24 | 25 | ||
25 | 26 |
-
请 注册 或 登录 后发表评论