feat: refs #6868 handleUser

This commit is contained in:
Sergio De la torre 2024-10-16 11:24:59 +02:00
parent aa04349845
commit 0c1f054b7f
3 changed files with 76 additions and 16 deletions

View File

@ -1,8 +1,11 @@
package es.verdnatura.presentation.view.feature.ajustes.fragment
import android.app.AlertDialog
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
@ -13,6 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentAjustesBinding
import es.verdnatura.domain.ConstAndValues.ANDROID_ID
import es.verdnatura.domain.ConstAndValues.HOLDPOSITION
import es.verdnatura.domain.ConstAndValues.ITEMPACKING
import es.verdnatura.domain.ConstAndValues.MENUBYDEFAULTSELECTED
import es.verdnatura.domain.ConstAndValues.NUMBEROFWAGONS
@ -99,14 +103,14 @@ class AjustesFragment :
getString(R.string.version) + ":\t" +
requireActivity().packageManager.getPackageInfo(
requireActivity().packageName, 0
).versionName!! + "\n" +
).versionName!! + "(${getVersionCode()})" + "\n" +
getString(R.string.user) + ":\t" +
mobileApplication.userName + "\n" +
getString(R.string.androidid) + ":\t" +
mobileApplication.dataStoreApp.readDataStoreKey<String>(
ANDROID_ID
) + "\n" +
if (!mobileApplication.serialNumber.isNullOrBlank() ) {
if (!mobileApplication.serialNumber.isNullOrBlank()) {
getString(R.string.serialNumber) + "\t" +
mobileApplication.serialNumber
} else ""
@ -122,6 +126,27 @@ class AjustesFragment :
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
private fun getVersionCode(): Long {
val context = requireContext()
val packageManager: PackageManager = context.packageManager
val packageInfo: PackageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(
context.packageName,
PackageManager.PackageInfoFlags.of(0)
)
} else {
@Suppress("DEPRECATION")
packageManager.getPackageInfo(context.packageName, 0)
}
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode
} else {
@Suppress("DEPRECATION")
packageInfo.versionCode.toLong()
}
}
override fun observeViewModel() {
with(viewModel) {
@ -241,6 +266,7 @@ class AjustesFragment :
.setDescription(getString(R.string.Noprinters))
.setOkButton(getString(R.string.Close)) {
customDialog.dismiss()
handleUserCall()
}.show()
}
@ -271,19 +297,40 @@ class AjustesFragment :
private fun getUserData() {
loginViewModel = LoginViewModel(requireActivity().applicationContext)
try {
loginViewModel.operatorGetData(mobileApplication.userId!!)
} catch (_: Exception) {
ma.messageWithSound(
message = getString(R.string.errorGetData), isError = true, isPlayed = true
)
}
loginViewModel.workerOperator.observe(this@AjustesFragment) { iti ->
runBlocking { mobileApplication.dataStoreApp.saveDataOperator(iti) }
/* try {
loginViewModel.operatorGetData(mobileApplication.userId!!)
} catch (_: Exception) {
ma.messageWithSound(
message = getString(R.string.errorGetData), isError = true, isPlayed = true
)
}
loginViewModel.workerOperator.observe(this@AjustesFragment) { iti ->
runBlocking { mobileApplication.dataStoreApp.saveDataOperator(iti) }
}*/
handleUserCall()
loginViewModel.handleUserResponse.observe(this@AjustesFragment) { iti ->
runBlocking { mobileApplication.dataStoreApp.saveWorkerData(iti) }
}
setSettings()
}
private fun handleUserCall() {
val jsonData = mutableMapOf<String, Any>(
"androidId" to mobileApplication.androidId,
"nameApp" to getString(R.string.nameApp),
"versionApp" to getInfoVersionNameApp()
)
loginViewModel.handleUser(if (getDevicePDA() != null) {
jsonData.apply {
this["deviceId"] = getDevicePDA().toString() // Añadir nuevo campo
}
} else {
jsonData
}
)
}
private fun showMenuByDefault() {
pasilleroViewModel.inititializeDefaultDataInit()
@ -311,9 +358,10 @@ class AjustesFragment :
mobileApplication.dataStoreApp.readDataStoreKey<String>(ITEMPACKING),
menuDefault = mobileApplication.dataStoreApp.readDataStoreKey(
MENUBYDEFAULTSELECTED
)
),
holdPosition = mobileApplication.dataStoreApp.readDataStoreKey<Boolean>(HOLDPOSITION),
)
)
}
binding.splashProgress.visibility = View.GONE
}
@ -483,6 +531,7 @@ class AjustesFragment :
labelerFk = id
)
settingsAdapter!!.notifyItemChanged(2)
handleUserCall()
}

View File

@ -65,7 +65,8 @@ class AjustesViewModel(val context: Context) : BaseViewModel(context) {
printerSelected: String,
train: String?,
itemPackingType: String?,
menuDefault: String
menuDefault: String,
holdPosition: Boolean = false
) {
_settingsItem.clear()
_settingsItem.add(
@ -99,6 +100,15 @@ class AjustesViewModel(val context: Context) : BaseViewModel(context) {
action = false
)
)
/*Tarea 5443
_settingsItem.add(
AjustesItemVO(
"Bajar línea al revisar",
holdPosition = holdPosition,
action = true
)
)*/
_settingsItem.add(
AjustesItemVO(
context.getString(R.string.vehicleControl), action = true

View File

@ -8,7 +8,8 @@ class AjustesItemVO(
var sectorFk: Int? = null,
var printerFk: Int? = null,
var printerSelected: String? = null,
var action: Boolean
var action: Boolean,
var holdPosition: Boolean = false
)
class SectorItemVO(
@ -28,7 +29,7 @@ class PrintersList(
class Printers(
var id: Int,
var name: String,
var sector:Sector?
var sector: Sector?
)