diff --git a/app/src/main/java/uca/baptistearthur/geocaching/data/Stub.kt b/app/src/main/java/uca/baptistearthur/geocaching/data/Stub.kt new file mode 100644 index 0000000..0ddbabe --- /dev/null +++ b/app/src/main/java/uca/baptistearthur/geocaching/data/Stub.kt @@ -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 { + 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() + } + +} \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/model/Place.kt b/app/src/main/java/uca/baptistearthur/geocaching/model/Place.kt index 6904b27..9a49d28 100644 --- a/app/src/main/java/uca/baptistearthur/geocaching/model/Place.kt +++ b/app/src/main/java/uca/baptistearthur/geocaching/model/Place.kt @@ -1,6 +1,6 @@ package uca.baptistearthur.geocaching.model data class Place( - val latitude : Long, - val longitude : Long + val latitude: Double, + val longitude: Double ) diff --git a/app/src/main/java/uca/baptistearthur/geocaching/model/RoadTrip.kt b/app/src/main/java/uca/baptistearthur/geocaching/model/RoadTrip.kt index cbabb74..4352b37 100644 --- a/app/src/main/java/uca/baptistearthur/geocaching/model/RoadTrip.kt +++ b/app/src/main/java/uca/baptistearthur/geocaching/model/RoadTrip.kt @@ -5,10 +5,10 @@ import java.util.Date class RoadTrip( val name: String, val date: Date, - val places: ArrayList + val places: MutableList ){ 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)) } \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/model/Stub.kt b/app/src/main/java/uca/baptistearthur/geocaching/model/Stub.kt deleted file mode 100644 index f2c610e..0000000 --- a/app/src/main/java/uca/baptistearthur/geocaching/model/Stub.kt +++ /dev/null @@ -1,6 +0,0 @@ -package uca.baptistearthur.geocaching.model - -class Stub { - - -} \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/PlacesAdapter.kt b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/PlacesAdapter.kt new file mode 100644 index 0000000..3e3b60f --- /dev/null +++ b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/PlacesAdapter.kt @@ -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) : RecyclerView.Adapter(){ + + 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 +} \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/PlacesViewHolder.kt b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/PlacesViewHolder.kt new file mode 100644 index 0000000..745cdb2 --- /dev/null +++ b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/PlacesViewHolder.kt @@ -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) + +} \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/RoadTripAdapter.kt b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/RoadTripAdapter.kt new file mode 100644 index 0000000..17796f6 --- /dev/null +++ b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/RoadTripAdapter.kt @@ -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) : RecyclerView.Adapter(){ + + 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 +} \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/RoadTripViewHolder.kt b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/RoadTripViewHolder.kt new file mode 100644 index 0000000..a6bd2b8 --- /dev/null +++ b/app/src/main/java/uca/baptistearthur/geocaching/recyclerview/RoadTripViewHolder.kt @@ -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) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/services/FragmentService.kt b/app/src/main/java/uca/baptistearthur/geocaching/services/FragmentService.kt new file mode 100644 index 0000000..37359f6 --- /dev/null +++ b/app/src/main/java/uca/baptistearthur/geocaching/services/FragmentService.kt @@ -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() + } + +} \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/ui/activity/MainWindow.kt b/app/src/main/java/uca/baptistearthur/geocaching/ui/activity/MainWindow.kt index d68ce9c..b38938c 100644 --- a/app/src/main/java/uca/baptistearthur/geocaching/ui/activity/MainWindow.kt +++ b/app/src/main/java/uca/baptistearthur/geocaching/ui/activity/MainWindow.kt @@ -1,14 +1,17 @@ package uca.baptistearthur.geocaching.ui.activity +import android.annotation.SuppressLint import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.Fragment import com.google.android.material.bottomnavigation.BottomNavigationView import uca.baptistearthur.geocaching.R +import uca.baptistearthur.geocaching.services.FragmentService + import uca.baptistearthur.geocaching.ui.fragment.Map -import uca.baptistearthur.geocaching.ui.fragment.RoadTrip +import uca.baptistearthur.geocaching.ui.fragment.RoadTripFragment class MainWindow: AppCompatActivity() { + @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { val map = Map() @@ -16,27 +19,25 @@ class MainWindow: AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.main_window) - loadFragment(Map()) + val fragmentService = FragmentService() + +// Bottom menu + fragmentService.loadFragment(Map(), supportFragmentManager) val navigation = findViewById(R.id.bottom_navigation) navigation.selectedItemId= R.id.map navigation.setOnItemSelectedListener { when (it.itemId) { R.id.map -> { - loadFragment(map) + fragmentService.loadFragment(map, supportFragmentManager) true } R.id.roadTrip -> { - loadFragment(RoadTrip()) + fragmentService.loadFragment(RoadTripFragment(), supportFragmentManager) true } else -> false } } } - private fun loadFragment(fragment: Fragment){ - val transaction = supportFragmentManager.beginTransaction() - transaction.replace(R.id.fragment_container, fragment) - transaction.commit() - } } \ No newline at end of file diff --git a/app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/RoadTrip.kt b/app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/DetailledRoadTripFragment.kt similarity index 63% rename from app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/RoadTrip.kt rename to app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/DetailledRoadTripFragment.kt index 4dce937..e10fa9d 100644 --- a/app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/RoadTrip.kt +++ b/app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/DetailledRoadTripFragment.kt @@ -1,11 +1,16 @@ package uca.baptistearthur.geocaching.ui.fragment import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View 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.model.RoadTrip +import uca.baptistearthur.geocaching.recyclerview.PlacesAdapter +import uca.baptistearthur.geocaching.recyclerview.RoadTripAdapter // TODO: Rename parameter arguments, choose names that match // 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 * create an instance of this fragment. */ -class RoadTrip : Fragment() { +class DetailledRoadTripFragment(val roadTrip: RoadTrip): Fragment() { // TODO: Rename and change types of parameters private var param1: String? = null private var param2: String? = null + private var placesRecyclerView : RecyclerView? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -30,12 +36,14 @@ class RoadTrip : 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) + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val view = inflater.inflate(R.layout.fragment_detailled_roadtrip, container, false) + + placesRecyclerView = view?.findViewById(R.id.recyclerViewPlacesList) + placesRecyclerView?.adapter = PlacesAdapter(roadTrip.places) + placesRecyclerView?.layoutManager = LinearLayoutManager(context) + + return view } companion object { @@ -50,7 +58,7 @@ class RoadTrip : Fragment() { // TODO: Rename and change types and number of parameters @JvmStatic fun newInstance(param1: String, param2: String) = - RoadTrip().apply { + RoadTripFragment().apply { arguments = Bundle().apply { putString(ARG_PARAM1, param1) putString(ARG_PARAM2, param2) diff --git a/app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/RoadTripFragment.kt b/app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/RoadTripFragment.kt new file mode 100644 index 0000000..a3870a6 --- /dev/null +++ b/app/src/main/java/uca/baptistearthur/geocaching/ui/fragment/RoadTripFragment.kt @@ -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) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/bin.xml b/app/src/main/res/drawable/bin.xml new file mode 100644 index 0000000..10025ad --- /dev/null +++ b/app/src/main/res/drawable/bin.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/drawable/right_arrow.xml b/app/src/main/res/drawable/right_arrow.xml new file mode 100644 index 0000000..72736fb --- /dev/null +++ b/app/src/main/res/drawable/right_arrow.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/cell_one_roadtrip.xml b/app/src/main/res/layout/cell_one_roadtrip.xml new file mode 100644 index 0000000..a29b808 --- /dev/null +++ b/app/src/main/res/layout/cell_one_roadtrip.xml @@ -0,0 +1,15 @@ + +