refs #6004 feat:preferences by dataStore

This commit is contained in:
Sergio De la torre 2024-02-20 09:45:43 +01:00
parent efd8ea47f5
commit 9cda22a4d9
8 changed files with 58 additions and 24 deletions

View File

@ -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<String>(BASEURLSALIX)
if (url.isNullOrBlank()) {
url = BASE_URL_SALIX
}
return url
}
}

View File

@ -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<String>(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/"
}
}

View File

@ -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<String>(
BASEURLSALIX
)
mobileApplication.dataStoreApp.getServerSalix()
}/#!/item/$itemId/summary"
)
)

View File

@ -1058,9 +1058,7 @@ class CollectionFragment(
mutableMapOf(
"entryPoint" to sale.ticketFk,
"web" to "${
mobileApplication.dataStoreApp.readDataStoreKey<String>(
ConstAndValues.BASEURLSALIX
)
mobileApplication.dataStoreApp.getServerSalix()
}/#!/ticket/${sale.ticketFk}/sale"
)
)

View File

@ -1064,9 +1064,7 @@ class CollectionFragmentPicker(
mutableMapOf(
"entryPoint" to sale.ticketFk,
"web" to "${
mobileApplication.dataStoreApp.readDataStoreKey<String>(
ConstAndValues.BASEURLSALIX
)
mobileApplication.dataStoreApp.getServerSalix()
}/#!/ticket/${sale.ticketFk}/sale"
)
)

View File

@ -1088,9 +1088,7 @@ class CollectionFragmentPreChecker(
mutableMapOf(
"entryPoint" to sale.ticketFk,
"web" to "${
mobileApplication.dataStoreApp.readDataStoreKey<String>(
BASEURLSALIX
)
mobileApplication.dataStoreApp.getServerSalix()
}/#!/ticket/${sale.ticketFk}/sale"
)
)

View File

@ -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<String>(
BASEURLSALIX
)
mobileApplication.dataStoreApp.getServerSalix()
}#!/route/${route.id}/tickets"
)
)
@ -394,9 +391,7 @@ class TicketsFragment(
mutableMapOf(
"entryPoint" to route.id,
"web" to "${
mobileApplication.dataStoreApp.readDataStoreKey<String>(
BASEURLSALIX
)
mobileApplication.dataStoreApp.getServerSalix()
}/api/Routes/${item.cmrFk}/cmr?access_token=${
mobileApplication.dataStoreApp.readDataStoreKey<String>(
TOKEN

View File

@ -92,9 +92,7 @@ class ShelvingLogFragment(
entryPoint = Gson().toJson(
mutableMapOf(
"entryPoint" to itemId,
"web" to "${mobileApplication.dataStoreApp.readDataStoreKey<String>(
BASEURLSALIX
)}/#!/shelving/$itemId/log"
"web" to "${ mobileApplication.dataStoreApp.getServerSalix()}/#!/shelving/$itemId/log"
)
)
)