refs #3520 feat:silex→salix

This commit is contained in:
Sergio De la torre 2024-04-19 10:51:54 +02:00
parent d031bab5b4
commit 00a2266a4d
1 changed files with 0 additions and 46 deletions

View File

@ -1,46 +0,0 @@
package es.verdnatura.domain
import android.content.Context
import es.verdnatura.MobileApplication
import es.verdnatura.domain.ConstAndValues.BASEURL
import es.verdnatura.domain.ConstAndValues.BASE_URL
import es.verdnatura.presentation.common.InteceptorListener
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
class ApiUtils {
companion object {
fun getApiService(context: Context, myObserver: InteceptorListener?): VerdnaturaService {
var client = OkHttpClient.Builder().addInterceptor(SilexInterceptor(context,myObserver))
.connectTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(40, TimeUnit.SECONDS).build()
val retrofit = Retrofit.Builder().baseUrl(getBaseUrlLocal(context))
.addConverterFactory(GsonConverterFactory.create()).client(client).build()
return retrofit.create(VerdnaturaService::class.java)
}
private fun getBaseUrlLocal(context: Context): String {
var url = (context as MobileApplication).dataStoreApp.readDataStoreKey<String>(BASEURL)
if (url.isNullOrEmpty()) {
runBlocking {
(context).dataStoreApp.editDataStoreKey(
BASEURL, BASE_URL
)
}
} else {
if (!url.contains("http")) {
url = "https://" + url
}
}
return if (url.isNullOrEmpty()) BASE_URL else url
}
}
}