Displaying places, name & data in roadtrip_detail

pull/8/head
Baptiste BONNEAU 2 years ago
parent c2c3ff158c
commit 7ba17005aa

@ -1,10 +1,14 @@
package uca.baptistearthur.geocaching.converters
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.room.TypeConverter
import java.util.Date
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import uca.baptistearthur.geocaching.model.Place
import uca.baptistearthur.geocaching.model.RoadTripEntity
import java.time.format.DateTimeFormatter
import java.util.*
class Converters {
@TypeConverter
@ -28,5 +32,13 @@ class Converters {
return Gson().fromJson(value, listType)
}
@TypeConverter
fun toRoadTripEntity(value: String?): RoadTripEntity {
return Gson().fromJson(value, RoadTripEntity::class.java)
}
}
fun Date.toFrenchFormat(): String {
return "${this.day}/${this.month}/${this.year} - ${this.hours}h${this.minutes}"
}

@ -17,7 +17,7 @@ class Stub {
2,
"Italie",
Date(),
listOf(Place(48.866667, 2.333333), Place(48.866667, 2.333333)).toMutableList()
listOf(Place(48.866667, 2.34533), Place(98.866667, 2.333333)).toMutableList()
),
RoadTripEntity(
3,

@ -3,6 +3,7 @@ package uca.baptistearthur.geocaching.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.google.gson.Gson
import java.util.Date
@Entity(tableName = "Roadtrip")
@ -15,5 +16,6 @@ class RoadTripEntity(
fun addPlaceToRoadTripList(place: Place) = places.add(place)
fun addPlaceToRoadTripList(latitude: Double, longitude: Double) = places.add(Place(latitude, longitude))
fun toJSON(): String = Gson().toJson(this)
}

@ -11,12 +11,12 @@ import uca.baptistearthur.geocaching.model.Place
class PlacesAdapter (val places: List<Place>) : RecyclerView.Adapter<PlacesViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlacesViewHolder {
return PlacesViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cell_one_roadtrip, parent, false))
return PlacesViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cell_place, parent, false))
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: PlacesViewHolder, position: Int) {
holder.placeText.text = "> " + places[position].longitude + " - " + places[position].latitude
holder.placeText.text = "" + (position+1) + ") LAT: " + places[position].latitude + " - LONG: " + places[position].longitude
}
override fun getItemCount(): Int = places.size
}

@ -3,9 +3,11 @@ package uca.baptistearthur.geocaching.recyclerview
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.core.os.bundleOf
import androidx.navigation.NavController
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.converters.Converters
import uca.baptistearthur.geocaching.model.RoadTripEntity
@ -17,8 +19,17 @@ class RoadTripViewHolder(val cellule: View, val navController: NavController): V
init{
roadTripAccessButton.setOnClickListener{
Log.d("RoadTripViewHolder", "RoadTripViewHolder clicked: ${clickedRoadTrip?.name}")
navController.navigate(R.id.action_roadTripFragment_to_roadtripDetail)
var clickRoadTripJSON = clickedRoadTrip?.toJSON()
// navController.navigate(R.id.action_roadTripFragment_to_roadtripDetail)
val bundle = bundleOf("roadTrip" to clickRoadTripJSON)
navController.navigate(R.id.action_roadTripFragment_to_roadtripDetail, bundle)
Log.d("RoadTripViewHolder", "Data sent: ${clickedRoadTrip?.name}")
}
}
}

@ -1,57 +1,43 @@
package uca.baptistearthur.geocaching.ui.fragment
import android.content.Context
import android.content.pm.PackageManager
import android.location.LocationManager
import android.annotation.SuppressLint
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import org.osmdroid.config.Configuration
import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.ScaleBarOverlay
import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.location.Location
import android.location.LocationListener
import android.util.Log
import android.widget.ProgressBar
import androidx.activity.result.contract.ActivityResultContracts
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.osmdroid.bonuspack.routing.OSRMRoadManager
import org.osmdroid.bonuspack.routing.RoadManager
import org.osmdroid.config.IConfigurationProvider
import org.osmdroid.library.BuildConfig
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.tileprovider.util.StorageUtils.getStorage
import org.osmdroid.views.overlay.compass.CompassOverlay
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.converters.Converters
import uca.baptistearthur.geocaching.converters.toFrenchFormat
import uca.baptistearthur.geocaching.recyclerview.PlacesAdapter
import uca.baptistearthur.geocaching.ui.overlay.AddMarkerOverlay
import uca.baptistearthur.geocaching.ui.overlay.RecenterOverlay
import java.time.format.DateTimeFormatter
import java.util.*
class RoadtripDetail : Fragment() {
private var placesRecyclerView : RecyclerView? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Log.d("GeoMap", "MAP ON CREATE VIEW")
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.roadtrip_detail, container, false)
// val roadTrip = // récupérer le roadtrip cliqué
// placesRecyclerView = view?.findViewById(R.id.recyclerViewPlacesList)
// placesRecyclerView?.adapter = PlacesAdapter(roadTrip.places)
// placesRecyclerView?.layoutManager = LinearLayoutManager(context)
return view
}
var roadTripJSON = arguments?.getString("roadTrip")
val roadTrip = Converters().toRoadTripEntity(roadTripJSON)
placesRecyclerView = view?.findViewById(R.id.recyclerViewPlacesList)
placesRecyclerView?.adapter = PlacesAdapter(roadTrip.places)
placesRecyclerView?.layoutManager = LinearLayoutManager(context)
view?.findViewById<TextView>(R.id.roadTripDetailTitle)?.text = roadTrip.name
view?.findViewById<TextView>(R.id.roadTripDetailDate)?.text = roadTrip.date.toFrenchFormat()
return view
}
}

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
app:defaultNavHost="true"
app:navGraph="@navigation/navgraph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/main_turquoise_700"
app:menu="@menu/bottom_tabs" />
</LinearLayout>

@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_border"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp">

@ -16,7 +16,9 @@
android:textColor="@color/main_turquoise_50"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:textSize="20sp"/>
android:textSize="20sp"
android:paddingStart="10dp"
tools:ignore="RtlSymmetry" />
<TextView
android:id="@+id/roadTripDetailDate"

Loading…
Cancel
Save