diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index dd0466c8..f7bcf33b 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -52,6 +52,7 @@ import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.sacador.model.MistakeTypeVO import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyVO +import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake import es.verdnatura.presentation.view.feature.workermistake.model.ExpeditionMistakeSalix @@ -92,6 +93,11 @@ interface SalixService { @Query("filter") filter: String ): Call> + @GET("ticketStates") + fun lastTicketGetByWorker( + @Query("filter") filter: String + ): Call> + @POST("Applications/{routine}/execute-func") fun executeFunc( @Path("routine") routine: String, diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/TicketLastStateAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/TicketLastStateAdapter.kt new file mode 100644 index 00000000..745440be --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/TicketLastStateAdapter.kt @@ -0,0 +1,43 @@ +package es.verdnatura.presentation.view.feature.sacador.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.databinding.ItemLastTicketRowBinding +import es.verdnatura.presentation.common.OnCollectionSelectedListener +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix + +class TicketLastStateAdapter( + private val items: List, + private val onCollectionSelected: OnCollectionSelectedListener, + private val type: String +) : RecyclerView.Adapter() { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder { + return AjustesItemHolder( + ItemLastTicketRowBinding.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(CollectionVO(items[position].ticketFk), type) + } + } + + + class AjustesItemHolder( + val binding: ItemLastTicketRowBinding + ) : RecyclerView.ViewHolder(binding.root) { + fun bind(item: TicketStateSalix) { + 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/showticket/ShowTicketFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/showticket/ShowTicketFragment.kt index 705e68a0..20c69a1a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/showticket/ShowTicketFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/showticket/ShowTicketFragment.kt @@ -5,25 +5,29 @@ import android.os.Bundle import android.text.InputType.TYPE_CLASS_NUMBER import android.view.View import android.view.inputmethod.EditorInfo +import androidx.recyclerview.widget.LinearLayoutManager import es.verdnatura.R -import es.verdnatura.databinding.FragmentGeneralBlackBinding +import es.verdnatura.databinding.FragmentShowTicketBinding import es.verdnatura.domain.ConstAndValues import es.verdnatura.domain.ConstAndValues.SECTORFK import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.OnCollectionSelectedListener import es.verdnatura.presentation.view.feature.precontrol.ShowTicketViewModel +import es.verdnatura.presentation.view.feature.sacador.adapter.TicketLastStateAdapter import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix @Suppress("UNUSED_ANONYMOUS_PARAMETER") class ShowTicketFragment(var menuOrigin: String) : - BaseFragment( + BaseFragment( ShowTicketViewModel::class ) { private var goBack: Boolean = false private var onCollectionSelectedListener: OnCollectionSelectedListener? = null - override fun getLayoutId(): Int = R.layout.fragment_general_black + override fun getLayoutId(): Int = R.layout.fragment_show_ticket private var type = "" + private var adapter: TicketLastStateAdapter? = null companion object { fun newInstance(menuOrigin: String) = ShowTicketFragment(menuOrigin = menuOrigin) @@ -42,9 +46,8 @@ class ShowTicketFragment(var menuOrigin: String) : if (menuOrigin == getString(R.string.main)) { hideBackButton(binding.mainToolbar) } - setEvents() - + viewModel.lastTicketGetByWorker(mobileApplication.userId!!) super.init() } @@ -64,6 +67,11 @@ class ShowTicketFragment(var menuOrigin: String) : binding.mainToolbar.backButton.setOnClickListener { requireActivity().onBackPressed() } + binding.sacadorSwipe.setOnRefreshListener { + binding.sacadorSwipe.isRefreshing = true + viewModel.lastTicketGetByWorker(mobileApplication.userId!!) + binding.sacadorSwipe.isRefreshing = false + } binding.scanInput.requestFocus() binding.scanInput.setRawInputType(TYPE_CLASS_NUMBER) @@ -80,6 +88,7 @@ class ShowTicketFragment(var menuOrigin: String) : print = "0", type = type ) + binding.splashProgress.visibility = View.VISIBLE } catch (ex: Exception) { ma.messageWithSound( @@ -98,6 +107,15 @@ class ShowTicketFragment(var menuOrigin: String) : } } + private fun createCollectionList(listTickets: List) { + + val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + adapter = TicketLastStateAdapter(listTickets, onCollectionSelectedListener!!, type) + binding.lastTicketsRecyclerview.layoutManager = lm + binding.lastTicketsRecyclerview.adapter = adapter + + } + override fun observeViewModel() { with(viewModel) { collectionTicketList.observe(viewLifecycleOwner) { @@ -110,7 +128,13 @@ class ShowTicketFragment(var menuOrigin: String) : } } - + lastTicketList.observe(viewLifecycleOwner) { + if (it.list.isNotEmpty()) { + createCollectionList(it.list) + } else { + binding.txtLastTickets.visibility = View.INVISIBLE + } + } } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/showticket/ShowTicketViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/showticket/ShowTicketViewModel.kt index 37531643..594940c2 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/showticket/ShowTicketViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/showticket/ShowTicketViewModel.kt @@ -3,49 +3,63 @@ package es.verdnatura.presentation.view.feature.precontrol import android.content.Context import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.SalixCallback import es.verdnatura.domain.SilexCallback import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.nameofFunction import es.verdnatura.presentation.view.feature.collection.mapper.map import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import es.verdnatura.presentation.view.feature.sacador.model.TicketStateList +import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix import retrofit2.Response class ShowTicketViewModel(val context: Context) : BaseViewModel(context) { private val _collectionTicketList by lazy { MutableLiveData() } - val collectionTicketList: LiveData - get() = _collectionTicketList + val collectionTicketList: LiveData = _collectionTicketList + + private val _lastTicketList by lazy { MutableLiveData() } + val lastTicketList: LiveData = _lastTicketList fun collectionTicketGet(collectionFk: Int, sectorFk: Int, print: String, type: String) { //Tarea 6276 //salix.collectionGetTickets(collectionFk,sectorFk,print.toInt(),type) silex.collection_getTickets(collectionFk, sectorFk, print, type) .enqueue(object : - SilexCallback(context) { - override fun onError(t: Throwable) { - _collectionTicketList.value = CollectionVO( - 0, - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } - - override fun onSuccess(response: Response) { - if (response.body() != null) { - _collectionTicketList.value = response.body()?.let { it.map(context) } - } else { + SilexCallback(context) { + override fun onError(t: Throwable) { _collectionTicketList.value = CollectionVO( 0, isError = true, - errorMessage = getMessageFromAllResponse( - nameofFunction(this), - response.message() - ) + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) ) } - } - }) + + override fun onSuccess(response: Response) { + if (response.body() != null) { + _collectionTicketList.value = response.body()?.let { it.map(context) } + } else { + _collectionTicketList.value = CollectionVO( + 0, + isError = true, + errorMessage = getMessageFromAllResponse( + nameofFunction(this), + response.message() + ) + ) + } + } + }) } + fun lastTicketGetByWorker(userId: Int) { + salix.lastTicketGetByWorker("""{"where": {"userFk": $userId},"order":"updated DESC","limit": 5}""") + .enqueue(object : SalixCallback>(context) { + override fun onSuccess(response: Response>) { + _lastTicketList.value = response.body()?.let { TicketStateList(it) } + } + + }) + } } \ 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 index 16946fe4..9fccbbb5 100644 --- 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 @@ -1,5 +1,9 @@ package es.verdnatura.presentation.view.feature.sacador.model +import android.os.Build +import androidx.annotation.RequiresApi +import es.verdnatura.domain.isoToString + //Tarea 5890 // Sacado reservado @@ -295,3 +299,23 @@ var collectionLocal = CollectionTicket( 3, tickets = ticketLocal ) + +class TicketStateList( + var list: List = listOf() +) + +data class TicketStateSalix( + val ticketFk: Int, + val alertLevel: Int, + val code: String, + val stateFk: Int, + val userFk: Int +) { + @RequiresApi(Build.VERSION_CODES.O) + var updated: String = "" + @RequiresApi(Build.VERSION_CODES.O) + get() { + return field.isoToString() + } + +} diff --git a/app/src/main/res/layout/fragment_show_ticket.xml b/app/src/main/res/layout/fragment_show_ticket.xml new file mode 100644 index 00000000..80568450 --- /dev/null +++ b/app/src/main/res/layout/fragment_show_ticket.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_last_ticket_row.xml b/app/src/main/res/layout/item_last_ticket_row.xml new file mode 100644 index 00000000..e8fb56d7 --- /dev/null +++ b/app/src/main/res/layout/item_last_ticket_row.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + \ 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 5b47c62c..ae95bc35 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -697,6 +697,7 @@ Está siendo revisado por %1$s Ha sido revisado por %1$s PREVIA:%1$s + Últimos tickets modificados : diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 72ce8caf..4ffac1b9 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -696,6 +696,7 @@ Está siendo revisado por %1$s Ha sido revisado por %1$s PREVIA:%1$s + Últimos tickets modificados : diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index f5507be4..17910c8a 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -696,6 +696,7 @@ Está siendo revisado por %1$s Ha sido revisado por %1$s PREVIA:%1$s + Últimos tickets modificados : diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a6b4e0be..32ad77af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -696,5 +696,6 @@ Ticket on checking by %1$s ticket checked by %1$s PREVIA:%1$s + Últimos tickets modificados :