|
|
|
@ -5,10 +5,13 @@ import android.util.Log
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import android.widget.Button
|
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import androidx.fragment.app.viewModels
|
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
|
|
|
import com.google.gson.JsonParser
|
|
|
|
|
import com.mapbox.mapboxsdk.Mapbox
|
|
|
|
@ -22,6 +25,10 @@ import com.mapbox.mapboxsdk.utils.BitmapUtils
|
|
|
|
|
import fr.iut.mapping.Model.RestaurantData
|
|
|
|
|
import fr.iut.mapping.API.getRestaurants
|
|
|
|
|
import kotlinx.android.synthetic.main.fragment_map_page.*
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
@ -37,6 +44,8 @@ class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
|
private lateinit var locationListener: fr.iut.mapping.LocationListener
|
|
|
|
|
private lateinit var listRestaurant: List<RestaurantData>
|
|
|
|
|
|
|
|
|
|
private lateinit var currentRestaurant: RestaurantData
|
|
|
|
|
|
|
|
|
|
private fun makeStyleUrl(): String {
|
|
|
|
|
return getString(R.string.mapbox_style_url);
|
|
|
|
|
}
|
|
|
|
@ -52,7 +61,7 @@ class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
|
|
|
|
|
|
val button: FloatingActionButton = rootView.findViewById(R.id.findRestaurant)
|
|
|
|
|
button.setOnClickListener {
|
|
|
|
|
findAndPutRestaurant()
|
|
|
|
|
findAndPutRestaurant(rootView)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,7 +77,7 @@ class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
|
return rootView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun findAndPutRestaurant(){
|
|
|
|
|
private fun findAndPutRestaurant(rootView: View){
|
|
|
|
|
if(locationListener.asPermission()){
|
|
|
|
|
Log.e("Debug","${locationListener.latitude},${locationListener.longitude}")
|
|
|
|
|
listRestaurant = emptyList()
|
|
|
|
@ -96,13 +105,38 @@ class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
|
this.symbolManager?.iconIgnorePlacement = true
|
|
|
|
|
|
|
|
|
|
listRestaurant.forEach { restaurant ->
|
|
|
|
|
val description = "${restaurant.adress}\n${restaurant.phone ?: "Pas de numéro disponible"}\n${restaurant.lat},${restaurant.lon}"
|
|
|
|
|
insertIconOnMap(LatLng(restaurant.lat, restaurant.lon), restaurant.name, description)
|
|
|
|
|
restaurant.adress?.let {
|
|
|
|
|
insertIconOnMap(LatLng(restaurant.lat, restaurant.lon), restaurant.name,
|
|
|
|
|
it,restaurant.phone ?: "Pas de numéro disponible")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.symbolManager?.addClickListener {
|
|
|
|
|
titleView.text = it.data?.asJsonObject?.get("title")?.asString
|
|
|
|
|
descriptionView.text = it.data?.asJsonObject?.get("description")?.asString
|
|
|
|
|
val clickedData = it.data?.asJsonObject
|
|
|
|
|
titleView.text = clickedData?.get("title")?.asString
|
|
|
|
|
addressRestaurant.text = clickedData?.get("address")?.asString
|
|
|
|
|
telephoneRestaurant.text = clickedData?.get("phone")?.asString
|
|
|
|
|
GPSRestaurant.text = clickedData?.get("GPS")?.asString
|
|
|
|
|
|
|
|
|
|
val button: Button = rootView.findViewById(R.id.addToFav)
|
|
|
|
|
button.setOnClickListener {
|
|
|
|
|
Log.d("debug button","click")
|
|
|
|
|
Log.d("debug button",clickedData.toString())
|
|
|
|
|
val gps = (clickedData?.get("GPS")?.asString ?: "").split(",")
|
|
|
|
|
val lat = gps[0]
|
|
|
|
|
val lon = gps[1]
|
|
|
|
|
|
|
|
|
|
val name = clickedData?.get("title")?.asString ?: ""
|
|
|
|
|
val address = clickedData?.get("address")?.asString ?: ""
|
|
|
|
|
val phone = clickedData?.get("phone")?.asString ?: ""
|
|
|
|
|
val restaurant = RestaurantData(lat.toDouble(), lon.toDouble(), name,address,phone)
|
|
|
|
|
|
|
|
|
|
viewLifecycleOwner.lifecycleScope.launch {
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
restaurantViewModel.insert(restaurant)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSelectedIcon(it)
|
|
|
|
|
toggleLayout()
|
|
|
|
@ -116,6 +150,10 @@ class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val restaurantViewModel: RestaurantViewModel by viewModels {
|
|
|
|
|
RestaurantViewModelFactory((requireActivity().application as MappingApplication).repository)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun toggleLayout() {
|
|
|
|
|
mapLayout?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 2f)
|
|
|
|
|
descriptionLayout?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
|
|
|
|
@ -138,11 +176,16 @@ class FirstFragment: Fragment(R.layout.fragment_map_page) {
|
|
|
|
|
this.lastSymbol = symbol
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun insertIconOnMap(point: LatLng, title: String, description: String) {
|
|
|
|
|
private fun insertIconOnMap(point: LatLng, title: String, address: String,phone: String) {
|
|
|
|
|
val lat = point.latitude
|
|
|
|
|
val lon = point.longitude
|
|
|
|
|
|
|
|
|
|
val jsonData = """
|
|
|
|
|
{
|
|
|
|
|
"title" : "$title",
|
|
|
|
|
"description" : "$description"
|
|
|
|
|
"address" : "$address",
|
|
|
|
|
"phone" : "$phone",
|
|
|
|
|
"GPS": "$lat,$lon"
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|