diff --git a/app/build.gradle b/app/build.gradle index 8ce32851..b0d9f5fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "es.verdnatura" minSdkVersion 21 targetSdkVersion 29 - versionCode 5 - versionName "5.0.5" + versionCode 7 + versionName "5.0.7" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index 08dee569..9204a681 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -3,6 +3,7 @@ package es.verdnatura.di import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesViewModel import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardViewModel import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemViewModel +import es.verdnatura.presentation.view.feature.collection.fragment.CollectionViewModel import es.verdnatura.presentation.view.feature.faltas.fragment.FaltasViewModel import es.verdnatura.presentation.view.feature.historico.fragment.HistoricoViewModel import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryViewModel @@ -12,6 +13,7 @@ import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionPa import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionScanViewModel import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionTruckListViewModel import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel +import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorViewModel import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingViewModel import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemViewModel import es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorViewModel @@ -89,4 +91,13 @@ val viewModelModule = module{ viewModel { ExpeditionScanViewModel() } + + // SACADOR + viewModel { + SacadorViewModel() + } + + viewModel { + CollectionViewModel() + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/ApiUtils.kt b/app/src/main/java/es/verdnatura/domain/ApiUtils.kt index 9f3228eb..b17cfbb4 100644 --- a/app/src/main/java/es/verdnatura/domain/ApiUtils.kt +++ b/app/src/main/java/es/verdnatura/domain/ApiUtils.kt @@ -8,8 +8,8 @@ import java.util.concurrent.TimeUnit class ApiUtils { companion object { - //const val BASE_URL:String = "http://192.168.1.108:8008/" - const val BASE_URL:String = "https://app.verdnatura.es/" + const val BASE_URL:String = "http://192.168.1.108:8008/" + //const val BASE_URL:String = "https://app.verdnatura.es/" fun getApiService():VerdnaturaService{ val retrofit = Retrofit.Builder() .baseUrl(BASE_URL) diff --git a/app/src/main/java/es/verdnatura/domain/GetSacadorControladorUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetSacadorControladorUserCase.kt new file mode 100644 index 00000000..49211622 --- /dev/null +++ b/app/src/main/java/es/verdnatura/domain/GetSacadorControladorUserCase.kt @@ -0,0 +1,20 @@ +package es.verdnatura.domain + +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import retrofit2.Call + +class GetSacadorControladorUserCase : RestClient() { + + fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String) : Call { + val params:ArrayList = ArrayList(); + params.add(collectionFk) + params.add(sectorFk) + return restClient!!.collectionTicketGet("json","1",usuario,password,"application/json",params) + } + + fun collectionGet(usuario:String,password:String) : Call> { + val params:ArrayList = ArrayList(); + return restClient!!.collectionGet("json","1",usuario,password,"application/json") + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt index 70bc9bbe..f57838cc 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -9,6 +9,7 @@ import es.verdnatura.presentation.view.feature.faltas.model.ItemFaltasVO import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO import es.verdnatura.presentation.view.feature.paletizador.model.* +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.shelvingparking.model.ItemShelvingParkingVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO import retrofit2.Call @@ -50,6 +51,24 @@ interface VerdnaturaService { Call> + //SACADORES / CONTROLADORES ========================================================================> + @POST("almacennew/collectionGet") + fun collectionGet(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String): + Call> + + @POST("almacennew/collectionTicketGet") + fun collectionTicketGet(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): + Call + //PASILLEROS ========================================================================> //CONSULTAR ARTICULO ========================================================================> diff --git a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt index be8a28ff..8379322b 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -12,6 +12,7 @@ import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionT import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO interface OnOptionsSelectedListener { @@ -77,4 +78,8 @@ interface OnComprobarPalletViewClickListener { interface OnScanLongClickListener { fun onScanLongClickListener(ItemExpeditionScanVO: ItemExpeditionScanVO) +} + +interface OnCollectionSelectedListener { + fun onCollectionSelected(collection: CollectionVO) } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/common/UIExtensions.kt b/app/src/main/java/es/verdnatura/presentation/common/UIExtensions.kt index 6b3eb3ad..5834443f 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UIExtensions.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UIExtensions.kt @@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentTransaction import com.bumptech.glide.Glide import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition +import java.util.* inline fun FragmentManager.inTransaction(func: FragmentTransaction.() -> FragmentTransaction) = @@ -65,8 +66,6 @@ fun View.setMargins(left: Int, top: Int, right: Int, bottom: Int) { } fun ImageView.loadUrl(url: String) { -// load(url) -// Glide.with(context).load(url).into(this) Glide.with(context) .asBitmap() .load(url) @@ -81,4 +80,37 @@ fun ImageView.loadUrl(url: String) { } inline val T.TAG: String - get() = T::class.java.canonicalName ?: T::class.simpleName ?: T::class.java.simpleName \ No newline at end of file + get() = T::class.java.canonicalName ?: T::class.simpleName ?: T::class.java.simpleName + +fun Calendar.convertToDateString(): String { + var dayOfWeek = "" + var dayOfMonth = "" + val day = this[Calendar.DATE] + + when (this[Calendar.DAY_OF_WEEK]) { + 1 -> dayOfWeek = "Dom" + 2 -> dayOfWeek = "Lun" + 3 -> dayOfWeek = "Mar" + 4 -> dayOfWeek = "Mie" + 5 -> dayOfWeek = "Jue" + 6 -> dayOfWeek = "Vie" + 7 -> dayOfWeek = "Sab" + } + + when (this[Calendar.MONTH]) { + 0 -> dayOfMonth = "Ene" + 1 -> dayOfMonth = "Feb" + 2 -> dayOfMonth = "Mar" + 3 -> dayOfMonth = "Abr" + 4 -> dayOfMonth = "May" + 5 -> dayOfMonth = "Jun" + 6 -> dayOfMonth = "Jul" + 7 -> dayOfMonth = "Ago" + 8 -> dayOfMonth = "Sep" + 9 -> dayOfMonth = "Oct" + 10 -> dayOfMonth = "Nov" + 11 -> dayOfMonth = "Dic" + } + + return dayOfWeek + " " + day + " " + dayOfMonth +} \ No newline at end of file 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 new file mode 100644 index 00000000..27760c2f --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt @@ -0,0 +1,112 @@ +package es.verdnatura.presentation.view.feature.collection.fragment + +import android.content.Context +import android.content.SharedPreferences +import android.graphics.drawable.Drawable +import androidx.lifecycle.ViewModelProviders +import android.os.Bundle +import android.util.Log +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager + +import es.verdnatura.R +import es.verdnatura.databinding.FragmentCollectionBinding +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.view.feature.inventario.adapter.ToolBarAdapter +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.fragment_collection.* +import kotlinx.android.synthetic.main.toolbar.* + +class CollectionFragment( + var collection : CollectionVO = CollectionVO() +) : BaseFragment(CollectionViewModel::class){ + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + + companion object { + fun newInstance(collection:CollectionVO) = CollectionFragment(collection) + } + + override fun onAttach(context: Context) { + super.onAttach(context) + + } + override fun getLayoutId(): Int = R.layout.fragment_collection + + override fun onCreate(savedInstanceState: Bundle?) { + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + if (collection.tickets.isEmpty()){ + viewModel.collectionTicketGet(user,password,collection.collectionFk,sectorFk) + }else{ + createCollectionList() + } + + super.onCreate(savedInstanceState) + } + + override fun init() { + activity!!.main_bottom_navigation.visibility = View.GONE + splash_progress.visibility = View.VISIBLE + toolbar_title.text = "collectionTicket_get" + setToolBar() + setEvents() + super.init() + } + + private fun setToolBar(){ + val listIcons:ArrayList = ArrayList() + val iconReload : Drawable = resources.getDrawable(R.drawable.ic_autorenew_black_24dp,resources.newTheme()) + listIcons.add(iconReload) + toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + if (item == iconReload){ + splash_progress.visibility = View.VISIBLE + viewModel.collectionTicketGet(user,password,collection.collectionFk,sectorFk) + } + } + }) + toolbar_icons.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun setEvents(){ + backButton.setOnClickListener { + activity!!.onBackPressed() + } + } + + override fun observeViewModel() { + with(viewModel){ + collectionTicketList.observe(viewLifecycleOwner, Observer { + splash_progress.visibility = View.GONE + if(it.tickets.isEmpty()){ + if (R.id.collection_empty_text == collection_switcher.nextView.id){ + collection_switcher.showNext() + } + }else{ + collection = it + createCollectionList() + } + + }) + } + } + + + private fun createCollectionList(){ + splash_progress.visibility = View.GONE + Log.i("Collection",collection.collectionFk) + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt new file mode 100644 index 00000000..5704234e --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt @@ -0,0 +1,41 @@ +package es.verdnatura.presentation.view.feature.collection.fragment + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.GetSacadorControladorUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class CollectionViewModel : BaseViewModel() { + + val emptyMessage = "La colección no tiene tickets"; + + private val getSacadorControladorUserCase: GetSacadorControladorUserCase = GetSacadorControladorUserCase() + + private val _collectionTicketList by lazy { MutableLiveData() } + val collectionTicketList: LiveData + get() = _collectionTicketList + + + fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String){ + getSacadorControladorUserCase.collectionTicketGet(usuario,password,collectionFk,sectorFk).enqueue(object : + Callback { + override fun onFailure(call: Call, t: Throwable) { + _collectionTicketList.value = CollectionVO(isError = true,errorMessage = t.message!!) + } + override fun onResponse( + call: Call, + response: Response + ) { + if (response.body() != null){ + _collectionTicketList.value = response.body()?.let { it } + }else{ + _collectionTicketList.value = CollectionVO(isError = true,errorMessage = "Error en la llamada de collection_get") + } + } + }) + } +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoViewModel.kt index 9c14a6f8..4b7bdb8e 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoViewModel.kt @@ -49,8 +49,4 @@ class HistoricoViewModel : BaseViewModel() { }) } - - - - } 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 f304dd0a..00481e4b 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 @@ -15,6 +15,7 @@ import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesFragment import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardFragment import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemFragment +import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragment import es.verdnatura.presentation.view.feature.faltas.fragment.FaltasFragment import es.verdnatura.presentation.view.feature.historico.fragment.HistoricoFragment import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryFragment @@ -27,6 +28,8 @@ import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionT import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroFragment import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorFragment +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingFragment import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemFragment import es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorFragment @@ -37,7 +40,7 @@ import kotlinx.coroutines.launch class MainActivity : BaseActivity() , OnPasillerosItemClickListener, - OnTruckClickListener, OnPalletClickListener,OnComprobarPalletViewClickListener { + OnTruckClickListener, OnPalletClickListener,OnComprobarPalletViewClickListener,OnCollectionSelectedListener { private var lastBottomMenuItemSelected: ItemMenuVO? = null private lateinit var customDialog: CustomDialog @@ -126,7 +129,8 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick true } "Sacadores" -> { - "Función Sacadores desactivada".toast(this@MainActivity) + fm.popBackStack(null,FragmentManager.POP_BACK_STACK_INCLUSIVE) + addFragment(SacadorFragment.newInstance(),R.id.main_frame_layout, SacadorFragment.TAG,false) true } "Controladores" -> { @@ -225,4 +229,8 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick addFragmentOnTop(ExpeditionPalletDetailFragment.newInstance(itemTruck,itemPallet)) } + override fun onCollectionSelected(collection: CollectionVO) { + addFragmentOnTop(CollectionFragment.newInstance(collection)) + } + } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletDetailViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletDetailViewModel.kt index edbc9d1c..a3ab7185 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletDetailViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletDetailViewModel.kt @@ -66,11 +66,11 @@ class ExpeditionPalletDetailViewModel: BaseViewModel() { fun expeditionPalletPrintSet(usuario:String,password:String,vPalletFk:String){ getPaletizadoresUserCase.expeditionPalletPrintSet(usuario,password,vPalletFk).enqueue(object : Callback{ override fun onFailure(call: Call, t: Throwable) { - _response.value = ResponseItemVO(isError = true,errorMessage = "Error al borrar pallet "+vPalletFk+ " Respuesta:"+t.message!!) + _response.value = ResponseItemVO(isError = true,errorMessage = "Error al imprimir pallet "+vPalletFk+ " Respuesta:"+t.message!!) } override fun onResponse(call: Call, response: Response) { if (response.body() == null){ - _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada expeditionPallet_Del") + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada expeditionPallet_PrintSet") }else{ _response.value = ResponseItemVO(isError = false,response = response.body()!!) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt index 202646be..a997aa70 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt @@ -41,8 +41,6 @@ class PasilleroFragment : BaseFragment, + private val onCollectionSelected: OnCollectionSelectedListener +): RecyclerView.Adapter () { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder { + return AjustesItemHolder( + ItemCollectionRowBinding.inflate(LayoutInflater.from(parent.context),parent,false) + ) + } + + override fun getItemCount() =items.size + + override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) { + holder.bind(items[position]) + holder.binding.root.setOnClickListener { + onCollectionSelected.onCollectionSelected(items[position]) + } + } + + + class AjustesItemHolder( + val binding: ItemCollectionRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + fun bind(item: CollectionVO) { + binding.apply { + this.item = item + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragment.kt new file mode 100644 index 00000000..fbd42065 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragment.kt @@ -0,0 +1,121 @@ +package es.verdnatura.presentation.view.feature.sacador.fragment + +import android.content.Context +import android.content.SharedPreferences +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.view.View +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentSacadorBinding +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnCollectionSelectedListener +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.view.feature.inventario.adapter.ToolBarAdapter +import es.verdnatura.presentation.view.feature.sacador.adapter.CollectionAdapter +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import kotlinx.android.synthetic.main.fragment_sacador.* +import kotlinx.android.synthetic.main.toolbar.* +import java.text.SimpleDateFormat +import java.util.* +import kotlin.collections.ArrayList + +class SacadorFragment : BaseFragment(SacadorViewModel::class) { + + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + private var onCollectionSelectedListener : OnCollectionSelectedListener? = null + + + companion object { + fun newInstance() = SacadorFragment() + } + + override fun onAttach(context: Context) { + super.onAttach(context) + if (context is OnCollectionSelectedListener) onCollectionSelectedListener = context + } + override fun getLayoutId(): Int = R.layout.fragment_sacador + + override fun onCreate(savedInstanceState: Bundle?) { + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + viewModel.collectionGet(user,password) + super.onCreate(savedInstanceState) + } + + override fun init() { + splash_progress.visibility = View.VISIBLE + toolbar_title.text = "collection_get" + setToolBar() + setEvents() + super.init() + } + + private fun setToolBar(){ + backButton.visibility = View.GONE + val listIcons:ArrayList = ArrayList() + val iconReload : Drawable = resources.getDrawable(R.drawable.ic_autorenew_black_24dp,resources.newTheme()) + val iconAdd : Drawable = resources.getDrawable(R.drawable.ic_add_black_24dp,resources.newTheme()) + listIcons.add(iconReload) + listIcons.add(iconAdd) + toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + if (item == iconReload){ + splash_progress.visibility = View.VISIBLE + viewModel.collectionGet(user,password) + }else if(item == iconAdd){ + splash_progress.visibility = View.VISIBLE + viewModel.collectionTicketGet(user,password,"",sectorFk) + } + } + + }) + toolbar_icons.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun setEvents(){ + + } + + override fun observeViewModel() { + with(viewModel){ + collectionList.observe(viewLifecycleOwner, Observer { + splash_progress.visibility = View.GONE + if(it.list.isEmpty()){ + if (R.id.sacador_empty_text == sacador_switcher.nextView.id){ + sacador_switcher.showNext() + } + }else { + createCollectionList(it.list) + } + + }) + collectionTicketList.observe(viewLifecycleOwner, Observer { + navigateToCollectionList(it) + }) + } + } + + private fun createCollectionList(collections:List){ + + val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + val adapter = CollectionAdapter(collections,onCollectionSelectedListener!!) + fragment_sacador_collections.layoutManager = lm + fragment_sacador_collections.adapter = adapter + } + + + private fun navigateToCollectionList(collection:CollectionVO){ + splash_progress.visibility = View.GONE + // onCollectionSelectedListener!!.onCollectionSelected(collection) + } + + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt new file mode 100644 index 00000000..0ce71572 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt @@ -0,0 +1,75 @@ +package es.verdnatura.presentation.view.feature.sacador.fragment + + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.GetSacadorControladorUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.view.feature.sacador.mapper.toDateFormat +import es.verdnatura.presentation.view.feature.sacador.model.CollectionListVO +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class SacadorViewModel : BaseViewModel() { + + val emptyMessage = "No tienes colecciones pendientes. Presiona sobre el + para crear colección"; + + private val getSacadorControladorUserCase: GetSacadorControladorUserCase = GetSacadorControladorUserCase() + + private val _collectionList by lazy { MutableLiveData() } + val collectionList: LiveData + get() = _collectionList + + private val _collectionTicketList by lazy { MutableLiveData() } + val collectionTicketList: LiveData + get() = _collectionTicketList + + + fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String){ + getSacadorControladorUserCase.collectionTicketGet(usuario,password,collectionFk,sectorFk).enqueue(object : + Callback { + override fun onFailure(call: Call, t: Throwable) { + _collectionTicketList.value = CollectionVO(isError = true,errorMessage = t.message!!) + } + override fun onResponse( + call: Call, + response: Response + ) { + if (response.body() != null){ + _collectionTicketList.value = response.body()?.let { it } + }else{ + _collectionTicketList.value = CollectionVO(isError = true,errorMessage = "Error en la llamada de collection_get") + } + } + }) + } + + fun collectionGet(usuario:String,password:String){ + getSacadorControladorUserCase.collectionGet(usuario,password).enqueue(object : + Callback> { + override fun onFailure(call: Call>, t: Throwable) { + val listError:ArrayList = ArrayList() + listError.add(CollectionVO(isError = true,errorMessage = t.message!!)) + _collectionList.value = CollectionListVO(listError) + } + + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _collectionList.value = response.body()?.let { CollectionListVO(it.toDateFormat()) } + }else{ + val listError:ArrayList = ArrayList() + listError.add(CollectionVO(isError = true,errorMessage = "Error en la llamada de collection_get")) + _collectionList.value = CollectionListVO(listError) + + } + } + + }) + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/mapper/SacadoresMapper.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/mapper/SacadoresMapper.kt new file mode 100644 index 00000000..609a6a64 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/mapper/SacadoresMapper.kt @@ -0,0 +1,27 @@ +package es.verdnatura.presentation.view.feature.sacador.mapper + +import es.verdnatura.presentation.common.convertToDateString +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import java.text.SimpleDateFormat +import java.util.* +import kotlin.collections.ArrayList + +fun List.toDateFormat(): ArrayList { + val collections : ArrayList = ArrayList() + this.forEach { + collections.add(CollectionVO( + collectionFk = it.collectionFk, + created = getCalendarFromDate(it.created).convertToDateString() + )) + + } + return collections +} + + +private fun getCalendarFromDate(date:String): Calendar { + val sdf = SimpleDateFormat("yyyy-MM-dd") + val cal = Calendar.getInstance() + cal.setTime(sdf.parse(date)) + return cal +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt new file mode 100644 index 00000000..7984037a --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt @@ -0,0 +1,69 @@ +package es.verdnatura.presentation.view.feature.sacador.model + +class CollectionListVO( + var list: List = listOf() +) + +class CollectionVO( + var collectionFk : String = "", + var created : String = "", + var tickets : List = listOf(), + var isError : Boolean = false, + var errorMessage : String = "" +) + +class TicketVO( + var ticketFk : String = "", + var level : String = "", + var agencyName : String = "", + var sales : List = listOf() +) +class SaleVO( + var ticketFk : String = "", + var saleFk : String = "", + var itemFk : String = "", + var quantity : String = "", + var longName : String = "", + var size : String = "", + var reserved : String = "", + var isPreviousPrepared : String = "", + var isPrepared : String = "", + var isControlled : String = "", + var color : String = "", + var productor : String = "", + var discount : String = "", + var price : String = "", + var stems : String = "", + var category : String = "", + var origin : String = "", + var clientFk : String = "", + var originalQuantity : String = "", + var line1 : String = "", + var line2 : String = "", + var line3 : String = "", + var isAdded : String = "", + var startQuantity : String = "", + var workerFk : String = "", + var placements : List = listOf(), + var Barcodes : List = listOf() +) + +class PlacementVO( + var saleFk : String = "", + var itemFk : String = "", + var placement : String = "", + var shelving : String = "", + var created : String = "", + var visible : String = "", + var order : String = "", + var grouping : String = "", + var priority : String = "", + var saleOrder : String = "", + var isPreviousPrepared : String = "", + var itemShelvingSaleFk : String = "", + var ticketFk : String = "", + var id : String = "" +) + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ccd5820f..f2e186f3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -23,7 +23,7 @@ android:layout_width="match_parent" android:layout_height="@dimen/bottom_navigation_height" app:itemBackground="@color/verdnatura_black_3" - app:itemTextColor="@drawable/selector_bottombar_text" + app:itemTextColor="@color/verdnatura_white" app:labelVisibilityMode="labeled" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/component_custom_dialog.xml b/app/src/main/res/layout/component_custom_dialog.xml index 6e328c83..3a9b6196 100644 --- a/app/src/main/res/layout/component_custom_dialog.xml +++ b/app/src/main/res/layout/component_custom_dialog.xml @@ -26,7 +26,8 @@ android:textStyle="bold" android:visibility="gone" tools:text="¿Estás seguro de que deseas eliminar el dispositivo de celia?" - tools:visibility="visible" /> + tools:visibility="visible" + android:gravity="center_horizontal" /> + tools:visibility="visible" + android:gravity="center_horizontal" />