|
|
@ -1,11 +1,11 @@
|
|
|
|
package uca.baptistearthur.geocaching.ui.overlay
|
|
|
|
package uca.baptistearthur.geocaching.ui.overlay
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.AlertDialog
|
|
|
|
import android.app.AlertDialog
|
|
|
|
import android.content.Context
|
|
|
|
|
|
|
|
import android.graphics.Canvas
|
|
|
|
import android.graphics.Canvas
|
|
|
|
import android.graphics.Color
|
|
|
|
import android.graphics.Color
|
|
|
|
import android.graphics.Paint
|
|
|
|
import android.graphics.Paint
|
|
|
|
import android.graphics.RectF
|
|
|
|
import android.graphics.RectF
|
|
|
|
|
|
|
|
import android.provider.Settings.System.getString
|
|
|
|
import android.text.InputFilter
|
|
|
|
import android.text.InputFilter
|
|
|
|
import android.util.Log
|
|
|
|
import android.util.Log
|
|
|
|
import android.view.MotionEvent
|
|
|
|
import android.view.MotionEvent
|
|
|
@ -15,18 +15,17 @@ import androidx.core.content.ContextCompat
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import org.osmdroid.util.GeoPoint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.osmdroid.views.MapView
|
|
|
|
import org.osmdroid.views.MapView
|
|
|
|
import org.osmdroid.views.overlay.Overlay
|
|
|
|
import org.osmdroid.views.overlay.Overlay
|
|
|
|
|
|
|
|
import org.osmdroid.views.overlay.Polyline
|
|
|
|
import uca.baptistearthur.geocaching.R
|
|
|
|
import uca.baptistearthur.geocaching.R
|
|
|
|
import uca.baptistearthur.geocaching.model.Address
|
|
|
|
|
|
|
|
import uca.baptistearthur.geocaching.model.Place
|
|
|
|
import uca.baptistearthur.geocaching.model.Place
|
|
|
|
import uca.baptistearthur.geocaching.model.RoadTripEntity
|
|
|
|
import uca.baptistearthur.geocaching.model.RoadTripEntity
|
|
|
|
import java.util.*
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NewRoadtripOverlay(val points: Collection<PlaceMarker>) : Overlay() {
|
|
|
|
class NewRoadtripOverlay(val points: MutableCollection<PlaceMarker>) : Overlay() {
|
|
|
|
|
|
|
|
|
|
|
|
private var circleRectF=RectF()
|
|
|
|
private var circleRectF=RectF()
|
|
|
|
|
|
|
|
|
|
|
@ -62,7 +61,7 @@ class NewRoadtripOverlay(val points: Collection<PlaceMarker>) : Overlay() {
|
|
|
|
override fun onSingleTapConfirmed(e: MotionEvent?, mapView: MapView?) =
|
|
|
|
override fun onSingleTapConfirmed(e: MotionEvent?, mapView: MapView?) =
|
|
|
|
if (e != null && circleRectF.contains(e.x, e.y)) {
|
|
|
|
if (e != null && circleRectF.contains(e.x, e.y)) {
|
|
|
|
mapView?.let{
|
|
|
|
mapView?.let{
|
|
|
|
createDialog(it.context)
|
|
|
|
createDialog(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.d("GeoRoad", "CONFIRM : "+points.size)
|
|
|
|
Log.d("GeoRoad", "CONFIRM : "+points.size)
|
|
|
|
true
|
|
|
|
true
|
|
|
@ -70,7 +69,12 @@ class NewRoadtripOverlay(val points: Collection<PlaceMarker>) : Overlay() {
|
|
|
|
false
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun createDialog(context: Context){
|
|
|
|
private fun clearMap(mapView: MapView){
|
|
|
|
|
|
|
|
mapView.overlays.removeAll { it is PlaceMarker || it is Polyline || it is NewRoadtripOverlay }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun createDialog(mapView: MapView){
|
|
|
|
|
|
|
|
val context = mapView.context
|
|
|
|
val input = EditText(context)
|
|
|
|
val input = EditText(context)
|
|
|
|
input.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(50))
|
|
|
|
input.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(50))
|
|
|
|
|
|
|
|
|
|
|
@ -86,14 +90,21 @@ class NewRoadtripOverlay(val points: Collection<PlaceMarker>) : Overlay() {
|
|
|
|
it.initAddress()
|
|
|
|
it.initAddress()
|
|
|
|
Log.d("GeoMap", it.address.displayName)
|
|
|
|
Log.d("GeoMap", it.address.displayName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val newRoadTrip = RoadTripEntity(
|
|
|
|
|
|
|
|
id = 0, // auto-generated ID
|
|
|
|
|
|
|
|
name = input.text.toString(),
|
|
|
|
|
|
|
|
date = Date(),
|
|
|
|
|
|
|
|
places = places
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: Persister le RoadTrip
|
|
|
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
|
|
|
context,
|
|
|
|
|
|
|
|
R.string.roadtripAdded,
|
|
|
|
|
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
|
|
|
|
).show()
|
|
|
|
|
|
|
|
points.clear()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val newRoadTrip = RoadTripEntity(
|
|
|
|
clearMap(mapView)
|
|
|
|
id = 0, // auto-generated ID
|
|
|
|
|
|
|
|
name = input.text.toString(),
|
|
|
|
|
|
|
|
date = Date(),
|
|
|
|
|
|
|
|
places = places
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: Persister le RoadTrip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Toast.makeText(
|
|
|
|
Toast.makeText(
|
|
|
|