Hovhannes
09/06/2021, 6:39 AMclass RemoteDataSource @Inject constructor() {
companion object {
var string: String?=null
fun setEncr(string: String){
this.string=string
}
fun getEncr():String{
return this.string!!
}
}
private fun getRetrofitClient( context: Context? = null): OkHttpClient {
val authenticator:Authenticator?=null
val encryp= getEncr()
val body = "{\r\n\"Data\":\"${encryp}\"\r\n}"
.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
return OkHttpClient.Builder()
.cache(null)
.addInterceptor { chain ->
chain.proceed(chain.request().newBuilder().also {
it.addHeader("Accept", "application/json")
it.method("POST", body)
}.build())
}.also { client ->
authenticator?.let { client.authenticator(it) }
if (BuildConfig.DEBUG) {
val logging = HttpLoggingInterceptor()
logging.setLevel(HttpLoggingInterceptor.Level.BODY)
client.addInterceptor(logging)
}
}.build()
}
}
in MainActivity
binding.buttonLogin.setOnClickListener {
val clientId = binding.edittxtClientId.text.toString().trim()
encrypted = encrypt(clientId, publicKey)
setStr(encrypted)
viewModel.loginResponse.observe(this, Observer {
when (it) {
is Resource.Success -> {
.....
}
}