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
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(
val name: String,
val date: Date,
val places: ArrayList<Place>
val places: MutableList<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
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Adapter
import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.RoadTrip
class RoadTripAdapter (val voyages: List<RoadTrip>) : Adapter<RoadTripViewHolder>(){
override fun onBindViewHolder(holder: RoadTripViewHolder, position: Int) {
holder.itemView.findViewById<Button>(R.id.btnGetRoadTripsInfo).text = "test"
}
class RoadTripAdapter (val voyages: List<RoadTrip>) : RecyclerView.Adapter<RoadTripViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RoadTripViewHolder {
return RoadTripViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cell_one_roadtrip, parent, false))
}
override fun getItemCount(): Int {
return voyages.size
@SuppressLint("SetTextI18n")
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
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.recyclerview.widget.RecyclerView.ViewHolder
@ -8,8 +7,6 @@ import uca.baptistearthur.geocaching.R
class RoadTripViewHolder(val cellule: View): ViewHolder(cellule) {
// init{
// cellule.findViewById<Button>(R.id.btnGetRoadTripsInfo). ...
// }
var roadTripAccessButton: Button = cellule.findViewById(R.id.btnGetRoadTripsInfo)
}

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

@ -1,11 +1,20 @@
package uca.baptistearthur.geocaching.ui.fragment
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
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.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
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@ -21,6 +30,11 @@ class RoadTripFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: 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?) {
super.onCreate(savedInstanceState)
@ -30,14 +44,31 @@ class RoadTripFragment : Fragment() {
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_roadtrip, container, false)
@SuppressLint("NotifyDataSetChanged")
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_roadtrip, container, false)
roadTripRecyclerView = view?.findViewById(R.id.recyclerViewRoadTripList)
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 {
/**
* Use this factory method to create a new instance of

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

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragment.RoadTrip"
tools:context=".ui.fragment.RoadTripFragment"
android:orientation="vertical">
<TextView
@ -13,14 +13,31 @@
android:background="@color/main_turquoise_200"
android:textColor="@color/main_turquoise_50"
android:padding="10dp"
android:textSize="20dp"/>
android:textSize="20sp"/>
<Button
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_roadtrip_button"
android:layout_gravity="center"
/>
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
android:id="@+id/buttonAddNewRoadTrip"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="@string/add_roadtrip_button"
android:layout_gravity="center"
android:backgroundTint="@color/main_turquoise_200"
/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewRoadTripList"

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