diff --git a/app/src/main/java/es/verdnatura/dataStore/DataStoreLocal.kt b/app/src/main/java/es/verdnatura/dataStore/DataStoreLocal.kt index 1d0f4c02..c563e949 100644 --- a/app/src/main/java/es/verdnatura/dataStore/DataStoreLocal.kt +++ b/app/src/main/java/es/verdnatura/dataStore/DataStoreLocal.kt @@ -191,9 +191,10 @@ class DataStoreLocal(var mobileApplication: MobileApplication) { } - if (listForms.isEmpty()) { + if (listForms.isEmpty() || listForms.size == 1) { createWorksDefault() } + //createWorksDefault() return listForms.sortedBy { it.created } } @@ -244,6 +245,13 @@ class DataStoreLocal(var mobileApplication: MobileApplication) { urlSalix = "http://192.168.1.132:3000" ) ) + saveWorkForm( + WorkForms( + "DEV SALIX", + "http://10.1.4.42:9000", + urlSalix = "https://dev-salix.verdnatura.es" + ) + ) } else { //deleteWorkForm("all") } @@ -279,4 +287,14 @@ class DataStoreLocal(var mobileApplication: MobileApplication) { } } + + fun getServerSalix(): String { + + var url = + readDataStoreKey(BASEURLSALIX) + if (url.isNullOrBlank()) { + url = BASE_URL_SALIX + } + return url + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/ApiSalixUtils.kt b/app/src/main/java/es/verdnatura/domain/ApiSalixUtils.kt index 69ab09ab..18ae0fd2 100644 --- a/app/src/main/java/es/verdnatura/domain/ApiSalixUtils.kt +++ b/app/src/main/java/es/verdnatura/domain/ApiSalixUtils.kt @@ -3,7 +3,9 @@ package es.verdnatura.domain import android.content.Context import com.google.gson.GsonBuilder import es.verdnatura.MobileApplication +import es.verdnatura.domain.ConstAndValues.BASEURL import es.verdnatura.domain.ConstAndValues.BASEURLSALIX +import es.verdnatura.domain.ConstAndValues.BASE_URL import es.verdnatura.domain.ConstAndValues.BASE_URL_SALIX import es.verdnatura.presentation.common.InteceptorListener import kotlinx.coroutines.runBlocking @@ -32,8 +34,37 @@ class ApiSalixUtils { } private fun getBaseUrlLocal(context: Context): String { + var myWorkFormSelected = + (context as MobileApplication).dataStoreApp.readDataStoreKey(ConstAndValues.WORKFORMSELECTED) as String + if (myWorkFormSelected != "Producción" && myWorkFormSelected.isNotBlank()) { + runBlocking { + var list = (context).dataStoreApp.getWorkForm() + for (l in list) { + if (l.name == myWorkFormSelected) { + context.dataStoreApp.editDataStoreKey( + BASEURL, + l.urlSilex + ) + context.dataStoreApp.editDataStoreKey(BASEURLSALIX, l.urlSalix) + } + } + } + } else { + runBlocking { + context.dataStoreApp.editDataStoreKey( + BASEURL, + BASE_URL + ) + context.dataStoreApp.editDataStoreKey( + BASEURLSALIX, + BASE_URL_SALIX + ) + } + } + var url = (context as MobileApplication).dataStoreApp.readDataStoreKey(BASEURLSALIX) + if (url.isNullOrEmpty()) { runBlocking { (context).dataStoreApp.editDataStoreKey( @@ -45,6 +76,7 @@ class ApiSalixUtils { url = "https://" + url } } + return if (url.isNullOrEmpty()) "$BASE_URL_SALIX/api/" else "$url/api/" } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt index eac0cc8a..3a680c64 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt @@ -15,7 +15,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.google.gson.Gson import es.verdnatura.R import es.verdnatura.databinding.FragmentItemCardBinding -import es.verdnatura.domain.ConstAndValues.BASEURLSALIX import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment @@ -131,9 +130,7 @@ class ItemCardFragment( mutableMapOf( "entryPoint" to itemId, "web" to "${ - mobileApplication.dataStoreApp.readDataStoreKey( - BASEURLSALIX - ) + mobileApplication.dataStoreApp.getServerSalix() }/#!/item/$itemId/summary" ) ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt index 58fb7267..3730982f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt @@ -1058,9 +1058,7 @@ class CollectionFragment( mutableMapOf( "entryPoint" to sale.ticketFk, "web" to "${ - mobileApplication.dataStoreApp.readDataStoreKey( - ConstAndValues.BASEURLSALIX - ) + mobileApplication.dataStoreApp.getServerSalix() }/#!/ticket/${sale.ticketFk}/sale" ) ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt index 7c678193..d42b6986 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt @@ -1064,9 +1064,7 @@ class CollectionFragmentPicker( mutableMapOf( "entryPoint" to sale.ticketFk, "web" to "${ - mobileApplication.dataStoreApp.readDataStoreKey( - ConstAndValues.BASEURLSALIX - ) + mobileApplication.dataStoreApp.getServerSalix() }/#!/ticket/${sale.ticketFk}/sale" ) ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt index fc237a12..5dfc190a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt @@ -1088,9 +1088,7 @@ class CollectionFragmentPreChecker( mutableMapOf( "entryPoint" to sale.ticketFk, "web" to "${ - mobileApplication.dataStoreApp.readDataStoreKey( - BASEURLSALIX - ) + mobileApplication.dataStoreApp.getServerSalix() }/#!/ticket/${sale.ticketFk}/sale" ) ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt index 875b3f57..caffe5bd 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt @@ -22,7 +22,6 @@ import com.google.gson.Gson import es.verdnatura.R import es.verdnatura.databinding.FragmentTicketsBinding import es.verdnatura.db.DeliveryDatabase -import es.verdnatura.domain.ConstAndValues.BASEURLSALIX import es.verdnatura.domain.ConstAndValues.TOKEN import es.verdnatura.domain.notNull import es.verdnatura.domain.toast @@ -146,9 +145,7 @@ class TicketsFragment( mutableMapOf( "entryPoint" to route.id, "web" to "${ - mobileApplication.dataStoreApp.readDataStoreKey( - BASEURLSALIX - ) + mobileApplication.dataStoreApp.getServerSalix() }#!/route/${route.id}/tickets" ) ) @@ -394,9 +391,7 @@ class TicketsFragment( mutableMapOf( "entryPoint" to route.id, "web" to "${ - mobileApplication.dataStoreApp.readDataStoreKey( - BASEURLSALIX - ) + mobileApplication.dataStoreApp.getServerSalix() }/api/Routes/${item.cmrFk}/cmr?access_token=${ mobileApplication.dataStoreApp.readDataStoreKey( TOKEN diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/historicoshelvinglog/fragment/shelvingLogFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/historicoshelvinglog/fragment/shelvingLogFragment.kt index 379c235c..36bc2847 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/historicoshelvinglog/fragment/shelvingLogFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/historicoshelvinglog/fragment/shelvingLogFragment.kt @@ -92,9 +92,7 @@ class ShelvingLogFragment( entryPoint = Gson().toJson( mutableMapOf( "entryPoint" to itemId, - "web" to "${mobileApplication.dataStoreApp.readDataStoreKey( - BASEURLSALIX - )}/#!/shelving/$itemId/log" + "web" to "${ mobileApplication.dataStoreApp.getServerSalix()}/#!/shelving/$itemId/log" ) ) )