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