diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3b9bd89a..f4698be1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -83,10 +83,23 @@ - + + - - + + + + + + + + + + + + + + - { + "keyToString": { + "ApkExportedModule": "Gestor_Almacén.app", + "ExportApk.ApkPathForGestor_Almacén.app": "C:\\Users\\sergiodt\\AndroidStudioProjects\\vn-warehouseManager\\app", + "PROJECT_TRUSTED_KEY": "true", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.cidr.known.project.marker": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "ScreenRecorder.SavePath": "C:\\Users\\sergiodt\\device-2023-03-17-114045.mp4", + "android-custom-viewC:/Users/sergiodt/.gradle/caches/modules-2/files-2.1/androidx.recyclerview/recyclerview/1.2.1/f0f93e67af3f7417bdd560d5142f6dec4fe629c3/recyclerview-1.2.1-sources.jar!/androidx/recyclerview/widget/RecyclerView.java_SELECTED": "RecyclerView", + "cidr.known.project.marker": "true", + "com.developerphil.adbidea.selecteddevices": "21114523025303", + "com.google.services.firebase.aqiPopupShown": "true", + "last_opened_file_path": "C:/Users/sergiodt/AndroidStudioProjects/vn-warehouseManager/app/src/main/res/drawable", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.17", + "project.structure.side.proportion": "0.2", + "run.code.analysis.last.selected.profile": "pProject Default", + "settings.editor.selected.configurable": "preferences.sourceCode.Shell Script" }, - "keyToStringList": { - "ExportApk.BuildVariants": [ - "generalRelease" + "keyToStringList": { + "ExportApk.BuildVariants": [ + "generalRelease" ], - "com.android.tools.idea.sqlite.queryhistory": [ - "select * from expedition e where e.addressFk= 34915", - "select * from expedition e where e.id= 6872921", - "select count(*) from expeditionPending\n", - "select count(*) from expedition\n", - "select count(*) from expedition" + "com.android.tools.idea.sqlite.queryhistory": [ + "select * from expedition e where e.addressFk= 34915", + "select * from expedition e where e.id= 6872921", + "select count(*) from expeditionPending\n", + "select count(*) from expedition\n", + "select count(*) from expedition" ] } -}]]> +} @@ -895,16 +908,6 @@ 457 diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index 41e826a3..31825261 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -179,7 +179,6 @@ interface SalixService { @Multipart fun uploadImage( @Query ("collection") collection: String, - //@Query("fileName") file: String, @Query("id") id: Int, @Part filePart: MultipartBody.Part, ): diff --git a/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt b/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt index 11e5c640..7349f4ae 100644 --- a/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt @@ -238,6 +238,7 @@ abstract class BaseFragment(viewModelCla R.drawable.camion ->getString(R.string.openLoadingConsignee) R.drawable.exit ->getString(R.string.exitScreen) + R.drawable.ic_image_upload->getString(R.string.messageUpload) else -> { 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 222d2c65..e879d7ab 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 @@ -190,7 +190,7 @@ class ItemCardFragment( private fun getItemCard(itemFk: String) { warehouseFk = getDataInt(WAREHOUSEFK) binding.splashProgressTwo.visibility = View.VISIBLE - viewModel.getItemCard(itemFk, warehouseFk!!) + viewModel.getItemCard(itemFk.toInt(), warehouseFk!!) this.itemFk = itemFk } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt index b59aecaf..6e38e3ff 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt @@ -16,7 +16,13 @@ import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO import es.verdnatura.presentation.view.feature.articulo.model.ItemPackingTypeList import es.verdnatura.presentation.view.feature.articulo.model.ItemProposal import es.verdnatura.presentation.view.feature.articulo.model.ItemProposalList +import okhttp3.MediaType +import okhttp3.MultipartBody +import okhttp3.RequestBody import retrofit2.Response +import java.io.File +import java.util.* +import kotlin.collections.ArrayList class ItemCardViewModel(var context: Context) : BaseViewModel(context) { @@ -39,7 +45,7 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) { fun getItemCard( - itemFk: String, + itemFk: Int, warehouseFk: Int, ) { @@ -304,4 +310,39 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) { }) } + + + private val _responseinsert by lazy { MutableLiveData() } + val responseinsert: LiveData + get() = _responseinsert + + + fun uploadPhoto( + urlImage:String, + itemFK:Int, + file: File = File("$urlImage"), + fileRequestBody: RequestBody = RequestBody.create(MediaType.parse("image/jpeg"), file), + filePart: MultipartBody.Part = MultipartBody.Part.createFormData("file", file.name, fileRequestBody), + ) { + salix.uploadImage("catalog",itemFK,filePart) + .enqueue(object : SilexCallback(context) { + override fun onError(t: Throwable) { + _responseinsert.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } + + override fun onSuccess(response: Response) { + _responseinsert.value = ResponseItemVO( + isError = false + + ) + } + + }) + } + + + } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/login/activity/LoginActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/login/activity/LoginActivity.kt index 737d0997..90bbc744 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/login/activity/LoginActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/login/activity/LoginActivity.kt @@ -1,6 +1,7 @@ package es.verdnatura.presentation.view.feature.login.activity import android.content.Intent +import android.net.Uri import es.verdnatura.R import es.verdnatura.databinding.ActivityLoginBinding import es.verdnatura.presentation.base.BaseActivity @@ -9,39 +10,26 @@ import es.verdnatura.presentation.common.addFragment import es.verdnatura.presentation.view.feature.login.fragment.LoginFragment import es.verdnatura.presentation.view.feature.main.activity.MainActivity -class LoginActivity : BaseActivity() { +class LoginActivity : BaseActivity() { + private var imageUri: Uri? = null override fun getLayoutId(): Int = R.layout.activity_login override fun init() { - /* val intent = intent + val intent = intent val action = intent.action - val type = intent.type*/ - /* val crashButton = Button(this) - crashButton.text = "Crash!" - crashButton.setOnClickListener { - throw RuntimeException("Test Crash") // Force a crash + val type = intent.type + + //Tarea 5322 + if (Intent.ACTION_SEND == action && type?.startsWith("image/") == true) { + val clipData = intent.clipData + if (clipData != null) { + imageUri = clipData.getItemAt(0).uri + } } - addContentView(crashButton, ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT))*/ - - //goToMain() - /*Tarea 5322 - if (Intent.ACTION_SEND == action && type?.startsWith("image/") == true) { - val imageUri: Uri? = intent.getParcelableExtra(Intent.EXTRA_STREAM) - imageUri?.let { - // Aquí puedes procesar la imagen recibida - // por ejemplo, mostrarla en una ImageView - val imageView: ImageView = findViewById(R.id.imageView) - imageView.setImageURI(imageUri) - } - - }*/ - - addFragment(LoginFragment.newInstance(), R.id.main_frame_layout, LoginFragment.TAG) + addFragment(LoginFragment.newInstance(imageUri), R.id.main_frame_layout, LoginFragment.TAG) } fun goToMain() { diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt index 5e9419c2..4ccc152b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt @@ -10,7 +10,6 @@ import android.content.pm.PackageManager import android.net.Uri import android.os.Environment import android.provider.Settings -import android.util.Log.d import android.view.View import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager @@ -34,7 +33,8 @@ import java.util.* import kotlin.system.exitProcess -class LoginFragment : BaseFragment(LoginViewModel::class) { +class LoginFragment(var imageUri: Uri?) : + BaseFragment(LoginViewModel::class) { private lateinit var customDialog: CustomDialog private lateinit var customNewForm: CustomDialogInputThreeValues @@ -42,13 +42,15 @@ class LoginFragment : BaseFragment(LoginVi private lateinit var customDialogList: CustomDialogList private lateinit var listForms: List + companion object { - fun newInstance() = LoginFragment() + fun newInstance(imageUri: Uri?) = LoginFragment(imageUri) } override fun getLayoutId(): Int = R.layout.fragment_login override fun init() { + customDialogList = CustomDialogList(requireContext()) customDialog = CustomDialog(requireContext()) @@ -63,8 +65,11 @@ class LoginFragment : BaseFragment(LoginVi password = binding.edittextPassword.text.toString() ) + } + if (imageUri != null && getData(TOKEN).isNotBlank()) { + goToMain() } binding.textviewRememberPassword.setOnClickListener { @@ -271,7 +276,7 @@ class LoginFragment : BaseFragment(LoginVi openURL.data = Uri.parse(it.url) startActivity(openURL) - } catch (ex:Exception) { + } catch (ex: Exception) { getString(R.string.problemUpdate).toast(requireActivity()) } @@ -517,6 +522,7 @@ class LoginFragment : BaseFragment(LoginVi private fun goToMain() { val intent = Intent(activity, MainActivity::class.java) + intent.data = imageUri startActivity(intent) binding.splashProgress.visibility = View.GONE requireActivity().finish() diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt index f27f5ce5..5f88369f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt @@ -5,6 +5,7 @@ package es.verdnatura.presentation.view.feature.main.activity import PhotosFragment import android.content.SharedPreferences import android.media.MediaPlayer +import android.net.Uri import android.view.Menu import android.widget.Toast import androidx.core.content.ContextCompat @@ -18,7 +19,6 @@ import es.verdnatura.domain.ConstAndValues.PREITEMPICKER import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseActivity import es.verdnatura.presentation.common.* -import es.verdnatura.presentation.testing.testPrint import es.verdnatura.presentation.view.component.CustomDialogMainActivity import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesFragment import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardFragment @@ -65,9 +65,9 @@ import es.verdnatura.presentation.view.feature.reubication.fragment.ReubicationC import es.verdnatura.presentation.view.feature.reubication.fragment.ReubicationFragment import es.verdnatura.presentation.view.feature.reubication.model.Reubication import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorFragment +import es.verdnatura.presentation.view.feature.sacador.fragment.showticket.ShowTicketFragment import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingFragment -import es.verdnatura.presentation.view.feature.sacador.fragment.showticket.ShowTicketFragment import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemFragment import es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorFragment import es.verdnatura.presentation.view.feature.workermistake.adapter.WorkermistakeFragment @@ -108,58 +108,33 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL private fun setFragments() { try { val extras = intent.extras - if (extras != null && extras.containsKey("menu")) { - comeFromDelivery = true - val option = extras.getString("menu") - saveDataInt("USERFK", extras.getString("userfk")!!.toInt()) - saveUserAccesPref( - extras.getString("user").toString(), - extras.getString("password").toString() + val uriImage = intent.data - ) - when (option) { - "log" -> onPasillerosItemClickListener( - PasillerosItemVO( - 30, - R.drawable.expedition_find, - getString(R.string.titleLog), - R.string.titleLog, - getString( - R.string.titleLogDescrip - ) + if (extras != null && extras.containsKey("menu")) { + comeFromDelivery = true + val option = extras.getString("menu") + saveDataInt("USERFK", extras.getString("userfk")!!.toInt()) + saveUserAccesPref( + extras.getString("user").toString(), + extras.getString("password").toString() - ), getString(R.string.titleLog) ) - "info" -> onPasillerosItemClickListener( - PasillerosItemVO( - 30, - R.drawable.ic_info, - getString(R.string.titleInfo), - R.string.titleInfo, - getString( - R.string.titleInfoDescription - ) - ), getString(R.string.titleInfo) - ) - "summary"->{ - - onPasillerosItemClickListener( + when (option) { + "log" -> onPasillerosItemClickListener( PasillerosItemVO( 30, - R.drawable.ic_info, - getString(R.string.titleDeliverySummary), - R.string.titleDeliverySummary, + R.drawable.expedition_find, + getString(R.string.titleLog), + R.string.titleLog, getString( - R.string.titleDeliverySummary + R.string.titleLogDescrip ) - ),extras.getString("route").toString() + ), getString(R.string.titleLog) ) - } - "unload"->{ - onPasillerosItemClickListener( + "info" -> onPasillerosItemClickListener( PasillerosItemVO( 30, R.drawable.ic_info, @@ -171,28 +146,74 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL ), getString(R.string.titleInfo) ) + "summary" -> { + + onPasillerosItemClickListener( + PasillerosItemVO( + 30, + R.drawable.ic_info, + getString(R.string.titleDeliverySummary), + R.string.titleDeliverySummary, + getString( + R.string.titleDeliverySummary + ) + + ), extras.getString("route").toString() + ) + } + "unload" -> { + onPasillerosItemClickListener( + PasillerosItemVO( + 30, + R.drawable.ic_info, + getString(R.string.titleInfo), + R.string.titleInfo, + getString( + R.string.titleInfoDescription + ) + + ), getString(R.string.titleInfo) + ) + } + } + + } else { + if (haveSector() && havePrinter()) addFragment( + PasilleroFragment.newInstance(getString(R.string.main), true), + R.id.main_frame_layout, + PasilleroFragment.TAG, + false + ) + else addFragment( + AjustesFragment.newInstance(), + R.id.main_frame_layout, + AjustesFragment.TAG, + false + ) + + + if (uriImage != null && uriImage is Uri) { + onPasillerosItemClickListener( + PasillerosItemVO( + 30, + R.drawable.photo_camera, + getString(R.string.titlePhotos), + R.string.titlePhotos, + getString( + R.string.titlePhotosDescrip + ) + + ), uriImage.toString() + ) + } } - - } else { - if (haveSector() && havePrinter()) addFragment( - PasilleroFragment.newInstance(getString(R.string.main), true), - R.id.main_frame_layout, - PasilleroFragment.TAG, - false - ) - else addFragment( - AjustesFragment.newInstance(), - R.id.main_frame_layout, - AjustesFragment.TAG, - false - ) - } } catch (exception: Exception) { getString(R.string.error).toast(this) } + } fun haveSector(): Boolean { @@ -674,7 +695,7 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL getString(R.string.titleLoadTruck) -> { addFragmentOnTop( - LoadUnloadFragment.newInstance(item.title, "ON DELIVERY",entryPoint), + LoadUnloadFragment.newInstance(item.title, "ON DELIVERY", entryPoint), if (comeFromDelivery == true) { getString(R.string.titleLoadTruck) } else { @@ -687,7 +708,7 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL getString(R.string.titleUnLoadTruck) -> { addFragmentOnTop( - LoadUnloadFragment.newInstance(item.title, "DELIVERED",entryPoint), + LoadUnloadFragment.newInstance(item.title, "DELIVERED", entryPoint), if (comeFromDelivery == true) { getString(R.string.titleUnLoadTruck) } else { @@ -700,7 +721,7 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL getString(R.string.titleDeliverySummary) -> { addFragmentOnTop( - SummaryFragment.newInstance(item.title, "ON DELIVERY",entryPoint.toInt()), + SummaryFragment.newInstance(item.title, "ON DELIVERY", entryPoint.toInt()), if (comeFromDelivery == true) { getString(R.string.titleDeliverySummary) } else { @@ -712,12 +733,13 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL getString(R.string.titlePhotos) -> { addFragmentOnTop( - PhotosFragment.newInstance(item.title)) + PhotosFragment.newInstance(item.title, entryPoint) + ) } getString(R.string.testing) -> { - addFragmentOnTop( - PhotosFragment.newInstance(item.title)) + // addFragmentOnTop( + // PhotosFragment.newInstance(item.title)) //addFragmentOnTop(testPrint.newInstance(item.title)) } } @@ -923,7 +945,7 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL } } } - }else{ + } else { mpErrorRepeat?.start() } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt index c2cbdad7..31d9ab1c 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt @@ -510,7 +510,8 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { R.string.titlePackaging, contextApp.getString(R.string.titlePackagingDescrip) ) - ) + )*/ + //Tarea 5322 _pasillerositem.add( PasillerosItemVO( 6, @@ -519,7 +520,7 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { R.string.titlePhotos, contextApp.getString(R.string.titlePhotos) ) - )*/ + ) val working_in_test=false if (working_in_test){ diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt index e59dba73..ef7fc5aa 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt @@ -1,171 +1,242 @@ - - import android.content.Context - import android.content.Intent - import android.graphics.Bitmap - import android.graphics.drawable.BitmapDrawable - import android.graphics.drawable.Drawable - import android.net.Uri - import android.os.Build - import android.os.Environment - import android.view.View - import android.view.View.* - import android.widget.ImageView - import androidx.annotation.RequiresApi - import androidx.lifecycle.Observer - import androidx.recyclerview.widget.LinearLayoutManager - import es.verdnatura.R - import es.verdnatura.databinding.FragmentPhotosBinding - import es.verdnatura.databinding.FragmentVehiclecontrolUserBinding - import es.verdnatura.presentation.base.BaseFragment - import es.verdnatura.presentation.common.OnOptionsSelectedListener - import es.verdnatura.presentation.common.ToolBarAdapterTooltip - import es.verdnatura.presentation.common.loadUrl - import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.ControlVehiculoUsuarioFragment - import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.ControlVehiculoViewModel - import es.verdnatura.presentation.view.feature.photos.fragment.PhotosViewModel - import java.io.File - import java.io.FileOutputStream - import java.io.IOException - import java.text.SimpleDateFormat - import java.util.* - import kotlin.collections.ArrayList +import android.app.Activity.RESULT_OK +import android.content.Context +import android.content.Intent +import android.graphics.Bitmap +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable +import android.net.Uri +import android.os.Build +import android.os.Environment +import android.provider.MediaStore +import android.view.View.* +import android.view.inputmethod.EditorInfo +import android.widget.ImageView +import androidx.annotation.RequiresApi +import androidx.core.net.toUri +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentPhotosBinding +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.ToolBarAdapterTooltip +import es.verdnatura.presentation.common.itemScanValue +import es.verdnatura.presentation.common.loadUrl +import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardViewModel +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.text.SimpleDateFormat +import java.util.* - class PhotosFragment( - var title: String - ) : BaseFragment( - PhotosViewModel::class - ) { +class PhotosFragment( + var title: String, + var uriImage: Uri? +) : BaseFragment( + ItemCardViewModel::class +) { + private val PICK_IMAGE_REQUEST = 1 + private val REQUEST_IMAGE_CAPTURE = 2 + private val imageUri: Uri? = null + private var originalItem = 0 - override fun getLayoutId(): Int = R.layout.fragment_photos + override fun getLayoutId(): Int = R.layout.fragment_photos + companion object { + fun newInstance(title: String, uriImage: String) = PhotosFragment(title, uriImage.toUri()) + } - companion object { - fun newInstance(title: String) = PhotosFragment(title) + @RequiresApi(Build.VERSION_CODES.O) + override fun init() { + binding.mainToolbar.toolbarTitle.text = title + binding.splashProgress.visibility = GONE + setEvents() + setToolBar() + setImage() + super.init() + } + + private fun setImage() { + if (uriImage != null) { + binding.itemcardImage.setImageURI(uriImage) } + } - @RequiresApi(Build.VERSION_CODES.O) - override fun init() { - binding.mainToolbar.toolbarTitle.text = title - binding.splashProgress.visibility = GONE - setEvents() - setToolBar() - upLoadPhoto() - super.init() - } + @RequiresApi(Build.VERSION_CODES.O) + private fun setToolBar() { - @RequiresApi(Build.VERSION_CODES.O) - private fun setToolBar() { + binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE + binding.mainToolbar.toolbarIcons.visibility = VISIBLE + binding.mainToolbar.backButton.visibility = VISIBLE - binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE - binding.mainToolbar.toolbarIcons.visibility = VISIBLE - binding.mainToolbar.backButton.visibility = VISIBLE + val listIcons: ArrayList = ArrayList() + val iconPhoto = ImageView(context) + val iconSend = ImageView(context) + iconSend.setImageResource(R.drawable.ic_image_upload) + iconPhoto.setImageResource(R.drawable.ef_ic_camera_white) - val listIcons: ArrayList = ArrayList() - val iconPhone = ImageView(context) - iconPhone.setImageResource(R.drawable.phone_call) + iconPhoto.tooltipText = getTooltip(R.drawable.ef_ic_camera_white) + iconSend.tooltipText = getTooltip(R.drawable.ic_image_upload) - iconPhone.tooltipText = getTooltip(R.drawable.phone_call) - listIcons.add(iconPhone) - binding.mainToolbar.toolbarIcons.adapter = - ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { - override fun onOptionsItemSelected(item: Drawable) { + listIcons.add(iconPhoto) + listIcons.add(iconSend) - when (item) { - iconPhone.drawable -> upLoadPhoto() - - } + binding.mainToolbar.toolbarIcons.adapter = + ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + when (item) { + iconPhoto.drawable -> getPhoto() + iconSend.drawable -> upLoadPhoto() } - }) - binding.mainToolbar.toolbarIcons.layoutManager = - LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + + + } + }) + binding.mainToolbar.toolbarIcons.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun getPhoto() { + pickImage() + } + + private fun setEvents() { + binding.mainToolbar.backButton.setOnClickListener { + requireActivity().onBackPressed() } + binding.editItemFk.setOnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!binding.editItemFk.text.toString().isEmpty()) + { + originalItem = itemScanValue( + binding.editItemFk.text.toString(), + "buy", + "more" + ).toString().toInt() - - private fun loadImage() { - - // binding.splashProgress.visibility = VISIBLE - - binding.userImage.loadUrl( - getData("base_urlSalix") + "/api/Images/user/160x160/19591/download?access_token=${ - getData( - TOKEN - ) - }" - ) - - - } - - private fun setEvents() { - binding.mainToolbar.backButton.setOnClickListener { - requireActivity().onBackPressed() - } - - - } - - - override fun observeViewModel() { - - with(viewModel) { - binding.splashProgress.visibility = View.GONE - - - - responseinsert.observe(viewLifecycleOwner, Observer { - - binding.splashProgress.visibility = GONE - - if (it.isError) { - ma.messageWithSound( - it.errorMessage + getString(R.string.user) + title, - isError = true, - true + try { + binding.splashProgress.visibility = VISIBLE + viewModel.getItemCard( + originalItem, getDataInt(WAREHOUSEFK) ) + + } catch (Ex: Exception) { + ma.messageWithSound(Ex.message.toString(), true, true) + } + } + binding.editItemFk.setText("") + ma.hideKeyboard(binding.editItemFk) + return@setOnEditorActionListener true + } + false + } + + binding.editItemFk.requestFocus() + + } + + override fun observeViewModel() { + + with(viewModel) { + responseinsert.observe(viewLifecycleOwner) { + binding.splashProgress.visibility = GONE + if (it.isError) { + ma.messageWithSound( + it.errorMessage + getString(R.string.user) + title, + isError = true, + true + ) + + } else { + ma.messageWithSound( + getString(R.string.itemUpdated), + isError = it.isError, + true + ) + } + + } + itemcard.observe(viewLifecycleOwner) { + binding.splashProgress.visibility = GONE + if (it.isError) { + ma.messageWithSound(it.errorMessage, true, false) + } else { + if (it.id != 0) { + binding.itemData.text = "${it.id}: ${it.longName}" + } else { ma.messageWithSound( - getString(R.string.itemUpdated), - isError = it.isError, - true, isToasted = null, + getString(R.string.itemNotFound), + true, + false, + getString(R.string.noResults) ) + } - }) - + } } } - private fun upLoadPhoto() { + } - val drawable = binding.userImage.drawable + private fun upLoadPhoto() { + + if (binding.itemData.text.isNullOrEmpty()) { + getString(R.string.messageUploadItem).toast(requireContext()).show() + } else { + val drawable = binding.itemcardImage.drawable if (drawable is BitmapDrawable) { val bitmap = drawable.bitmap - - println("Ruta"+saveBitmapAsTempFile(requireContext(),bitmap)) - - viewModel.uploadPhoto(saveBitmapAsTempFile(requireContext(),bitmap)) - } - } - fun saveBitmapAsTempFile(context: Context, bitmap: Bitmap): String { - val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date()) - val fileName = "IMG_$timeStamp.jpg" - - val storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) - val tempFile = File.createTempFile(fileName, null, storageDir) - - return try { - val fileOutputStream = FileOutputStream(tempFile) - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream) - fileOutputStream.close() - tempFile.absolutePath - } catch (e: IOException) { - e.printStackTrace() - "" + binding.splashProgress.visibility=VISIBLE + viewModel.uploadPhoto(itemFK = originalItem, urlImage = saveBitmapAsTempFile(requireContext(), bitmap)) } } } + + fun saveBitmapAsTempFile(context: Context, bitmap: Bitmap): String { + val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date()) + val fileName = "IMG_$timeStamp.jpg" + + val storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + val tempFile = File.createTempFile(fileName, null, storageDir) + + return try { + val fileOutputStream = FileOutputStream(tempFile) + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream) + fileOutputStream.close() + tempFile.absolutePath + } catch (e: IOException) { + e.printStackTrace() + "" + } + } + + private fun pickImage() { + val pickIntent = Intent(Intent.ACTION_PICK) + pickIntent.type = "image/*" + val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) + val chooserIntent = Intent.createChooser(pickIntent, "Seleccionar imagen") + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(captureIntent)) + startActivityForResult(chooserIntent, PICK_IMAGE_REQUEST) + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK) { + if (data != null && data.data != null) { + // Imagen seleccionada desde la galería + binding.itemcardImage.setImageURI(data.data) + } else { + // Imagen cámara + var uri = saveBitmapAsTempFile(requireContext(),data?.extras?.get("data") as Bitmap).toUri() + binding.itemcardImage.setImageURI(uri) + //binding.itemcardImage.setImageBitmap(data?.extras?.get("data") as? Bitmap?) + + } + } + } +} diff --git a/app/src/main/res/drawable/ic_image_upload.xml b/app/src/main/res/drawable/ic_image_upload.xml new file mode 100644 index 00000000..aa98e237 --- /dev/null +++ b/app/src/main/res/drawable/ic_image_upload.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_photos.xml b/app/src/main/res/layout/fragment_photos.xml index fc41cfe7..fb47a5ab 100644 --- a/app/src/main/res/layout/fragment_photos.xml +++ b/app/src/main/res/layout/fragment_photos.xml @@ -1,80 +1,96 @@ - - - - - - + android:orientation="vertical" > + + + + + + android:orientation="vertical" + android:visibility="visible"> + + + + + + + + - - + + android:id="@+id/main_toolbar" + layout="@layout/toolbar_fragment" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + app:layout_constraintTop_toTopOf="parent" + android:gravity="center"> + + \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 29b088f2..76415a84 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -229,7 +229,7 @@ Operación ¿Estás seguro de cerrar el pedido? Confirmar acción - Escanea un item + Escanea un artículo No hemos podido encontrar el artículo. Revisa el sector. Error al realizar la operación Escanea expedición. @@ -590,5 +590,8 @@ ¿Desea resetear la revisión del carro? Al pulsar permite resetear la revisión Revisión del carro + Escanea artículo a subir + Tienes que escanear el artículo para poder subirlo + Sube la imagen al servidor diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 1bc15216..279877d8 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -229,7 +229,7 @@ Operación ¿Estás seguro de cerrar el pedido? Confirmar acción - Escanea un item + Escanear artículo No hemos podido encontrar el artículo. Revisa el sector. Error al realizar la operación Escanea expedición. @@ -590,5 +590,8 @@ Souhaitez-vous supprimer la révision de la voiture? Al pulsar permite resetear la revisión Revisión del carro + Escanea artículo a subir + Tienes que escanear el artículo para poder subirlo + Sube la imagen al servidor diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 5e88f673..389dd468 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -229,7 +229,7 @@ Operación ¿Estás seguro de cerrar el pedido? Confirmar acción - Escanea un item + Escanear artículo No hemos podido encontrar el artículo. Revisa el sector. Error al realizar la operación Escanea expedición. @@ -590,5 +590,8 @@ Você deseja excluir a revisão do carro? Al pulsar permite resetear la revisión Revisión del carro + Escanea artículo a subir + Tienes que escanear el artículo para poder subirlo + Sube la imagen al servidor diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c90276c..cc7c1dd6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -589,5 +589,7 @@ Do you want to delete the shelving review? By pressing it allows resetting the review Shelving checking - + Scan item upload + Tienes que escanear el artículo para poder subirlo + Sube la imagen al servidor