diff --git a/app/src/main/java/es/verdnatura/presentation/base/BaseActivity.kt b/app/src/main/java/es/verdnatura/presentation/base/BaseActivity.kt index 7d307cd3..273c8305 100644 --- a/app/src/main/java/es/verdnatura/presentation/base/BaseActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/base/BaseActivity.kt @@ -73,12 +73,16 @@ abstract class BaseActivity : 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 : 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, diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt index 94688615..38ac09db 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt @@ -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(), 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(), LocationUpdateCallba } else { uploadImage(MyLocation(locationCurrent.longitude, locationCurrent.latitude)) } - } + }*/ } private fun setEvents() { @@ -208,12 +237,79 @@ class SignedActivity : BaseActivity(), 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, + 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(), 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") } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt index 27529be5..e80d0ec7 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt @@ -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 private lateinit var db: DeliveryDatabase - private lateinit var myListRouteLoaded:List + private lateinit var myListRouteLoaded: List 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()) + } } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt index ec340751..680b1512 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt @@ -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().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 = 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 +) + + diff --git a/app/src/main/res/layout/fragment_tickets.xml b/app/src/main/res/layout/fragment_tickets.xml index bf58f4d9..3010884a 100644 --- a/app/src/main/res/layout/fragment_tickets.xml +++ b/app/src/main/res/layout/fragment_tickets.xml @@ -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"> - diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 3e1fb0f6..c8c10d00 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -232,7 +232,7 @@ Escanea un artículo No hemos podido encontrar el artículo. Revisa el sector. Error al realizar la operación - Escanea expedición. + Escanea expedición Buffer: Packing guardado Previa recogida @@ -624,9 +624,11 @@ NO INTERNET Asegúrate de tener la app de reparto instalada Teléfonos + Teléfono Kilómetros Horas Km de inicio + Comercial Km de fin Hora de inicio Hora de fin @@ -643,6 +645,7 @@ La lista del inventario está vacía ¿Estás seguro de firmar? La última posición \nobtenida es distinta \na la actual. ¿Quieres modificar la posición o mantener la registrada? + Distancia al último punto en que se firmó la descarga en metros: Mantener Firmar tickets Firmar CMR @@ -652,6 +655,9 @@ Ver firmados Offline No hay teléfonos + Permiso de Ubicación Requerido + Para usar esta aplicación, debes otorgar permisos de ubicación. + Habilita manualmente el permiso de ubicación. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 48cbf7dd..c32df606 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -232,7 +232,7 @@ Escanear artículo No hemos podido encontrar el artículo. Revisa el sector. Error al realizar la operación - Escanea expedición. + Escanea expedición Buffer: Packing guardado Previa recogida @@ -624,9 +624,11 @@ NO INTERNET Assurez-vous que l\'application de livraison est installée Téléphone + Téléphone Kilomètres Heures Kilométrage de départ + Comercial Kilométrage de fin Heure de départ Heure de fin @@ -643,6 +645,7 @@ La lista del inventario está vacía Êtes-vous sûr de vouloir signer ? La dernière position obtenue est différente de la position actuelle. Voulez-vous modifier la position ou la conserver enregistrée? + Distance jusqu\'au dernier point où la livraison a été signée en mètres : Maintenir Signature tickets Signature CMR @@ -652,5 +655,8 @@ Voir les tickets signés Offline Téléphone absent + Permission de Localisation Requise + Pour utiliser cette application, vous devez accorder des autorisations de localisation. + Activez manuellement l\'autorisation de localisation. diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 4db0b8bf..1d6b3801 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -232,7 +232,7 @@ Escanear artículo No hemos podido encontrar el artículo. Revisa el sector. Error al realizar la operación - Escanea expedición. + Escanea expedición Buffer: Packing guardado Previa recogida @@ -624,9 +624,11 @@ NO INTERNET Certifique-se de ter o aplicativo de entrega instalado Telefone + Telefone Kilometros Horas Km de inicio + Comercial Km fim Hora de inicio Hora fim @@ -643,6 +645,7 @@ La lista del inventario está vacía Tens certeza que queres assinar? A última posição obtida é diferente à atual. Queres modificar a posição ou manter a registrada? + Distancia ao último ponto em que se assinou a descarga em metros: Manter Assinatura tickets Assinatura CMR @@ -652,5 +655,8 @@ Ver assinados Offline No telefone + Permissão de Localização Necessária + Para usar este aplicativo, você deve conceder permissões de localização. + Habilite manualmente a permissão de localização. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df2a1aa0..c7696b3e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -623,9 +623,11 @@ NO INTERNET Make sure you have the delivery app installed Phones + Phone Kilometers Hours Start km + Sales person Finish km Start hour Finish hour @@ -651,5 +653,9 @@ Show signed tickets App Offline Not phones + Distance to the last point signed: + Location Permission Required + To use this application, you must grant location permissions. + Manually Enable Location Permission.