baptiste #6

Merged
baptiste.bonneau merged 6 commits from baptiste into master 2 years ago

@ -0,0 +1,34 @@
package uca.baptistearthur.geocaching.data
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()
}
}

@ -1,6 +1,6 @@
package uca.baptistearthur.geocaching.model package uca.baptistearthur.geocaching.model
data class Place( data class Place(
val latitude : Long, val latitude: Double,
val longitude : Long val longitude: Double
) )

@ -5,10 +5,10 @@ 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)
fun addPlaceToRoadTripList(latitude: Long, longitude: Long) = places.add(Place(latitude, longitude)) fun addPlaceToRoadTripList(latitude: Double, longitude: Double) = places.add(Place(latitude, longitude))
} }

@ -1,6 +0,0 @@
package uca.baptistearthur.geocaching.model
class Stub {
}

@ -0,0 +1,23 @@
package uca.baptistearthur.geocaching.recyclerview
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.Place
import uca.baptistearthur.geocaching.model.RoadTrip
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))
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: PlacesViewHolder, position: Int) {
holder.placeText.text = "> " + places[position].longitude + " - " + places[position].latitude
}
override fun getItemCount(): Int = places.size
}

@ -0,0 +1,14 @@
package uca.baptistearthur.geocaching.recyclerview
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import uca.baptistearthur.geocaching.R
class PlacesViewHolder(val cellule: View): ViewHolder(cellule) {
var placeDeleteButton: Button = cellule.findViewById(R.id.btnDeletePlace)
var placeText: TextView = cellule.findViewById(R.id.txtPlaceName)
}

@ -0,0 +1,22 @@
package uca.baptistearthur.geocaching.recyclerview
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.RoadTrip
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))
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: RoadTripViewHolder, position: Int) {
holder.roadTripAccessButton.text = "> " + voyages[position].name
}
override fun getItemCount(): Int = voyages.size
}

@ -0,0 +1,27 @@
package uca.baptistearthur.geocaching.recyclerview
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.RoadTrip
import uca.baptistearthur.geocaching.services.FragmentService
import uca.baptistearthur.geocaching.ui.activity.MainWindow
import uca.baptistearthur.geocaching.ui.fragment.DetailledRoadTripFragment
class RoadTripViewHolder(val cellule: View): ViewHolder(cellule) {
var roadTripAccessButton: Button = cellule.findViewById(R.id.btnGetRoadTripsInfo)
init{
roadTripAccessButton.setOnClickListener{
val roadTripName = roadTripAccessButton.text.substring(3)
Log.d("RoadTripViewHolder", "RoadTripViewHolder clicked: ${roadTripName}")
// val roadTrip: RoadTrip = Find roadtrip by name here
// FragmentService().loadFragment(DetailledRoadTripFragment(roadTrip), (cellule.context as MainWindow).supportFragmentManager)
}
}
}

@ -0,0 +1,16 @@
package uca.baptistearthur.geocaching.services
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.ui.fragment.DetailledRoadTripFragment
class FragmentService {
fun loadFragment(fragment: Fragment, supportFragmentManager: FragmentManager){
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container, fragment)
transaction.commit()
}
}

@ -1,14 +1,17 @@
package uca.baptistearthur.geocaching.ui.activity package uca.baptistearthur.geocaching.ui.activity
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
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.services.FragmentService
import uca.baptistearthur.geocaching.ui.fragment.Map import uca.baptistearthur.geocaching.ui.fragment.Map
import uca.baptistearthur.geocaching.ui.fragment.RoadTrip import uca.baptistearthur.geocaching.ui.fragment.RoadTripFragment
class MainWindow: AppCompatActivity() { class MainWindow: AppCompatActivity() {
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
val map = Map() val map = Map()
@ -16,27 +19,25 @@ class MainWindow: AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.main_window) setContentView(R.layout.main_window)
loadFragment(Map()) val fragmentService = FragmentService()
// Bottom menu
fragmentService.loadFragment(Map(), supportFragmentManager)
val navigation = findViewById<BottomNavigationView>(R.id.bottom_navigation) val navigation = findViewById<BottomNavigationView>(R.id.bottom_navigation)
navigation.selectedItemId= R.id.map navigation.selectedItemId= R.id.map
navigation.setOnItemSelectedListener { navigation.setOnItemSelectedListener {
when (it.itemId) { when (it.itemId) {
R.id.map -> { R.id.map -> {
loadFragment(map) fragmentService.loadFragment(map, supportFragmentManager)
true true
} }
R.id.roadTrip -> { R.id.roadTrip -> {
loadFragment(RoadTrip()) fragmentService.loadFragment(RoadTripFragment(), supportFragmentManager)
true true
} }
else -> false else -> false
} }
} }
} }
private fun loadFragment(fragment: Fragment){
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container, fragment)
transaction.commit()
}
} }

@ -1,11 +1,16 @@
package uca.baptistearthur.geocaching.ui.fragment package uca.baptistearthur.geocaching.ui.fragment
import android.os.Bundle import android.os.Bundle
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 androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import uca.baptistearthur.geocaching.R import uca.baptistearthur.geocaching.R
import uca.baptistearthur.geocaching.model.RoadTrip
import uca.baptistearthur.geocaching.recyclerview.PlacesAdapter
import uca.baptistearthur.geocaching.recyclerview.RoadTripAdapter
// 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
@ -17,10 +22,11 @@ private const val ARG_PARAM2 = "param2"
* Use the [RoadTrip.newInstance] factory method to * Use the [RoadTrip.newInstance] factory method to
* create an instance of this fragment. * create an instance of this fragment.
*/ */
class RoadTrip : Fragment() { class DetailledRoadTripFragment(val roadTrip: RoadTrip): 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 placesRecyclerView : RecyclerView? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -30,12 +36,14 @@ class RoadTrip : Fragment() {
} }
} }
override fun onCreateView( override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
inflater: LayoutInflater, container: ViewGroup?, val view = inflater.inflate(R.layout.fragment_detailled_roadtrip, container, false)
savedInstanceState: Bundle?
): View? { placesRecyclerView = view?.findViewById(R.id.recyclerViewPlacesList)
// Inflate the layout for this fragment placesRecyclerView?.adapter = PlacesAdapter(roadTrip.places)
return inflater.inflate(R.layout.fragment_roadtrip, container, false) placesRecyclerView?.layoutManager = LinearLayoutManager(context)
return view
} }
companion object { companion object {
@ -50,7 +58,7 @@ class RoadTrip : Fragment() {
// TODO: Rename and change types and number of parameters // TODO: Rename and change types and number of parameters
@JvmStatic @JvmStatic
fun newInstance(param1: String, param2: String) = fun newInstance(param1: String, param2: String) =
RoadTrip().apply { RoadTripFragment().apply {
arguments = Bundle().apply { arguments = Bundle().apply {
putString(ARG_PARAM1, param1) putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2) putString(ARG_PARAM2, param2)

@ -0,0 +1,101 @@
package uca.baptistearthur.geocaching.ui.fragment
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
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 uca.baptistearthur.geocaching.services.FragmentService
import uca.baptistearthur.geocaching.ui.activity.MainWindow
import java.util.*
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
/**
* A simple [Fragment] subclass.
* Use the [RoadTrip.newInstance] factory method to
* create an instance of this fragment.
*/
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)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}
}
@SuppressLint("MissingInflatedId")
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 {
addRoadTrip(editTextRoadTripName!!, roadTripRecyclerView!!)
}
return view
}
@SuppressLint("NotifyDataSetChanged")
fun addRoadTrip(editText: EditText, recyclerView: RecyclerView) {
val roadTripName = editText.text.toString().trim()
if(roadTripName.isNotEmpty() && roadTripName.length <= 20){
editText.text?.clear()
val roadTrip = RoadTrip(roadTripName, Date(), mutableListOf())
model.add(roadTrip)
recyclerView.adapter?.notifyDataSetChanged()
}else{
editText.error = "Le nom du voyage doit être compris entre 1 et 20 caractères."
}
}
companion object {
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment List.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
RoadTripFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
}
}

@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="91dp"
android:height="91dp"
android:viewportWidth="91"
android:viewportHeight="91">
<path
android:fillColor="#FF000000"
android:pathData="M67.305,36.442v-8.055c0,-0.939 -0.762,-1.701 -1.7,-1.701H54.342v-5.524c0,-0.938 -0.761,-1.7 -1.699,-1.7h-12.75c-0.939,0 -1.701,0.762 -1.701,1.7v5.524H26.93c-0.939,0 -1.7,0.762 -1.7,1.701v8.055c0,0.938 0.761,1.699 1.7,1.699h0.488v34.021c0,0.938 0.761,1.7 1.699,1.7h29.481c3.595,0 6.52,-2.924 6.52,-6.518V38.142h0.486C66.543,38.142 67.305,37.381 67.305,36.442zM41.592,22.862h9.35v3.824h-9.35V22.862zM61.719,67.345c0,1.719 -1.4,3.117 -3.12,3.117h-27.78v-32.32l30.9,0.002V67.345zM63.904,34.742H28.629v-4.655h11.264h12.75h11.262V34.742z"/>
<path
android:fillColor="#FF000000"
android:pathData="M36.066,44.962h3.4v19.975h-3.4z"/>
<path
android:fillColor="#FF000000"
android:pathData="M44.566,44.962h3.4v19.975h-3.4z"/>
<path
android:fillColor="#FF000000"
android:pathData="M53.066,44.962h3.4v19.975h-3.4z"/>
</vector>

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="800dp"
android:height="800dp"
android:viewportWidth="330"
android:viewportHeight="330">
<path
android:pathData="M250.61,154.39l-150,-150c-5.86,-5.86 -15.35,-5.86 -21.21,0c-5.86,5.86 -5.86,15.35 0,21.21l139.39,139.39L79.39,304.39c-5.86,5.86 -5.86,15.35 0,21.21C82.32,328.54 86.16,330 90,330s7.68,-1.46 10.61,-4.39l150,-150c2.81,-2.81 4.39,-6.63 4.39,-10.61C255,161.02 253.42,157.2 250.61,154.39z"
android:fillColor="#000000"/>
</vector>

@ -0,0 +1,15 @@
<?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"
android:layout_gravity="start"
android:background="@color/white"
android:drawableStart="@drawable/right_arrow"
android:drawableLeft="@drawable/right_arrow"
android:gravity="left"
android:textColor="@color/black"
android:textSize="20sp"
tools:ignore="RtlHardcoded" />

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/txtPlaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="> TMP/ Place Name"
android:textColor="@color/black"
android:padding="5dp"
android:textSize="17sp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" />
<Button
android:id="@+id/btnDeletePlace"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="X"
android:backgroundTint="@color/main_turquoise_200"
/>
</LinearLayout>

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragment.DetailledRoadTripFragment"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TMP/ Roadtrip Name"
android:background="@color/main_turquoise_200"
android:textColor="@color/main_turquoise_50"
android:padding="10dp"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/placesList"
android:textColor="@color/main_turquoise_200"
android:padding="5dp"
android:textSize="17sp"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewPlacesList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<Button
android:id="@+id/btnDeleteRoadTrip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btnDeleteRoadTrip"
android:backgroundTint="@color/main_turquoise_500"
android:layout_margin="10dp"/>
</LinearLayout>

@ -1,14 +1,48 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/roadtrip_title"
android:background="@color/main_turquoise_200"
android:textColor="@color/main_turquoise_50"
android:padding="10dp"
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
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 <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewRoadTripList" android:id="@+id/recyclerViewRoadTripList"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
/> />
</FrameLayout> </LinearLayout>

@ -2,6 +2,12 @@
<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>
<string name="add_roadtrip_button">+</string>
<string name="textaddNewRoadTrip">Entrez le nom du nouveau voyage</string>
<string name="placesList">Vos lieux à visiter:</string>
<string name="btnDeleteRoadTrip">Supprimer le 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