feat notesDelivery #refs 6921
This commit is contained in:
parent
fcb351c7d8
commit
83635cfa2e
|
@ -15,6 +15,7 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.gson.Gson
|
||||
import es.verdnatura.R
|
||||
import es.verdnatura.databinding.FragmentTicketsBinding
|
||||
|
@ -40,7 +41,6 @@ import es.verdnatura.presentation.view.component.CustomDialogInputNotes
|
|||
import es.verdnatura.presentation.view.component.CustomDialogList
|
||||
import es.verdnatura.presentation.view.feature.delivery.adapters.TicketAdapter
|
||||
import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix
|
||||
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
|
||||
import es.verdnatura.presentation.view.feature.delivery.model.RouteInfo
|
||||
import es.verdnatura.presentation.view.feature.delivery.model.Ticket
|
||||
import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel
|
||||
|
@ -51,7 +51,7 @@ import kotlinx.coroutines.withContext
|
|||
import java.util.Calendar
|
||||
|
||||
class TicketsFragment(
|
||||
var title: String = "", var route: RouteInfo
|
||||
var title: String = "", var route: RouteInfo,
|
||||
) : BaseFragment<FragmentTicketsBinding, DeliveryViewModel>(
|
||||
DeliveryViewModel::class
|
||||
) {
|
||||
|
@ -64,6 +64,7 @@ class TicketsFragment(
|
|||
private lateinit var db: DeliveryDatabase
|
||||
private var isBack = false
|
||||
private lateinit var customDialogList: CustomDialogList
|
||||
private var firstVisibleItemPosition = -1
|
||||
|
||||
companion object {
|
||||
fun newInstance(title: String, entryPoint: String) =
|
||||
|
@ -82,8 +83,7 @@ class TicketsFragment(
|
|||
binding.mainToolbar.toolbarTitle.text = route.name
|
||||
viewModel.getTickets(route.id)
|
||||
db = database(requireContext().applicationContext)
|
||||
println("route started ${route.started}")
|
||||
println("route finished ${route.finished}")
|
||||
|
||||
}
|
||||
|
||||
private fun setTitle() {
|
||||
|
@ -140,8 +140,8 @@ class TicketsFragment(
|
|||
showSigned = !showSigned
|
||||
changeVisibleSettings(showSigned)
|
||||
changeColorIcon(iconSettings.drawable, showSigned)
|
||||
binding.kmStart.setText(route.kmStart?.toString())
|
||||
binding.kmEnd.setText(route.kmEnd?.toString())
|
||||
binding.kmStart.setText(route.kmStart?.toString() ?: "0")
|
||||
binding.kmEnd.setText(route.kmEnd?.toString() ?: "0")
|
||||
|
||||
binding.hourInit.setText(getHourDay(route.started.isoToString()))
|
||||
if (route.started == "0000-00-00 00:00:00" || route.started > route.finished) {
|
||||
|
@ -158,8 +158,7 @@ class TicketsFragment(
|
|||
title = getString(R.string.titleWebViewer),
|
||||
), entryPoint = Gson().toJson(
|
||||
mutableMapOf(
|
||||
"entryPoint" to route.id,
|
||||
"web" to "${
|
||||
"entryPoint" to route.id, "web" to "${
|
||||
mobileApplication.dataStoreApp.getServerSalix()
|
||||
}#!/route/${route.id}/tickets"
|
||||
)
|
||||
|
@ -234,6 +233,19 @@ class TicketsFragment(
|
|||
}
|
||||
}
|
||||
setSettingsRoute()
|
||||
setRecyclerViewer()
|
||||
}
|
||||
|
||||
private fun setRecyclerViewer() {
|
||||
binding.ticketsRecyclerview.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
|
||||
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
||||
firstVisibleItemPosition = layoutManager.findFirstCompletelyVisibleItemPosition()
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun setSettingsRoute() {
|
||||
|
@ -241,11 +253,10 @@ class TicketsFragment(
|
|||
binding.kmStart.setText(route.kmStart.toString())
|
||||
binding.kmEnd.setText(route.kmEnd.toString())
|
||||
binding.saveButton.setOnClickListener {
|
||||
route.kmStart = binding.kmStart.text.toString().toLong()
|
||||
route.kmEnd = binding.kmEnd.text.toString().toLong()
|
||||
route.kmStart = binding.kmStart.text.toString().toLongOrNull()
|
||||
route.kmEnd = binding.kmEnd.text.toString().toLongOrNull()
|
||||
route.started = addDateToTime(binding.hourInit.text.toString())
|
||||
route.finished = addDateToTime(binding.hourEnd.text.toString())
|
||||
println()
|
||||
viewModel.routeUpdate(route)
|
||||
}
|
||||
binding.hourInit.setOnFocusChangeListener { _, b ->
|
||||
|
@ -271,7 +282,11 @@ class TicketsFragment(
|
|||
// createListRoutes(it.list)
|
||||
}
|
||||
}
|
||||
|
||||
loadNotes.observe(viewLifecycleOwner) { event ->
|
||||
event.getContentIfNotHandled().notNull {
|
||||
viewModel.getTickets(route.id)
|
||||
}
|
||||
}
|
||||
|
||||
clientTicketList.observe(viewLifecycleOwner) {
|
||||
if (it.list.isNotEmpty()) {
|
||||
|
@ -282,7 +297,13 @@ class TicketsFragment(
|
|||
responseStateAdd.observe(viewLifecycleOwner) {}
|
||||
response.observe(viewLifecycleOwner) {
|
||||
if (!it.isError) {
|
||||
ma.messageWithSound(it.response, isError = false, isPlayed = false, titleWithError = "", isToasted = true)
|
||||
ma.messageWithSound(
|
||||
it.response,
|
||||
isError = false,
|
||||
isPlayed = false,
|
||||
titleWithError = "",
|
||||
isToasted = true
|
||||
)
|
||||
}
|
||||
}
|
||||
responseUpdateRoute.observe(viewLifecycleOwner) {
|
||||
|
@ -291,7 +312,13 @@ class TicketsFragment(
|
|||
setToolBar()
|
||||
}
|
||||
responseLoadList.observe(viewLifecycleOwner) {
|
||||
ma.messageWithSound(getString(R.string.offline), isError = true, isPlayed = false, titleWithError = "", isToasted = true)
|
||||
ma.messageWithSound(
|
||||
getString(R.string.offline),
|
||||
isError = true,
|
||||
isPlayed = false,
|
||||
titleWithError = "",
|
||||
isToasted = true
|
||||
)
|
||||
createLisTickets(mutableListOf(), getSaved = true)
|
||||
}
|
||||
}
|
||||
|
@ -406,8 +433,7 @@ class TicketsFragment(
|
|||
title = getString(R.string.titleWebViewer),
|
||||
), entryPoint = Gson().toJson(
|
||||
mutableMapOf(
|
||||
"entryPoint" to route.id,
|
||||
"web" to "${
|
||||
"entryPoint" to route.id, "web" to "${
|
||||
mobileApplication.dataStoreApp.getServerSalix()
|
||||
}/api/Routes/${item.cmrFk}/cmr?access_token=${
|
||||
mobileApplication.dataStoreApp.readDataStoreKey<String>(
|
||||
|
@ -432,6 +458,7 @@ class TicketsFragment(
|
|||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
adapter!!.notifyDataSetChanged()
|
||||
setTitle()
|
||||
setListPosition()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,21 +492,18 @@ class TicketsFragment(
|
|||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
customDialogInput.setOkButton(getString(R.string.save)) {
|
||||
//tarea 6921
|
||||
/*if (itemClient.observationDropOff == null) {
|
||||
viewModel.addNotesFromDropOff(
|
||||
TicketObservation(
|
||||
ticketFk = itemClient.id,
|
||||
description = customDialogInput.getValue(),
|
||||
observationTypeFk = 10
|
||||
if (itemClient.observationDropOff == null) {
|
||||
viewModel.addFropOff(
|
||||
ticketFK = itemClient.id,
|
||||
note = customDialogInput.getValue(),
|
||||
|
||||
)
|
||||
)
|
||||
} else {
|
||||
viewModel.updateNotesFromDropOff(
|
||||
itemClient.id,
|
||||
description = customDialogInput.getValue()
|
||||
itemClient.id, description = customDialogInput.getValue()
|
||||
)
|
||||
}*/
|
||||
viewModel.addNotes(itemClient.tickets, customDialogInput.getValue())
|
||||
}
|
||||
// viewModel.addNotes(itemClient.tickets, customDialogInput.getValue())
|
||||
customDialogInput.dismiss()
|
||||
}.setKoButton(getString(R.string.cancel)) {
|
||||
customDialogInput.cancel()
|
||||
|
@ -487,6 +511,9 @@ class TicketsFragment(
|
|||
}
|
||||
customDialogInput.show()
|
||||
|
||||
/* firstVisibleItemPosition =
|
||||
(binding.ticketsRecyclerview.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()*/
|
||||
|
||||
}
|
||||
|
||||
fun showNotes(clientClicked: ClientTicketSalix) {
|
||||
|
@ -496,7 +523,7 @@ class TicketsFragment(
|
|||
|
||||
ticketNotes.add(
|
||||
GeneralItem(
|
||||
text = "Reparto:${clientClicked.observationDelivery}",
|
||||
text = getString(R.string.deliveryNote, clientClicked.observationDelivery),
|
||||
code = ""
|
||||
)
|
||||
)
|
||||
|
@ -505,7 +532,7 @@ class TicketsFragment(
|
|||
|
||||
ticketNotes.add(
|
||||
GeneralItem(
|
||||
text = "Repartidor:${clientClicked.observationDropOff}",
|
||||
text = getString(R.string.deliveryDriverNote, clientClicked.observationDropOff),
|
||||
code = ""
|
||||
)
|
||||
)
|
||||
|
@ -534,11 +561,10 @@ class TicketsFragment(
|
|||
|
||||
}
|
||||
|
||||
private fun setListPosition(list: MutableList<ExpeditionInfoLoadUnload>) {
|
||||
for (i in list.indices) {
|
||||
binding.ticketsRecyclerview.scrollToPosition(i)
|
||||
break
|
||||
}
|
||||
private fun setListPosition() {
|
||||
(binding.ticketsRecyclerview.layoutManager as LinearLayoutManager).scrollToPosition(
|
||||
firstVisibleItemPosition
|
||||
)
|
||||
}
|
||||
|
||||
fun showPhones(clientClicked: ClientTicketSalix) {
|
||||
|
@ -636,17 +662,13 @@ class TicketsFragment(
|
|||
val hour = mcurrentTime[Calendar.HOUR_OF_DAY]
|
||||
val minute = mcurrentTime[Calendar.MINUTE]
|
||||
val mTimePicker = TimePickerDialog(
|
||||
requireContext(),
|
||||
{ _, selectedHour, selectedMinute ->
|
||||
textV.text =
|
||||
getString(R.string.hourMinute, selectedHour, selectedMinute)
|
||||
},
|
||||
hour,
|
||||
minute,
|
||||
true
|
||||
requireContext(), { _, selectedHour, selectedMinute ->
|
||||
textV.text = getString(R.string.hourMinute, selectedHour, selectedMinute)
|
||||
}, hour, minute, true
|
||||
)
|
||||
mTimePicker.setTitle(getString(R.string.selectTime))
|
||||
mTimePicker.show()
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue