Код: Выделить всё
RetrofitInstance().UserAction("retrieveChatForUser",cuserData){ returnMessage->
if(returnMessage.status==true) {
val chatList = returnMessage.content as List
adapter.setData(chatList)
}
}
Код: Выделить всё
class RetrofitInstance {
fun UserAction(action:String, userData: UserData, toUserData: UserData?=null, returnCallback:(ReturnMessage)->Unit){
val retrofit = Retrofit.Builder()
.baseUrl(CommonVals.base_url)
.addConverterFactory(GsonConverterFactory.create())
.build()
val service: RestApiUser = retrofit.create(RestApiUser::class.java)
val callAuth: Call = service.authOraddUser(action, userData.username,userData.phonenumber,toUserData?.username)
callAuth.enqueue(object : Callback {
override fun onResponse(call: Call, response: Response) {
if (response.isSuccessful) {
val post = response.body()
post?.let { post->
Log.d("api","${action} ${post}")
returnCallback(post)
}
} else {
Log.d("apierror", "${action} error ${response.code()}")
}
}
override fun onFailure(call: Call, t: Throwable) {
Log.d("apierror","${action} error ${t.message}")
}
})
}
private interface RestApiUser {
@FormUrlEncoded
@POST("{action}")
fun authOraddUser(
@Path("action") action:String,
@Field("username") username: String?=null,
@Field("password") password: String?=null,
@Field("username2") username2: String?=null,
): Call
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... -to-remove