Moving loadFragment in a service, Creating the recyclerView for a roadtrip's places, Starting to display this recyclerView in RoadTripRecyclerView by getting the roadTrip by name
parent
02fd486bc1
commit
fe58ff22da
@ -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)
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,27 @@
|
|||||||
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
|
||||||
import uca.baptistearthur.geocaching.R
|
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) {
|
class RoadTripViewHolder(val cellule: View): ViewHolder(cellule) {
|
||||||
|
|
||||||
var roadTripAccessButton: Button = cellule.findViewById(R.id.btnGetRoadTripsInfo)
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package uca.baptistearthur.geocaching.ui.fragment
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
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
|
||||||
|
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 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)
|
||||||
|
arguments?.let {
|
||||||
|
param1 = it.getString(ARG_PARAM1)
|
||||||
|
param2 = it.getString(ARG_PARAM2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
/**
|
||||||
|
* 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,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>
|
Loading…
Reference in new issue