Server DATEt IME

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

in WebUtils class---------

----------------------------------
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>> {

val data = MutableLiveData<Resource<ServerDateTime>>()


data.setValue(Resource.loading(null))

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))
}
}

override fun onFailure(call: Call<ServerDateTime>, t: Throwable) {

data.setValue(Resource.error(CallServer.serverError, null, 0, t))


}
})

return data
}
new class add in request package--
--------------------------------------------

package com.tecxpert.saras_pro.data.request

import com.google.gson.annotations.SerializedName

data class ServerDateTimeDTO (


@SerializedName("Key")
val Key: String
)

in class add in response package----


-----------------------------------------
package com.tecxpert.saras_pro.data.response

import com.google.gson.annotations.SerializedName

data class ServerDateTime (


@field:SerializedName("Loving")
val myDate: List<MyDate?>? = null,

@field:SerializedName("Error_Msg")
val Error_Msg: String? = null

)data class MyDate(


@field:SerializedName("Result")
val Result: String? = null,
@field:SerializedName("Response_Date")
val Response_Date: String? = null,
)

in DBTRegisterViewModel-----
--------------------------------------------------
private val dbtGetSummaryResponse = MutableLiveData<DBTGetSUmmaryDTO>()
private val dbtGetSummaryResponseLD: LiveData<Resource<DBTGetSummaryResponse>>

serverDateTime=
Transformations.switchMap(serverDateTimeDTO){input->
DBTRegisterRepo.get().getDateTime(input)
}

fun callServerDateTime(s: ServerDateTimeDTO) {


serverDateTimeDTO.value = s
}

fun callgetServerDate(): LiveData<Resource<ServerDateTime>> {


return serverDateTime
}

in DBTRegisterActivity
-------------------------------
var serverDate=""

private fun serverDateTime() {

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 -> {

}
}
})

private fun mydatetime(){


val requestPaymentCycle =
ServerDateTimeDTO(
WebUtils.APP_KEY
)
hideKeyBoard()
// showProgressDialog()
dbtRegisterViewModel?.callServerDateTime(requestPaymentCycle)
}

serverDateTime()
mydatetime()

serverDate---show pdf and execl

You might also like