Skip to content

Commit 0fcb046

Browse files
committed
feat: RouteDetailAdapter 추가
1 parent 1f96e62 commit 0fcb046

File tree

6 files changed

+98
-11
lines changed

6 files changed

+98
-11
lines changed

presentation/src/main/java/com/stop/ui/route/RouteFragment.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ class RouteFragment : Fragment() {
5858
* UI가 ViewModel을 직접 호출하면 안 되지만, 테스트를 위해 막차 조회 함수를 호출했습니다.
5959
* 여기서 UI가 ViewModel을 직접 호출하지 않으면서 막차 조회 함수를 호출할 수 있을까요?
6060
*/
61-
itinerary.routes.forEach {
62-
if (it is TransportRoute) {
63-
Log.d("itinerary", it.start.name)
64-
it.lines.forEach { it2 ->
65-
Log.d("itinerary", it2.toString())
66-
}
67-
}
68-
}
69-
Log.d("itinerary", itinerary.toString())
7061
viewModel.tempItinerary = itinerary
7162
viewModel.calculateLastTransportTime(itinerary)
7263
}
@@ -96,7 +87,6 @@ class RouteFragment : Fragment() {
9687
viewModel.lastTimeResponse.observe(viewLifecycleOwner) {
9788
it.getContentIfNotHandled()?.let { response ->
9889
viewModel.tempLastTime = response.toMutableList()
99-
Log.d("itinerary", response.toMutableList().toString())
10090
binding.root.findNavController().navigate(R.id.action_routeFragment_to_routeDetailFragment)
10191
}
10292
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.stop.ui.routedetail
2+
3+
import com.stop.domain.model.route.tmap.custom.Route
4+
5+
interface OnRouteDetailClickListener {
6+
fun clickRouteDetail(route: Route)
7+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.stop.ui.routedetail
2+
3+
import android.view.LayoutInflater
4+
import android.view.ViewGroup
5+
import androidx.recyclerview.widget.DiffUtil
6+
import androidx.recyclerview.widget.ListAdapter
7+
import androidx.recyclerview.widget.RecyclerView
8+
import com.stop.databinding.RoutePathItemBinding
9+
import com.stop.domain.model.route.tmap.custom.Route
10+
11+
class RouteDetailAdapter(
12+
// private val onRouteDetailClickListener: OnRouteDetailClickListener
13+
): ListAdapter<Route, RecyclerView.ViewHolder>(diffUtil) {
14+
class PathViewHolder(
15+
private val binding: RoutePathItemBinding
16+
) : RecyclerView.ViewHolder(binding.root) {
17+
fun bind(route: Route) {
18+
binding.route = route
19+
}
20+
}
21+
22+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
23+
val inflater = LayoutInflater.from(parent.context)
24+
25+
return PathViewHolder(RoutePathItemBinding.inflate(inflater, parent, false))
26+
}
27+
28+
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
29+
(holder as PathViewHolder).bind(getItem(position))
30+
}
31+
32+
companion object {
33+
private val diffUtil = object : DiffUtil.ItemCallback<Route>() {
34+
override fun areItemsTheSame(oldRoute: Route, newRoute: Route): Boolean {
35+
return oldRoute.start.name == newRoute.start.name
36+
}
37+
38+
override fun areContentsTheSame(oldRoute: Route, newRoute: Route): Boolean {
39+
return oldRoute::class == newRoute::class
40+
}
41+
}
42+
}
43+
}

presentation/src/main/java/com/stop/ui/routedetail/RouteDetailFragment.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class RouteDetailFragment : Fragment(), RouteDetailHandler {
3737

3838
initTMap()
3939
initView()
40+
setRecyclerView()
4041
}
4142

4243
override fun alertTMapReady() {
@@ -68,6 +69,13 @@ class RouteDetailFragment : Fragment(), RouteDetailHandler {
6869
}
6970
}
7071

72+
private fun setRecyclerView() {
73+
val adapter = RouteDetailAdapter()
74+
75+
binding.routeDetailDrawer.recyclerViewRouteDetail.adapter = adapter
76+
adapter.submitList(routeViewModel.tempItinerary.routes)
77+
}
78+
7179
override fun onDestroyView() {
7280
_binding = null
7381

presentation/src/main/res/layout/route_detail_drawer.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@
9797
app:layout_constraintBottom_toBottomOf="parent" />
9898
</androidx.constraintlayout.widget.ConstraintLayout>
9999

100-
100+
<androidx.recyclerview.widget.RecyclerView
101+
android:id="@+id/recycler_view_route_detail"
102+
android:layout_width="0dp"
103+
android:layout_height="0dp"
104+
android:layout_marginTop="17dp"
105+
app:layout_constraintStart_toStartOf="parent"
106+
app:layout_constraintEnd_toEndOf="parent"
107+
app:layout_constraintTop_toBottomOf="@id/view_alarm"
108+
app:layout_constraintBottom_toBottomOf="parent"
109+
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
110+
tools:listitem="@layout/route_path_item" />
101111
</androidx.constraintlayout.widget.ConstraintLayout>
102112
</layout>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools">
6+
7+
<data>
8+
<variable
9+
name="route"
10+
type="com.stop.domain.model.route.tmap.custom.Route" />
11+
</data>
12+
13+
<androidx.constraintlayout.widget.ConstraintLayout
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:background="@color/white">
17+
18+
<TextView
19+
android:layout_width="0dp"
20+
android:layout_height="150dp"
21+
android:text="@{route.start.name}"
22+
android:textSize="15sp"
23+
android:gravity="center"
24+
app:layout_constraintStart_toStartOf="parent"
25+
app:layout_constraintEnd_toEndOf="parent"
26+
app:layout_constraintTop_toTopOf="parent"
27+
tools:text="성복역" />
28+
</androidx.constraintlayout.widget.ConstraintLayout>
29+
</layout>

0 commit comments

Comments
 (0)