Professional Documents
Culture Documents
Server DATEt IME
Server DATEt IME
Server DATEt IME
----------------------------------
const val GET_SERVER_DATE="GetServerDateTime"
in ApiInterface---------
--------------------------------------
@POST(GET_SERVER_DATE)
@FormUrlEncoded
fun getDate(
@Field("Key") op: String?
):Call<ServerDateTime>
in DBTRegisterRepo class------------
-----------------------------------------------------------------------------------
---------------
fun getDateTime(request: ServerDateTimeDTO): LiveData<Resource<ServerDateTime>> {
CallServer.get(context).apiName.getDate(
request.Key
).enqueue(object :
Callback<ServerDateTime> {
override fun onResponse(
call: Call<ServerDateTime>,
response: Response<ServerDateTime>
) {
if (response.isSuccessful) {
if (response.body() != null) {
if (!response.body()!!.equals("200")) {
data.setValue(Resource.success(response.body()))
} else
data.setValue(Resource.error("", null, 0, null))
}
}
else {
data.setValue(Resource.error(response.message(), null, 0,
null))
}
}
return data
}
new class add in request package--
--------------------------------------------
package com.tecxpert.saras_pro.data.request
import com.google.gson.annotations.SerializedName
import com.google.gson.annotations.SerializedName
@field:SerializedName("Error_Msg")
val Error_Msg: String? = null
in DBTRegisterViewModel-----
--------------------------------------------------
private val dbtGetSummaryResponse = MutableLiveData<DBTGetSUmmaryDTO>()
private val dbtGetSummaryResponseLD: LiveData<Resource<DBTGetSummaryResponse>>
serverDateTime=
Transformations.switchMap(serverDateTimeDTO){input->
DBTRegisterRepo.get().getDateTime(input)
}
in DBTRegisterActivity
-------------------------------
var serverDate=""
dbtRegisterViewModel =
ViewModelProvider(this).get(DBTRegisterViewModel::class.java)
dbtRegisterViewModel?.callgetServerDate()
?.observe(this, Observer<Resource<ServerDateTime>> { resource ->
if (resource == null) {
return@Observer
}
when (resource.status) {
Status.LOADING -> {
}
Status.SUCCESS -> {
dismissProgressDialog()
if (resource.data != null) {
val dataItem = resource.data
if (dataItem.myDate != null) {
serverDate=dataItem.myDate[0]?.Response_Date.toString()
} else {
} else {
}
Status.ERROR -> {
}
}
})
serverDateTime()
mydatetime()