merge & displaying address informations on detail

master
Baptiiiiste 2 years ago
parent 9b9c71474f
commit 4942de0bd5

@ -12,6 +12,7 @@
tools:ignore="ScopedStorage" /> tools:ignore="ScopedStorage" />
<application <application
android:name=".application.RTApplication"
android:allowBackup="true" android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules" android:fullBackupContent="@xml/backup_rules"
@ -20,6 +21,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Geocaching" android:theme="@style/Theme.Geocaching"
android:enableOnBackInvokedCallback="true"
tools:targetApi="31"> tools:targetApi="31">
<activity <activity
android:name=".ui.activity.MainWindow" android:name=".ui.activity.MainWindow"

@ -1,24 +1,10 @@
package uca.baptistearthur.geocaching.application package uca.baptistearthur.geocaching.application
import android.app.Application import android.app.Application
import uca.baptistearthur.geocaching.data.Database import uca.baptistearthur.geocaching.data.BDD
class RTApplication: Application() { class RTApplication: Application() {
// val db: Database by lazy { val db: BDD by lazy { BDD.getInstance(this) }
// Database.getInstance(this)
// }
//
// lateinit var db: Database
//
// override fun onCreate() {
// super.onCreate()
//
// // Initialiser la propriété db ici
// db = Database.getInstance(this) as Database
// }
} }

@ -43,5 +43,10 @@ class Converters {
} }
fun Date.toFrenchFormat(): String { fun Date.toFrenchFormat(): String {
return "${this.day}/${this.month}/${this.year} - ${this.hours}h${this.minutes}" val day: String = if(this.date < 10) "0${this.date}" else "${this.date}"
} val month: String = if(this.month < 10) "0${this.month}" else "${this.month}"
val year = "${this.year + 1900}"
val hours: String = if(this.hours < 10) "0${this.hours}" else "${this.hours}"
val minutes: String = if(this.minutes < 10) "0${this.minutes}" else "${this.minutes}"
return "$day/$month/$year - ${hours}h$minutes"}

@ -6,20 +6,22 @@ import androidx.room.RoomDatabase
import androidx.room.TypeConverters import androidx.room.TypeConverters
import uca.baptistearthur.geocaching.converters.Converters import uca.baptistearthur.geocaching.converters.Converters
import uca.baptistearthur.geocaching.model.RoadTripEntity import uca.baptistearthur.geocaching.model.RoadTripEntity
import androidx.room.Database
@androidx.room.Database(entities = arrayOf(RoadTripEntity::class), version=1) @Database(entities = arrayOf(RoadTripEntity::class), version=1, exportSchema = false)
@TypeConverters(Converters::class) @TypeConverters(Converters::class)
abstract class Database : RoomDatabase(){ abstract class BDD : RoomDatabase(){
abstract fun roadTripDAO(): RoadTripDAO abstract fun roadTripDAO(): RoadTripDAO
companion object{ companion object{
private var INSTANCE: Database ?= null private var INSTANCE: BDD ?= null
fun getInstance(context: Context) = fun getInstance(context: Context) =
INSTANCE ?: synchronized(this){ INSTANCE ?: synchronized(this){
val db = Room.databaseBuilder(context, Database::class.java, "roadTripDB").build() val db = Room.databaseBuilder(context, BDD::class.java, "roadTripDB").build()
INSTANCE = db INSTANCE = db
INSTANCE!!
} }
} }

@ -6,9 +6,10 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import org.osmdroid.util.GeoPoint import org.osmdroid.util.GeoPoint
import uca.baptistearthur.geocaching.R import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.Place
class PlacesAdapter (val places: List<GeoPoint>) : RecyclerView.Adapter<PlacesViewHolder>(){ class PlacesAdapter (val places: List<Place>) : RecyclerView.Adapter<PlacesViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlacesViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlacesViewHolder {
return PlacesViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cell_place, parent, false)) return PlacesViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cell_place, parent, false))
@ -16,7 +17,9 @@ class PlacesAdapter (val places: List<GeoPoint>) : RecyclerView.Adapter<PlacesVi
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: PlacesViewHolder, position: Int) { override fun onBindViewHolder(holder: PlacesViewHolder, position: Int) {
holder.placeText.text = "" + (position+1) + ") LAT: " + places[position].latitude + " - LONG: " + places[position].longitude holder.placeAddress.text = places[position].address.displayName
holder.placeCoordinates.text = "(${places[position].longitude}, ${places[position].latitude}), ${places[position].address.country}"
} }
override fun getItemCount(): Int = places.size override fun getItemCount(): Int = places.size
} }

@ -8,7 +8,7 @@ import uca.baptistearthur.geocaching.R
class PlacesViewHolder(val cellule: View): ViewHolder(cellule) { class PlacesViewHolder(val cellule: View): ViewHolder(cellule) {
var placeDeleteButton: Button = cellule.findViewById(R.id.btnDeletePlace) var placeAddress: TextView = cellule.findViewById(R.id.txtPlaceAddress)
var placeText: TextView = cellule.findViewById(R.id.txtPlaceName) var placeCoordinates: TextView = cellule.findViewById(R.id.txtPlaceCoordinates)
} }

@ -18,8 +18,13 @@ import uca.baptistearthur.geocaching.recyclerview.RoadTripAdapter
import java.util.* import java.util.*
class RoadTripFragment : Fragment() { class RoadTripFragment : Fragment() {
private var model = Stub().load()
private var roadTripRecyclerView : RecyclerView? = null private var roadTripRecyclerView : RecyclerView? = null
private var model = Stub().load()
// private val roadTripViewModel: RoadTripViewModel by viewModels<RoadTripViewModel> {
// RoadTripViewModelFactory((MainWindow().application as RTApplication).db.roadTripDAO()) // MainWindow().application ????? bof bof
// }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

@ -1,7 +1,7 @@
package uca.baptistearthur.geocaching.viewModels package uca.baptistearthur.geocaching.viewModels
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData //import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import uca.baptistearthur.geocaching.data.RoadTripDAO import uca.baptistearthur.geocaching.data.RoadTripDAO
@ -9,9 +9,9 @@ import uca.baptistearthur.geocaching.model.RoadTripEntity
class RoadTripViewModel(val dao: RoadTripDAO): ViewModel() { class RoadTripViewModel(val dao: RoadTripDAO): ViewModel() {
fun getRoadTripById(id: Int) = dao.getRoadTripById(id).asLiveData() fun getRoadTripById(id: Int) = dao.getRoadTripById(id)//.asLiveData()
fun getAllRoadTrips() = dao.getAllRoadTrips().asLiveData() fun getAllRoadTrips() = dao.getAllRoadTrips()//.asLiveData()
fun insertRoadTrip(r: RoadTripEntity){ fun insertRoadTrip(r: RoadTripEntity){
viewModelScope.launch { viewModelScope.launch {

@ -0,0 +1,20 @@
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/gray" >
</solid>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" >
</padding>
<corners
android:radius="11dp" >
</corners>
</shape>

@ -4,26 +4,46 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"> android:layout_marginLeft="10dp"
android:layout_margin="5dp"
android:background="@drawable/corner_radius"
>
<TextView
android:id="@+id/txtPlaceName" <ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="1) LAT: 49.264562 - LONG: 48.5485248" android:layout_marginRight="10dp"
android:textSize="17sp" android:layout_marginLeft="10dp"
android:layout_weight="1" android:layout_margin="10dp"
android:layout_gravity="center_vertical" android:src="@drawable/center" />
android:textColor="@color/main_turquoise_500"
/>
<LinearLayout
<Button android:layout_width="match_parent"
android:id="@+id/btnDeletePlace" android:layout_height="match_parent"
android:layout_width="50dp" android:orientation="vertical"
android:layout_height="wrap_content" >
android:layout_gravity="center"
android:text="X" <TextView
android:backgroundTint="@color/main_turquoise_200" android:id="@+id/txtPlaceAddress"
/> android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="17dp"
android:textColor="@color/black"
/>
<TextView
android:id="@+id/txtPlaceCoordinates"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="13dp"
/>
</LinearLayout>
</LinearLayout> </LinearLayout>

@ -39,7 +39,9 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:layout_weight="1" /> android:layout_weight="1"
android:background="@drawable/corner_radius"
android:layout_margin="5dp"/>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"

@ -10,6 +10,7 @@
<color name="green">#FF3D7D3C</color> <color name="green">#FF3D7D3C</color>
<color name="green_variant">#FF659964</color> <color name="green_variant">#FF659964</color>
<color name="gray">#ececec</color>
<color name="main_turquoise_700">#2f3e46</color> <color name="main_turquoise_700">#2f3e46</color>
<color name="main_turquoise_500">#354f52</color> <color name="main_turquoise_500">#354f52</color>
<color name="main_turquoise_200">#52796f</color> <color name="main_turquoise_200">#52796f</color>

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
id 'com.android.application' version '7.3.0' apply false id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.3.0' apply false id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.20' apply false id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
// id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false // id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
} }
Loading…
Cancel
Save