Skip to content

Commit 4cb5fa8

Browse files
committed
temp: 집에 가서 하기( RecyclerView를 이용해서 소요 되는 시간 표시하기 )
1 parent a147b43 commit 4cb5fa8

12 files changed

+215
-20
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.stop.ui.route
22

3+
import android.graphics.Rect
4+
import android.view.View
35
import androidx.recyclerview.widget.RecyclerView
46
import com.stop.databinding.RouteItemBinding
57
import com.stop.domain.model.route.tmap.custom.Itinerary
@@ -10,11 +12,29 @@ class RouteViewHolder(
1012
private val binding: RouteItemBinding
1113
) : RecyclerView.ViewHolder(binding.root) {
1214

15+
private val adapter = TimeLineAdapter()
16+
17+
init {
18+
binding.recyclerviewTimeLine.adapter = adapter
19+
binding.recyclerviewTimeLine.setHasFixedSize(true)
20+
binding.recyclerviewTimeLine.addItemDecoration(object: RecyclerView.ItemDecoration() {
21+
override fun getItemOffsets(
22+
outRect: Rect,
23+
view: View,
24+
parent: RecyclerView,
25+
state: RecyclerView.State
26+
) {
27+
if (parent.getChildAdapterPosition(view) != RecyclerView.NO_POSITION) {
28+
outRect.set(0, 0, -40, 0)
29+
}
30+
}
31+
})
32+
}
33+
1334
fun bind(itinerary: Itinerary) {
14-
binding.itinerary = itinerary
15-
binding.textViewExpectedRoute.text = calculateExpectedRoute(itinerary)
1635
binding.textViewExpectedRequiredTime.text = secondToHourAndMinute(itinerary.totalTime)
17-
binding.executePendingBindings()
36+
37+
adapter.submitList(itinerary.routes)
1838
}
1939

2040
private fun calculateExpectedRoute(itinerary: Itinerary): String {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.stop.ui.route
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 com.stop.databinding.TimeLineItemBinding
8+
import com.stop.domain.model.route.tmap.custom.Route
9+
import com.stop.domain.model.route.tmap.custom.TransportRoute
10+
import com.stop.domain.model.route.tmap.custom.WalkRoute
11+
12+
class TimeLineAdapter : ListAdapter<Route, TimeLineViewHolder>(diffUtil) {
13+
14+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TimeLineViewHolder {
15+
val binding = TimeLineItemBinding.inflate(
16+
LayoutInflater.from(parent.context),
17+
parent,
18+
false
19+
)
20+
21+
return TimeLineViewHolder(binding)
22+
}
23+
24+
override fun onBindViewHolder(holder: TimeLineViewHolder, position: Int) {
25+
holder.bind(getItem(position), holder.adapterPosition)
26+
}
27+
28+
companion object {
29+
private val diffUtil = object : DiffUtil.ItemCallback<Route>() {
30+
override fun areItemsTheSame(oldRoute: Route, newRoute: Route): Boolean {
31+
return false
32+
return oldRoute.sectionTime == newRoute.sectionTime &&
33+
oldRoute.mode == newRoute.mode
34+
}
35+
36+
override fun areContentsTheSame(oldRoute: Route, newRoute: Route): Boolean {
37+
if (oldRoute is TransportRoute && newRoute is TransportRoute) {
38+
return oldRoute == newRoute
39+
} else if (oldRoute is WalkRoute && newRoute is WalkRoute) {
40+
return oldRoute == newRoute
41+
}
42+
return false
43+
}
44+
}
45+
}
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.stop.ui.route
2+
3+
import android.view.View
4+
import androidx.core.content.ContextCompat
5+
import androidx.recyclerview.widget.RecyclerView
6+
import com.stop.R
7+
import com.stop.databinding.TimeLineItemBinding
8+
import com.stop.domain.model.route.tmap.custom.MoveType
9+
import com.stop.domain.model.route.tmap.custom.Route
10+
11+
class TimeLineViewHolder(
12+
private val binding: TimeLineItemBinding
13+
) : RecyclerView.ViewHolder(binding.root) {
14+
15+
fun bind(route: Route, position: Int) {
16+
val text = route.start.name + " " +
17+
binding.root.resources.getString(
18+
R.string.section_time,
19+
(route.sectionTime / 60).toInt().toString()
20+
)
21+
binding.textViewSectionTime.text = text
22+
23+
24+
val imageSrc = when (route.mode) {
25+
MoveType.BUS -> R.drawable.time_line_bus_16
26+
MoveType.SUBWAY -> R.drawable.time_line_subway_16
27+
MoveType.WALK, MoveType.TRANSFER -> {
28+
if (position != 0) {
29+
binding.imageViewIcon.visibility = View.GONE
30+
return
31+
}
32+
R.drawable.time_line_directions_walk_16
33+
}
34+
else -> R.drawable.time_line_help_16
35+
}
36+
37+
38+
val drawable = ContextCompat.getDrawable(binding.root.context, imageSrc)
39+
?: throw IllegalArgumentException()
40+
41+
binding.imageViewIcon.setImageDrawable(drawable)
42+
}
43+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="18dp" android:tint="#000000"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="18dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M4,16c0,0.88 0.39,1.67 1,2.22L5,20c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-1h8v1c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-1.78c0.61,-0.55 1,-1.34 1,-2.22L20,6c0,-3.5 -3.58,-4 -8,-4s-8,0.5 -8,4v10zM7.5,17c-0.83,0 -1.5,-0.67 -1.5,-1.5S6.67,14 7.5,14s1.5,0.67 1.5,1.5S8.33,17 7.5,17zM16.5,17c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM18,11L6,11L6,6h12v5z"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="18dp" android:tint="#000000"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="18dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M13.5,5.5c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM9.8,8.9L7,23h2.1l1.8,-8 2.1,2v6h2v-7.5l-2.1,-2 0.6,-3C14.8,12 16.8,13 19,13v-2c-1.9,0 -3.5,-1 -4.3,-2.4l-1,-1.6c-0.4,-0.6 -1,-1 -1.7,-1 -0.3,0 -0.5,0.1 -0.8,0.1L6,8.3V13h2V9.6l1.8,-0.7"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="18dp" android:tint="#000000"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="18dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"/>
5+
</vector>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector android:height="18dp" android:tint="#000000"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="18dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M15.5,16m-1,0a1,1 0,1 1,2 0a1,1 0,1 1,-2 0"/>
5+
<path android:fillColor="@android:color/white" android:pathData="M8.5,16m-1,0a1,1 0,1 1,2 0a1,1 0,1 1,-2 0"/>
6+
<path android:fillColor="@android:color/white" android:pathData="M7.01,9h10v5h-10zM17.8,2.8C16,2.09 13.86,2 12,2c-1.86,0 -4,0.09 -5.8,0.8C3.53,3.84 2,6.05 2,8.86L2,22h20L22,8.86c0,-2.81 -1.53,-5.02 -4.2,-6.06zM18,15.88c0,1.45 -1.18,2.62 -2.63,2.62l1.13,1.12L16.5,20L15,20l-1.5,-1.5h-2.83L9.17,20L7.5,20v-0.38l1.12,-1.12C7.18,18.5 6,17.32 6,15.88L6,9c0,-2.63 3,-3 6,-3 3.32,0 6,0.38 6,3v6.88z"/>
7+
</vector>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
5+
<corners android:radius="6dp" />
6+
7+
<stroke android:width="1dp"
8+
android:color="@color/black" />
9+
10+
<solid
11+
android:color="@color/white" />
12+
13+
</shape>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
5+
<stroke android:width="1dp"
6+
android:color="@color/black" />
7+
8+
<solid android:color="@color/white" />
9+
10+
</shape>

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools">
55

6-
<data>
7-
8-
<variable
9-
name="itinerary"
10-
type="com.stop.domain.model.route.tmap.custom.Itinerary" />
11-
</data>
12-
136
<androidx.constraintlayout.widget.ConstraintLayout
147
android:layout_width="match_parent"
158
android:layout_height="wrap_content"
@@ -34,19 +27,18 @@
3427
app:layout_constraintTop_toTopOf="@id/guideline_start_horizontal"
3528
tools:text="1시간 10분" />
3629

37-
<TextView
38-
android:id="@+id/text_view_expected_route"
30+
<androidx.recyclerview.widget.RecyclerView
31+
android:id="@+id/recyclerview_time_line"
3932
android:layout_width="0dp"
4033
android:layout_height="wrap_content"
41-
android:layout_marginTop="16dp"
34+
android:orientation="horizontal"
35+
tools:listitem="@layout/time_line_item"
4236
android:layout_marginBottom="16dp"
43-
android:ellipsize="end"
44-
android:maxLines="3"
4537
app:layout_constraintBottom_toBottomOf="parent"
46-
app:layout_constraintEnd_toEndOf="@id/guideline_end_vertical"
47-
app:layout_constraintStart_toStartOf="@id/guideline_start_vertical"
48-
app:layout_constraintTop_toBottomOf="@id/text_view_expected_required_time"
49-
tools:text="출발지 -> 1호선 Xxx역 -> 5315번 버스 환승 -> 2호선 Xxx역 환승 -> 도착지" />
38+
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
39+
app:layout_constraintTop_toBottomOf="@id/text_view_required_time_text"
40+
app:layout_constraintEnd_toStartOf="@+id/guideline_end_vertical"
41+
app:layout_constraintStart_toStartOf="@+id/guideline_start_vertical" />
5042

5143
<androidx.constraintlayout.widget.Guideline
5244
android:id="@+id/guideline_start_vertical"
@@ -67,7 +59,7 @@
6759
android:layout_width="wrap_content"
6860
android:layout_height="wrap_content"
6961
android:orientation="vertical"
70-
app:layout_constraintGuide_end="80dp" />
62+
app:layout_constraintGuide_end="16dp" />
7163

7264
</androidx.constraintlayout.widget.ConstraintLayout>
7365
</layout>

0 commit comments

Comments
 (0)