parent
832e6b70f8
commit
295019d54a
@ -0,0 +1,17 @@
|
||||
package com.common.commonlibtest.bean
|
||||
|
||||
class LoginData {
|
||||
var admin: Boolean = false
|
||||
var chapterTops: List<Long>? = null
|
||||
var coinCount: Int = 0
|
||||
var collectIds: List<String>? = null
|
||||
var email: String = ""
|
||||
var icon: String = ""
|
||||
var id: Long = 0
|
||||
var nickname: String = ""
|
||||
var password: String = ""
|
||||
var publicName: String = ""
|
||||
var token: String = ""
|
||||
var type: Int = 0
|
||||
var username: String = ""
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.common.commonlibtest.bean
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.common.commonlib.net.bean.BaseResponse
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@Parcelize
|
||||
class LoginResponse : BaseResponse(), Parcelable {
|
||||
var data: LoginData? = null
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.common.commonlibtest.manager
|
||||
|
||||
import com.common.commonlib.net.BaseObserve
|
||||
import com.common.commonlib.net.RequestCallBack
|
||||
import com.common.commonlibtest.bean.LoginResponse
|
||||
import io.reactivex.Observable
|
||||
import okhttp3.Interceptor
|
||||
import retrofit2.http.*
|
||||
|
||||
class LoginLoader(interceptors: List<Interceptor>) :
|
||||
BaseObserve<LoginLoader.LoginApi>() {
|
||||
private val api: LoginApi
|
||||
|
||||
init {
|
||||
api = initService(LoginApi::class.java, interceptors)
|
||||
}
|
||||
|
||||
fun login(userName: String, pwd: String, callBack: RequestCallBack<LoginResponse>) {
|
||||
observe(api.login(userName, pwd), callBack)
|
||||
}
|
||||
|
||||
interface LoginApi {
|
||||
@FormUrlEncoded
|
||||
@Headers("baseurl:debug1")
|
||||
@POST("/user/login")
|
||||
fun login(
|
||||
@Field("username") userName: String,
|
||||
@Field("password") pwd: String
|
||||
): Observable<LoginResponse>
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.common.commonlib.net.interceptor
|
||||
|
||||
import android.util.Log
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* 响应头部拦截器
|
||||
*/
|
||||
class ResponseHeadInterceptor(private var callBack: ResponseCallBack?) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
// 获取响应
|
||||
val response = chain.proceed(chain.request())
|
||||
callBack?.onResult(response)
|
||||
return response
|
||||
}
|
||||
|
||||
interface ResponseCallBack {
|
||||
fun onResult(response: Response)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue