recycler view & adapter & viewholder + pb on stub & recyclerview display

pull/6/head
Baptiste BONNEAU 2 years ago
parent f91a64bc15
commit f2a38eb339

@ -4,12 +4,21 @@ import java.util.Date
class Stub {
fun load(): List<RoadTrip> {
return listOf(
RoadTrip("France", Date(), listOf(Place(48.866667, 2.333333), Place(48.866667, 2.333333)) as ArrayList<Place>),
RoadTrip("Italie", Date(), listOf(Place(52.866667, 4.333333), Place(48.866667, 2.333333)) as ArrayList<Place>),
RoadTrip("Allemagne", Date(), listOf(Place(37.866667, 3.333333)) as ArrayList<Place>),
)
}
// 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
// }
}

@ -0,0 +1,26 @@
package uca.baptistearthur.geocaching.recyclerview
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"
}
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
}
}

@ -0,0 +1,15 @@
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
class RoadTripViewHolder(val cellule: View): ViewHolder(cellule) {
// init{
// cellule.findViewById<Button>(R.id.btnGetRoadTripsInfo). ...
// }
}

@ -1,15 +1,22 @@
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 androidx.fragment.app.commit
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.recyclerview.RoadTripAdapter
import uca.baptistearthur.geocaching.ui.fragment.Map
import uca.baptistearthur.geocaching.ui.fragment.RoadTrip
import uca.baptistearthur.geocaching.ui.fragment.RoadTripFragment
import uca.baptistearthur.geocaching.model.RoadTrip
class MainWindow: AppCompatActivity() {
// private val model: List<RoadTrip> = Stub().load()
override fun onCreate(savedInstanceState: Bundle?) {
val map = Map()
@ -28,21 +35,21 @@ class MainWindow: AppCompatActivity() {
true
}
R.id.roadTrip -> {
loadFragment(RoadTrip())
loadFragment(RoadTripFragment())
true
}
else -> false
}
}
}
// Map
// code here
// Voyages
// code here
// 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)

@ -17,7 +17,7 @@ private const val ARG_PARAM2 = "param2"
* Use the [RoadTrip.newInstance] factory method to
* create an instance of this fragment.
*/
class RoadTrip : Fragment() {
class RoadTripFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
@ -50,7 +50,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)

@ -1,33 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btnGetRoadTripsInfo"
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal">
<Button
android:id="@+id/btnGetRoadTripsInfo"
android:layout_width="314dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="@color/white"
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"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="end"
android:src="@drawable/bin"
android:background="@color/white"
android:scaleType="fitCenter"
/>
</LinearLayout>
android:layout_gravity="start"
android:background="@color/white"
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"
/>

Loading…
Cancel
Save