From 0c1f054b7fe0ec3837151359a4ef19ab3dee2a4c Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Wed, 16 Oct 2024 11:24:59 +0200 Subject: [PATCH] feat: refs #6868 handleUser --- .../ajustes/fragment/AjustesFragment.kt | 75 +++++++++++++++---- .../ajustes/fragment/AjustesViewModel.kt | 12 ++- .../feature/ajustes/model/AjustesItemVO.kt | 5 +- 3 files changed, 76 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesFragment.kt index 2efae36a..c4e7d529 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesFragment.kt @@ -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( 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( + "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(ITEMPACKING), menuDefault = mobileApplication.dataStoreApp.readDataStoreKey( MENUBYDEFAULTSELECTED - ) + ), + holdPosition = mobileApplication.dataStoreApp.readDataStoreKey(HOLDPOSITION), - ) + ) } binding.splashProgress.visibility = View.GONE } @@ -483,6 +531,7 @@ class AjustesFragment : labelerFk = id ) settingsAdapter!!.notifyItemChanged(2) + handleUserCall() } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesViewModel.kt index 7d58be42..c20a4863 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/fragment/AjustesViewModel.kt @@ -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 diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/model/AjustesItemVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/model/AjustesItemVO.kt index 31bfaac0..d0ced468 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/model/AjustesItemVO.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ajustes/model/AjustesItemVO.kt @@ -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? )