refs #4677 Modificar pantalla delivery en picking

This commit is contained in:
Sergio De la torre 2023-09-19 07:19:48 +02:00
parent 8618425413
commit d93e34e13b
9 changed files with 243 additions and 87 deletions

View File

@ -73,12 +73,16 @@ abstract class BaseActivity<T : ViewDataBinding> : AppCompatActivity() {
return ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
}
fun requestLocationUpdates(
fusedLocationClient: FusedLocationProviderClient
) {
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
@ -87,16 +91,10 @@ abstract class BaseActivity<T : ViewDataBinding> : AppCompatActivity() {
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
/*Debes aceptar permisos*/
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
1
)
return
}
println("location running")
fusedLocationClient.requestLocationUpdates(
locationRequest,
locationCallback,

View File

@ -1,8 +1,13 @@
package es.verdnatura.presentation.view.feature.delivery.activity
import android.Manifest
import android.content.DialogInterface
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.location.Location
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.app.ActivityCompat
import androidx.lifecycle.lifecycleScope
import com.google.android.gms.location.LocationResult
import com.google.android.gms.location.LocationServices
@ -91,7 +96,31 @@ class SignedActivity : BaseActivity<ActivitySignBinding>(), LocationUpdateCallba
}
if (locationCurrent.distanceTo(locationClient) > 100 && locationClient.latitude != null && locationClient.longitude != null) {
if (clientTicket.Latitude != null && clientTicket.Longitude != null) {
if (locationCurrent.distanceTo(locationClient) > 100 ) {
val customDialogDistance = CustomDialog(this)
customDialogDistance.setTitle(getString(R.string.confirm))
.setDescription(getString(R.string.locationDiferent)+ getString(R.string.distance) + locationCurrent.distanceTo(locationClient))
.setOkButton(getString(R.string.keep)) {
uploadImage(MyLocation(locationClient.latitude, locationClient.longitude))
customDialogDistance.dismiss()
}.setKoButton(getString(R.string.modify)) {
uploadImage(lastLocationCurrent)
customDialogDistance.dismiss()
}
.show()
}else{
uploadImage(MyLocation(locationClient.longitude, locationClient.latitude))
}
}else{
uploadImage(lastLocationCurrent)
}
/* if (locationCurrent.distanceTo(locationClient) > 100 && clientTicket.Latitude != null && clientTicket.Longitude != null) {
val customDialogDistance = CustomDialog(this)
customDialogDistance.setTitle(getString(R.string.confirm))
@ -112,7 +141,7 @@ class SignedActivity : BaseActivity<ActivitySignBinding>(), LocationUpdateCallba
} else {
uploadImage(MyLocation(locationCurrent.longitude, locationCurrent.latitude))
}
}
}*/
}
private fun setEvents() {
@ -208,12 +237,79 @@ class SignedActivity : BaseActivity<ActivitySignBinding>(), LocationUpdateCallba
}
private fun setLocation() {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
111
)
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
locationUpdateCallback = this
if (checkLocationPermission()) {
requestLocationUpdates(fusedLocationClient)
}
requestLocationUpdates(fusedLocationClient)
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
val permission = Manifest.permission.ACCESS_FINE_LOCATION
if (requestCode == 111) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
requestLocationUpdates(fusedLocationClient)
} else {
if (!shouldShowRequestPermissionRationale(permission)) {
val builder = AlertDialog.Builder(this)
builder.apply {
setTitle(getString(R.string.permissionRequired))
setMessage(getString(R.string.manuallyPermission))
setPositiveButton(
"Aceptar"
) { dialog, which ->
finish()
}
}
val dialog = builder.create()
dialog.show()
} else {
val activity = this
val builder = AlertDialog.Builder(this)
builder.apply {
setTitle(getString(R.string.permissionRequired))
setMessage(getString(R.string.advicePermission))
setPositiveButton(
getString(R.string.accept)
) { dialog, which ->
dialog.dismiss()
ActivityCompat.requestPermissions(
activity,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
111
)
}
setNegativeButton(
getString(R.string.cancel)
) { dialog, which ->
finish()
}
}
val dialog = builder.create()
dialog.show()
}
}
}
}
override fun onLocationReceived(location: LocationResult) {
@ -222,7 +318,7 @@ class SignedActivity : BaseActivity<ActivitySignBinding>(), LocationUpdateCallba
lastLocationCurrent.Latitude = location.locations.last().latitude
println("ubicación - Latitud: $lastLocationCurrent.Latitude, Longitud: $lastLocationCurrent.Longitude")
} else {
println("ubicación vacía")
println("ubicación vacía")
}
}

View File

@ -31,9 +31,7 @@ import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
class RoutesFragment(
@ -46,7 +44,7 @@ class RoutesFragment(
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
private lateinit var myListRoute: MutableList<RouteInfo>
private lateinit var db: DeliveryDatabase
private lateinit var myListRouteLoaded:List <RouteLoaded>
private lateinit var myListRouteLoaded: List<RouteLoaded>
companion object {
fun newInstance(title: String) =
@ -67,7 +65,6 @@ class RoutesFragment(
}
private fun pendingOperations() {
db = database(requireContext().applicationContext)
if (mobileApplication.hasNetwork) {
@ -242,16 +239,15 @@ class RoutesFragment(
}
binding.scanInput.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
val searchText = s.toString().lowercase()
val filteredList = myListRoute.filter { route ->
route.toString().lowercase().contains(searchText)
}.toMutableList()
adapter!!.updateList(filteredList)
filteredList(s.toString().lowercase())
}
override fun afterTextChanged(s: Editable?) {
@ -261,6 +257,14 @@ class RoutesFragment(
}
private fun filteredList(searchText: String) {
val filteredList = myListRoute.filter { route ->
route.toString().lowercase().contains(searchText)
}.toMutableList()
adapter!!.updateList(filteredList)
}
@RequiresApi(Build.VERSION_CODES.O)
override fun observeViewModel() {
@ -333,6 +337,7 @@ class RoutesFragment(
}
// myListRoute = list
adapter = RouteAdapter(
myListRoute,
object : OnItemImageRouteRowClickListener {
@ -359,7 +364,7 @@ class RoutesFragment(
}
},myListRouteLoaded
}, myListRouteLoaded
)
binding.routeRecyclerview.addItemDecoration(
@ -373,6 +378,9 @@ class RoutesFragment(
binding.routeRecyclerview.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter!!.notifyDataSetChanged()
if (!binding.scanInput.text.isNullOrBlank()) {
filteredList(binding.scanInput.text.toString())
}
}
}

View File

@ -16,6 +16,7 @@ import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
@ -28,6 +29,7 @@ import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.base.database
import es.verdnatura.presentation.common.*
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.ClientTicket
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
@ -55,6 +57,7 @@ class TicketsFragment(
private var showSettings = false
private lateinit var db: DeliveryDatabase
private var isBack = false
private lateinit var customDialogList: CustomDialogList
companion object {
fun newInstance(title: String, entryPoint: String) =
@ -85,6 +88,7 @@ class TicketsFragment(
} else {
"0/0"
}
customDialogList = CustomDialogList(requireContext())
}
private fun callBack(callBackEndPoint: Unit) {
@ -195,7 +199,7 @@ class TicketsFragment(
override fun onResume() {
super.onResume()
if (isBack){
if (isBack) {
callBack(viewModel.getTickets(route.id))
isBack = false
}
@ -242,26 +246,14 @@ class TicketsFragment(
private fun setEvents() {
binding.mainToolbar.backButton.setOnClickListener {
setSettingsRoute()
if (!binding.itemcardLayout.isVisible) {
requireActivity().onBackPressed()
} else {
setSettingsRoute()
}
}
setSettingsRoute()
/* binding.scanInput.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
val searchText = s.toString().lowercase()
val filteredList = myListClientTicket.filter { route ->
route.toString().lowercase().contains(searchText)
}.toMutableList()
adapter!!.updateList(filteredList)
}
override fun afterTextChanged(s: Editable?) {
}
})
*/
}
private fun setSettingsRoute() {
@ -379,7 +371,7 @@ class TicketsFragment(
}
//db.clienTicketDao().delete()
myListClientTicketAux.forEach{
myListClientTicketAux.forEach {
it.route = route.id
}
db.clienTicketDao().insert(myListClientTicketAux)
@ -557,40 +549,73 @@ class TicketsFragment(
fun showPhones(clientClicked: ClientTicket) {
if (!clientClicked.Phones.isNullOrEmpty()) {
val phones = mutableListOf<String>().apply {
addAll(clientClicked.Phones!!)
if (!clientClicked.SalePersonPhone.isNullOrEmpty())
add(clientClicked.SalePersonPhone!!)
}
val builder = AlertDialog.Builder(context)
builder.setTitle(getString(R.string.phones))
val listPhones = phones.toTypedArray()
builder.setItems(listPhones) { dialog, which ->
val phones: MutableList<GeneralItem> = mutableListOf()
if (ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.CALL_PHONE
) == PackageManager.PERMISSION_GRANTED
) {
val callIntent = Intent(Intent.ACTION_CALL)
callIntent.data = Uri.parse("tel:$which]")
startActivity(callIntent)
} else {
ActivityCompat.requestPermissions(
context as Activity,
arrayOf(Manifest.permission.CALL_PHONE),
REQUEST_CALL_PERMISSION
if (clientClicked.Phones != null && clientClicked.Phones!!.isNotEmpty()) {
for (t in clientClicked.Phones!!) {
phones.add(
GeneralItem(
text = "${getString(R.string.Cliente)}:$t",
code = t
)
)
}
}
if (!clientClicked.SalePersonPhone.isNullOrEmpty())
phones.add(
GeneralItem(
text = "${getString(R.string.comercial)}:${clientClicked.SalePersonPhone}",
code =
clientClicked.SalePersonPhone.toString()
)
)
customDialogList.setValueVisibility(View.GONE)
customDialogList.setTitle(getString(R.string.phones))
.setKoButton(
getString(
R.string.cancel
)
) {
customDialogList.dismiss()
}.hideDialog().show()
val listPhonesAdapter =
GeneralAdapter(phones, object : OnGeneralItemRowClickListener {
override fun OnGeneralItemRowClickListener(item: GeneralItem) {
phones.forEach {
if (it.code == item.code) {
if (ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.CALL_PHONE
) == PackageManager.PERMISSION_GRANTED
) {
val callIntent = Intent(Intent.ACTION_CALL)
callIntent.data = Uri.parse("tel:${it.code}")
startActivity(callIntent)
}
} else {
ActivityCompat.requestPermissions(
context as Activity,
arrayOf(Manifest.permission.CALL_PHONE),
REQUEST_CALL_PERMISSION
)
}
customDialogList.dismiss()
}
}
}
val dialog = builder.create()
dialog.show()
} else {
getString(R.string.no_phones).toast(requireContext())
}
})
customDialogList.getRecyclerView().adapter = listPhonesAdapter
customDialogList.getRecyclerView().layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
}
fun goMaps(item: ClientTicket) {
@ -635,14 +660,17 @@ class TicketsFragment(
private fun isGoogleMapsInstalled(): Boolean {
return try {
val packageName = "com.google.android.apps.maps"
val packageManager = context?.packageManager
packageManager?.getPackageInfoCompat(packageName)
true
} catch (e: Exception) {
false
}
return true
/*val packageManager = mobileApplication.packageManager
try {
packageManager.getApplicationInfo(
"com.google.android.apps.maps",
PackageManager.GET_ACTIVITIES
)
return true
} catch (e: PackageManager.NameNotFoundException) {
return false
}*/
}
@ -665,3 +693,9 @@ class TicketsFragment(
}
}
data class PhonesTicket(
var label: String,
var phone: String
)

View File

@ -28,7 +28,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/divider"
app:layout_constraintTop_toBottomOf="@+id/main_toolbar"
tools:visibility="visible">
tools:visibility="gone">
<TextView
android:id="@+id/textView20"
@ -277,10 +277,6 @@
tools:listitem="@layout/item_ticket_row"
tools:visibility="gone"/>
<TextClock
android:id="@+id/textClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>

View File

@ -232,7 +232,7 @@
<string name="scanItem">Escanea un artículo</string>
<string name="itemNotFound">No hemos podido encontrar el artículo. Revisa el sector.</string>
<string name="errorOperation">Error al realizar la operación</string>
<string name="scanLabelExpedition">Escanea expedición.</string>
<string name="scanLabelExpedition">Escanea expedición</string>
<string name="buffer">Buffer:</string>
<string name="packingSave">Packing guardado</string>
<string name="previousCollected">Previa recogida</string>
@ -624,9 +624,11 @@
<string name="sin_internet">NO INTERNET</string>
<string name="deliveryApp">Asegúrate de tener la app de reparto instalada</string>
<string name="phones">Teléfonos</string>
<string name="phone">Teléfono</string>
<string name="km">Kilómetros</string>
<string name="hours">Horas</string>
<string name="km_init">Km de inicio</string>
<string name="comercial">Comercial</string>
<string name="km_end">Km de fin</string>
<string name="hour_start">Hora de inicio</string>
<string name="hour_end">Hora de fin</string>
@ -643,6 +645,7 @@
<string name="listInventoryEmpty">La lista del inventario está vacía</string>
<string name="sureSign">¿Estás seguro de firmar?</string>
<string name="locationDiferent">La última posición \nobtenida es distinta \na la actual. ¿Quieres modificar la posición o mantener la registrada?</string>
<string name="distance">Distancia al último punto en que se firmó la descarga en metros:</string>
<string name="keep">Mantener</string>
<string name="sign">Firmar tickets</string>
<string name="signCmr">Firmar CMR</string>
@ -652,6 +655,9 @@
<string name="signed">Ver firmados</string>
<string name="offline">Offline</string>
<string name="no_phones">No hay teléfonos</string>
<string name="permissionRequired">Permiso de Ubicación Requerido</string>
<string name="advicePermission">Para usar esta aplicación, debes otorgar permisos de ubicación.</string>
<string name="manuallyPermission">Habilita manualmente el permiso de ubicación.</string>
</resources>

View File

@ -232,7 +232,7 @@
<string name="scanItem">Escanear artículo</string>
<string name="itemNotFound">No hemos podido encontrar el artículo. Revisa el sector.</string>
<string name="errorOperation">Error al realizar la operación</string>
<string name="scanLabelExpedition">Escanea expedición.</string>
<string name="scanLabelExpedition">Escanea expedición</string>
<string name="buffer">Buffer:</string>
<string name="packingSave">Packing guardado</string>
<string name="previousCollected">Previa recogida</string>
@ -624,9 +624,11 @@
<string name="sin_internet">NO INTERNET</string>
<string name="deliveryApp">Assurez-vous que l\'application de livraison est installée</string>
<string name="phones">Téléphone</string>
<string name="phone">Téléphone</string>
<string name="km">Kilomètres</string>
<string name="hours">Heures</string>
<string name="km_init">Kilométrage de départ</string>
<string name="comercial">Comercial</string>
<string name="km_end">Kilométrage de fin</string>
<string name="hour_start">Heure de départ</string>
<string name="hour_end">Heure de fin</string>
@ -643,6 +645,7 @@
<string name="listInventoryEmpty">La lista del inventario está vacía</string>
<string name="sureSign">Êtes-vous sûr de vouloir signer ?</string>
<string name="locationDiferent">La dernière position obtenue est différente de la position actuelle. Voulez-vous modifier la position ou la conserver enregistrée?</string>
<string name="distance">Distance jusqu\'au dernier point où la livraison a été signée en mètres :</string>
<string name="keep">Maintenir</string>
<string name="sign">Signature tickets</string>
<string name="signCmr">Signature CMR</string>
@ -652,5 +655,8 @@
<string name="signed">Voir les tickets signés</string>
<string name="offline">Offline</string>
<string name="no_phones">Téléphone absent</string>
<string name="permissionRequired">Permission de Localisation Requise</string>
<string name="advicePermission">Pour utiliser cette application, vous devez accorder des autorisations de localisation.</string>
<string name="manuallyPermission">Activez manuellement l\'autorisation de localisation.</string>
</resources>

View File

@ -232,7 +232,7 @@
<string name="scanItem">Escanear artículo</string>
<string name="itemNotFound">No hemos podido encontrar el artículo. Revisa el sector.</string>
<string name="errorOperation">Error al realizar la operación</string>
<string name="scanLabelExpedition">Escanea expedición.</string>
<string name="scanLabelExpedition">Escanea expedición</string>
<string name="buffer">Buffer:</string>
<string name="packingSave">Packing guardado</string>
<string name="previousCollected">Previa recogida</string>
@ -624,9 +624,11 @@
<string name="sin_internet">NO INTERNET</string>
<string name="deliveryApp">Certifique-se de ter o aplicativo de entrega instalado</string>
<string name="phones">Telefone</string>
<string name="phone">Telefone</string>
<string name="km">Kilometros</string>
<string name="hours">Horas</string>
<string name="km_init">Km de inicio</string>
<string name="comercial">Comercial</string>
<string name="km_end">Km fim</string>
<string name="hour_start">Hora de inicio</string>
<string name="hour_end">Hora fim</string>
@ -643,6 +645,7 @@
<string name="listInventoryEmpty">La lista del inventario está vacía</string>
<string name="sureSign">Tens certeza que queres assinar?</string>
<string name="locationDiferent">A última posição obtida é diferente à atual. Queres modificar a posição ou manter a registrada?</string>
<string name="distance">Distancia ao último ponto em que se assinou a descarga em metros:</string>
<string name="keep">Manter</string>
<string name="sign">Assinatura tickets</string>
<string name="signCmr">Assinatura CMR</string>
@ -652,5 +655,8 @@
<string name="signed">Ver assinados</string>
<string name="offline">Offline</string>
<string name="no_phones">No telefone</string>
<string name="permissionRequired">Permissão de Localização Necessária</string>
<string name="advicePermission">Para usar este aplicativo, você deve conceder permissões de localização.</string>
<string name="manuallyPermission">Habilite manualmente a permissão de localização.</string>
</resources>

View File

@ -623,9 +623,11 @@
<string name="sin_internet">NO INTERNET</string>
<string name="deliveryApp">Make sure you have the delivery app installed</string>
<string name="phones">Phones</string>
<string name="phone">Phone</string>
<string name="km">Kilometers</string>
<string name="hours">Hours</string>
<string name="km_init">Start km</string>
<string name="comercial">Sales person</string>
<string name="km_end">Finish km</string>
<string name="hour_start">Start hour</string>
<string name="hour_end">Finish hour</string>
@ -651,5 +653,9 @@
<string name="signed">Show signed tickets</string>
<string name="offline">App Offline</string>
<string name="no_phones">Not phones</string>
<string name="distance">Distance to the last point signed:</string>
<string name="permissionRequired">Location Permission Required</string>
<string name="advicePermission">To use this application, you must grant location permissions.</string>
<string name="manuallyPermission">Manually Enable Location Permission.</string>
</resources>