Affichage de la recyclerview, fonction d'ajout d'un voyage

pull/6/head
Baptiiiiste 2 years ago
parent f2a38eb339
commit 02fd486bc1

@ -1,6 +1,34 @@
package uca.baptistearthur.geocaching.data package uca.baptistearthur.geocaching.data
class Stub { import uca.baptistearthur.geocaching.model.Place
import uca.baptistearthur.geocaching.model.RoadTrip
import java.util.Date
class Stub {
fun load(): MutableList<RoadTrip> {
val list = listOf(
RoadTrip(
"France",
Date(),
listOf(Place(49.3, 49.3)).toMutableList()
),
RoadTrip(
"Italie",
Date(),
listOf(Place(48.866667, 2.333333), Place(48.866667, 2.333333)).toMutableList()
),
RoadTrip(
"Danemark",
Date(),
listOf(Place(48.866667, 2.333333), Place(48.866667, 2.333333)).toMutableList()
),
RoadTrip(
"Islande",
Date(),
listOf(Place(48.866667, 2.333333), Place(48.866667, 2.333333), Place(48.866667, 2.333333)).toMutableList()
),
)
return list.toMutableList()
}
} }

@ -5,7 +5,7 @@ import java.util.Date
class RoadTrip( class RoadTrip(
val name: String, val name: String,
val date: Date, val date: Date,
val places: ArrayList<Place> val places: MutableList<Place>
){ ){
fun addPlaceToRoadTripList(place: Place) = places.add(place) fun addPlaceToRoadTripList(place: Place) = places.add(place)

@ -1,24 +0,0 @@
package uca.baptistearthur.geocaching.model
import java.util.Date
class Stub {
// private val list = listOf(
// RoadTrip(
// "France",
// Date(),
// listOf(Place(48.866667, 2.333333), Place(48.866667, 2.333333)) as ArrayList<Place>
// ),
// RoadTrip(
// "Italie",
// Date(),
// listOf(Place(48.866667, 2.333333), Place(48.866667, 2.333333)) as ArrayList<Place>
// ),
// )
// fun load(): List<RoadTrip> {
// return list
// }
}

@ -1,26 +1,22 @@
package uca.baptistearthur.geocaching.recyclerview package uca.baptistearthur.geocaching.recyclerview
import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Adapter
import uca.baptistearthur.geocaching.R import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.RoadTrip import uca.baptistearthur.geocaching.model.RoadTrip
class RoadTripAdapter (val voyages: List<RoadTrip>) : Adapter<RoadTripViewHolder>(){ class RoadTripAdapter (val voyages: List<RoadTrip>) : RecyclerView.Adapter<RoadTripViewHolder>(){
override fun onBindViewHolder(holder: RoadTripViewHolder, position: Int) {
holder.itemView.findViewById<Button>(R.id.btnGetRoadTripsInfo).text = "test"
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RoadTripViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RoadTripViewHolder {
return RoadTripViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cell_one_roadtrip, parent, false)) return RoadTripViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cell_one_roadtrip, parent, false))
} }
override fun getItemCount(): Int { @SuppressLint("SetTextI18n")
return voyages.size override fun onBindViewHolder(holder: RoadTripViewHolder, position: Int) {
holder.roadTripAccessButton.text = "> " + voyages[position].name
} }
override fun getItemCount(): Int = voyages.size
} }

@ -1,6 +1,5 @@
package uca.baptistearthur.geocaching.recyclerview package uca.baptistearthur.geocaching.recyclerview
import android.util.Log
import android.view.View import android.view.View
import android.widget.Button import android.widget.Button
import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.recyclerview.widget.RecyclerView.ViewHolder
@ -8,8 +7,6 @@ import uca.baptistearthur.geocaching.R
class RoadTripViewHolder(val cellule: View): ViewHolder(cellule) { class RoadTripViewHolder(val cellule: View): ViewHolder(cellule) {
// init{ var roadTripAccessButton: Button = cellule.findViewById(R.id.btnGetRoadTripsInfo)
// cellule.findViewById<Button>(R.id.btnGetRoadTripsInfo). ...
// }
} }

@ -2,21 +2,21 @@ package uca.baptistearthur.geocaching.ui.activity
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import uca.baptistearthur.geocaching.R import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.RoadTrip
import uca.baptistearthur.geocaching.model.Stub
import uca.baptistearthur.geocaching.recyclerview.RoadTripAdapter import uca.baptistearthur.geocaching.recyclerview.RoadTripAdapter
import uca.baptistearthur.geocaching.ui.fragment.Map import uca.baptistearthur.geocaching.ui.fragment.Map
import uca.baptistearthur.geocaching.ui.fragment.RoadTripFragment import uca.baptistearthur.geocaching.ui.fragment.RoadTripFragment
import uca.baptistearthur.geocaching.model.RoadTrip
class MainWindow: AppCompatActivity() { class MainWindow: AppCompatActivity() {
// private val model: List<RoadTrip> = Stub().load() @SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
val map = Map() val map = Map()
@ -43,18 +43,10 @@ class MainWindow: AppCompatActivity() {
} }
} }
// RecyclerView voyage
// override fun onResume() {
// super.onResume()
// findViewById<RecyclerView>(R.id.recyclerViewRoadTripList).adapter = RoadTripAdapter(model)
// findViewById<RecyclerView>(R.id.recyclerViewRoadTripList).layoutManager = LinearLayoutManager(this)
// }
private fun loadFragment(fragment: Fragment){ private fun loadFragment(fragment: Fragment){
val transaction = supportFragmentManager.beginTransaction() val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container, fragment) transaction.replace(R.id.fragment_container, fragment)
transaction.commit() transaction.commit()
} }
} }

@ -1,11 +1,20 @@
package uca.baptistearthur.geocaching.ui.fragment package uca.baptistearthur.geocaching.ui.fragment
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import uca.baptistearthur.geocaching.R import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.data.Stub
import uca.baptistearthur.geocaching.model.RoadTrip
import uca.baptistearthur.geocaching.recyclerview.RoadTripAdapter
import java.util.*
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@ -21,6 +30,11 @@ class RoadTripFragment : Fragment() {
// TODO: Rename and change types of parameters // TODO: Rename and change types of parameters
private var param1: String? = null private var param1: String? = null
private var param2: String? = null private var param2: String? = null
private var model = Stub().load()
private var roadTripRecyclerView : RecyclerView? = null
private var editTextRoadTripName: EditText? = null
private var buttonAddNewRoadTrip: Button? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -30,14 +44,31 @@ class RoadTripFragment : Fragment() {
} }
} }
override fun onCreateView( @SuppressLint("NotifyDataSetChanged")
inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
savedInstanceState: Bundle? val view = inflater.inflate(R.layout.fragment_roadtrip, container, false)
): View? {
// Inflate the layout for this fragment roadTripRecyclerView = view?.findViewById(R.id.recyclerViewRoadTripList)
return inflater.inflate(R.layout.fragment_roadtrip, container, false) roadTripRecyclerView?.adapter = RoadTripAdapter(model)
roadTripRecyclerView?.layoutManager = LinearLayoutManager(context)
editTextRoadTripName = view?.findViewById(R.id.editTextRoadTripName)
buttonAddNewRoadTrip = view?.findViewById(R.id.buttonAddNewRoadTrip)
buttonAddNewRoadTrip?.setOnClickListener {
val roadTripName = editTextRoadTripName?.text.toString()
editTextRoadTripName?.text?.clear()
val roadTrip = RoadTrip(roadTripName, Date(), mutableListOf())
model.add(roadTrip)
roadTripRecyclerView?.adapter?.notifyDataSetChanged()
} }
return view
}
companion object { companion object {
/** /**
* Use this factory method to create a new instance of * Use this factory method to create a new instance of

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Button <Button
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/btnGetRoadTripsInfo" android:id="@+id/btnGetRoadTripsInfo"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="45dp" android:layout_height="45dp"
@ -9,7 +10,6 @@
android:drawableStart="@drawable/right_arrow" android:drawableStart="@drawable/right_arrow"
android:drawableLeft="@drawable/right_arrow" android:drawableLeft="@drawable/right_arrow"
android:gravity="left" android:gravity="left"
android:text="@string/app_name"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="20sp" android:textSize="20sp"
/> tools:ignore="RtlHardcoded" />

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.fragment.RoadTrip" tools:context=".ui.fragment.RoadTripFragment"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
@ -13,15 +13,32 @@
android:background="@color/main_turquoise_200" android:background="@color/main_turquoise_200"
android:textColor="@color/main_turquoise_50" android:textColor="@color/main_turquoise_50"
android:padding="10dp" android:padding="10dp"
android:textSize="20dp"/> android:textSize="20sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="@+id/editTextRoadTripName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/textaddNewRoadTrip"
android:layout_weight="1"/>
<Button <Button
android:layout_width="wrap_content" android:id="@+id/buttonAddNewRoadTrip"
android:layout_width="50dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/add_roadtrip_button" android:text="@string/add_roadtrip_button"
android:layout_gravity="center" android:layout_gravity="center"
android:backgroundTint="@color/main_turquoise_200"
/> />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewRoadTripList" android:id="@+id/recyclerViewRoadTripList"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -2,8 +2,10 @@
<string name="app_name">RoadTrip</string> <string name="app_name">RoadTrip</string>
<string name="carte">Carte</string> <string name="carte">Carte</string>
<string name="voyages">Voyages</string> <string name="voyages">Voyages</string>
<string name="roadtrip_title">Mes RoadTrips:</string>v <string name="roadtrip_title">Mes RoadTrips:</string>
<string name="add_roadtrip_button">+ Ajouter un voyage</string>v <string name="add_roadtrip_button">+</string>
<string name="textaddNewRoadTrip">Entrez le nom du nouveau voyage</string>
<!-- TODO: Remove or change this placeholder text --> <!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
</resources> </resources>
Loading…
Cancel
Save