作者 杨谦

1.走读代码

2.获取测试域名
3.确认已调试的接口并调试,部分目前无数据,需后续确认
4.请求拦截器添加回调参数打印
... ... @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
/.idea/
... ...
... ... @@ -10,7 +10,8 @@ import java.io.File
*/
object Constant {
// const val BASE_URL = "https://security.brofirst.cn/"
const val BASE_URL = "http://admin.anqixing.com"
const val BASE_URL = "http://security.brofirst.cn/"
// const val BASE_URL = "http://admin.anqixing.com"
const val USERNAME_KEY = "username"
const val USERID_KEY = "userid"
const val LOGIN_KEY = "login"
... ...
... ... @@ -153,6 +153,7 @@ interface ApiService {
@FormUrlEncoded
@POST("/api/item/paper_list")
fun practiceList(
@Field("type") type: Int, //所属类型:1=模拟考试,2=专项练习
@Field("pos_id") pos_id: Int,
@Field("page") page: Int,
@Field("page_num") page_num: Int
... ...
... ... @@ -3,7 +3,6 @@ package com.wjx.android.wanandroidmvvm.network
import android.util.Log
import com.br_technology.electricityandroid.util.token
import com.br_technology.securitytrain_master.base.common.Constant
import com.br_technology.securitytrain_master.base.common.StateType
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Request
... ... @@ -11,6 +10,10 @@ import okhttp3.Response
import retrofit2.Retrofit
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.io.IOException
import java.nio.Buffer
import java.nio.charset.Charset
/**
* Time: 7/26/2021 10:11
... ... @@ -19,9 +22,9 @@ import retrofit2.converter.gson.GsonConverterFactory
*/
class RetrofitFactory private constructor() {
private val retrofit : Retrofit
private val retrofit: Retrofit
fun <T> create(clazz: Class<T>) : T {
fun <T> create(clazz: Class<T>): T {
return retrofit.create(clazz)
}
... ... @@ -41,7 +44,6 @@ class RetrofitFactory private constructor() {
}
private fun initOkHttpClient(): OkHttpClient {
return OkHttpClient.Builder()
.addInterceptor(initCookieIntercept())
... ... @@ -63,7 +65,7 @@ class RetrofitFactory private constructor() {
//只保存登录或者注册
if(requestUrl.contains(Constant.SAVE_USER_LOGIN_KEY) || requestUrl.contains(Constant.SAVE_USER_REGISTER_KEY)){
if (requestUrl.contains(Constant.SAVE_USER_LOGIN_KEY) || requestUrl.contains(Constant.SAVE_USER_REGISTER_KEY)) {
val mCookie = response.headers(Constant.SET_COOKIE_KEY)
mCookie?.let {
// saveCookie(domain,parseCookie(it))
... ... @@ -80,7 +82,7 @@ class RetrofitFactory private constructor() {
val builder = request.newBuilder()
val domain = request.url().host()
if(domain.isNotEmpty()){
if (domain.isNotEmpty()) {
// val mCookie by SPreference("cookie","")
// if(mCookie.isNotEmpty()){
// builder.addHeader(Constant.COOKIE_NAME,mCookie)
... ... @@ -100,12 +102,14 @@ class RetrofitFactory private constructor() {
.header("token", token)
.build()
chain.proceed(request)
val response = chain.proceed(request)
Log.e("response", getResponseInfo(response))
response
}
}
private fun parseCookie(it: List<String>): String {
if(it.isEmpty()){
if (it.isEmpty()) {
return ""
}
... ... @@ -115,7 +119,7 @@ class RetrofitFactory private constructor() {
stringBuilder.append(cookie).append(";")
}
if(stringBuilder.isEmpty()){
if (stringBuilder.isEmpty()) {
return ""
}
//末尾的";"去掉
... ... @@ -128,4 +132,32 @@ class RetrofitFactory private constructor() {
// resutl = parseCookie
// }
// }
/**
* 打印返回消息
*
* @param response 返回的对象
*/
private fun getResponseInfo(response: Response?): String {
var str = ""
if (response == null || !response.isSuccessful) {
return str
}
val responseBody = response.body()
val contentLength = responseBody!!.contentLength()
val source = responseBody.source()
try {
source.request(Long.MAX_VALUE) // Buffer the entire body.
} catch (e: IOException) {
e.printStackTrace()
}
val buffer: okio.Buffer? = source.buffer()
val charset: Charset = Charset.forName("utf-8")
if (contentLength != 0L) {
if (buffer != null) {
str = buffer.clone().readString(charset)
}
}
return str
}
}
\ No newline at end of file
... ...
... ... @@ -38,7 +38,7 @@ class BankRepository(val loadState: MutableLiveData<State>): ApiRepository() {
page_num : Int,
liveData: MutableLiveData<BaseResponse<PracticeBean>>
) {
apiService.practiceList(pos_id,page, page_num)
apiService.practiceList(1,pos_id,page, page_num)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
... ...
... ... @@ -23,7 +23,7 @@ class ClassifyPop(context: Activity) : PopupWindow(context) {
private var mWorkTypeList: MutableList<WorkTypeBean.ListBean>? = null
private var textCourseTypeAdapter: TextCourseTypeAdapter? = null
private var pos : Int = 0
private var pos: Int = 0
private val binding by lazy {
PopClassifyBinding.inflate(LayoutInflater.from(context))
}
... ... @@ -58,7 +58,11 @@ class ClassifyPop(context: Activity) : PopupWindow(context) {
mWorkTypeList?.let { textCourseTypeAdapter?.addList(it) }
complete.setOnClickListener {
EventBus.getDefault().post(mWorkTypeList?.get(pos)?.let { it1 -> GetWorkTypeEvent(it1.id,it1.name) })
val index:Int = (mWorkTypeList?.size?:mWorkTypeList?.size) as Int
if (index > pos) {
EventBus.getDefault().post(
mWorkTypeList?.get(pos)!!.let { it1 -> GetWorkTypeEvent(it1.id, it1.name) })
}
dismiss()
}
}
... ...
... ... @@ -15,6 +15,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="36dp"
android:visibility="invisible"
android:contentDescription="@string/logo"
android:src="@mipmap/ic_back" />
... ...
... ... @@ -16,6 +16,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="36dp"
android:visibility="invisible"
android:contentDescription="@string/logo"
android:src="@mipmap/ic_back" />
... ...
... ... @@ -14,6 +14,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:visibility="invisible"
android:layout_marginTop="36dp"
android:contentDescription="@string/logo"
android:src="@mipmap/ic_back" />
... ...
... ... @@ -19,7 +19,8 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="476dp"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="40dp">
... ...