Skip to content

Commit b1d27f5

Browse files
Merge pull request #84 from boostcampwm-2022/27-feature-route-ui
경로 화면 UI 그리기
2 parents 9ec526a + bb314d3 commit b1d27f5

19 files changed

+691
-405
lines changed

presentation/src/main/java/com/stop/model/route/RouteItem.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ data class RouteItem(
1111
val lastTime: String?,
1212
val beforeColor: Int,
1313
val currentColor: Int,
14-
val type: RouteItemType
14+
val type: RouteItemType,
15+
val typeName: String = "",
1516
)
1617

1718
fun RouteItem.toFirstRouteItem(): RouteItem {
@@ -20,7 +21,10 @@ fun RouteItem.toFirstRouteItem(): RouteItem {
2021
)
2122
}
2223

23-
fun RouteItem.toLastRouteItem(name: String, coordinate: com.stop.model.route.Coordinate): RouteItem {
24+
fun RouteItem.toLastRouteItem(
25+
name: String,
26+
coordinate: com.stop.model.route.Coordinate
27+
): RouteItem {
2428
return this.copy(
2529
name = name,
2630
coordinate = Coordinate(coordinate.latitude, coordinate.longitude),

presentation/src/main/java/com/stop/ui/alarmsetting/AlarmSettingFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class AlarmSettingFragment : Fragment() {
125125
const val ALARM_CODE = 123
126126
const val ALARM_MAP_CODE = 122
127127
const val ALARM_NOTIFICATION_ID = 121
128+
const val ALARM_NOTIFICATION_HIGH_ID = 120
128129
const val LAST_TIME = "lastTime"
129130
const val ALARM_TIME = "alarmTime"
130131
}

presentation/src/main/java/com/stop/ui/mission/MissionFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.fragment.app.Fragment
1111
import androidx.fragment.app.activityViewModels
1212
import androidx.fragment.app.viewModels
1313
import androidx.lifecycle.lifecycleScope
14+
import androidx.navigation.fragment.findNavController
1415
import com.google.android.material.snackbar.Snackbar
1516
import com.skt.tmap.TMapPoint
1617
import com.stop.R
@@ -108,7 +109,7 @@ class MissionFragment : Fragment(), MissionHandler {
108109
fun clickMissionOver() {
109110
Snackbar.make(requireActivity().findViewById(R.id.constraint_layout_container), "미션을 취소합니다", Snackbar.LENGTH_SHORT).show()
110111
missionViewModel.isMissionOver.value = true
111-
//findNavController().navigate(R.id.action_missionFragment_to_mapFragment)
112+
findNavController().navigate(R.id.action_missionFragment_to_mapFragment)
112113
}
113114

114115
override fun alertTMapReady() {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 androidx.recyclerview.widget.RecyclerView
8+
import com.stop.databinding.RoutePathAtTimeLineItemBinding
9+
import com.stop.model.route.RouteItem
10+
11+
class RouteDetailAdapter : ListAdapter<RouteItem, RouteDetailAdapter.PathViewHolder>(diffUtil) {
12+
13+
class PathViewHolder(
14+
private val binding: RoutePathAtTimeLineItemBinding
15+
) : RecyclerView.ViewHolder(binding.root) {
16+
17+
fun bind(routeItem: RouteItem) {
18+
binding.routeItem = routeItem
19+
}
20+
}
21+
22+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PathViewHolder {
23+
val inflater = LayoutInflater.from(parent.context)
24+
val binding = RoutePathAtTimeLineItemBinding.inflate(inflater, parent, false)
25+
26+
return PathViewHolder(binding)
27+
}
28+
29+
override fun onBindViewHolder(holder: PathViewHolder, position: Int) {
30+
holder.bind(getItem(position))
31+
}
32+
33+
companion object {
34+
private val diffUtil = object : DiffUtil.ItemCallback<RouteItem>() {
35+
override fun areItemsTheSame(oldItem: RouteItem, newItem: RouteItem): Boolean {
36+
return oldItem.name == newItem.name
37+
}
38+
39+
override fun areContentsTheSame(oldItem: RouteItem, newItem: RouteItem): Boolean {
40+
return oldItem == newItem
41+
}
42+
}
43+
}
44+
}

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

Lines changed: 94 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,115 @@
11
package com.stop.ui.route
22

3-
import android.graphics.Rect
4-
import android.view.View
3+
import android.graphics.Color
4+
import androidx.core.content.ContextCompat
55
import androidx.recyclerview.widget.RecyclerView
6+
import com.stop.R
67
import com.stop.databinding.RouteItemBinding
7-
import com.stop.domain.model.route.tmap.custom.Itinerary
8+
import com.stop.domain.model.route.tmap.custom.*
9+
import com.stop.model.route.RouteItem
10+
import com.stop.model.route.RouteItemType
811

912
class RouteViewHolder(
1013
private val binding: RouteItemBinding
1114
) : RecyclerView.ViewHolder(binding.root) {
1215

13-
private val adapter = TimeLineAdapter()
16+
private val adapter = RouteDetailAdapter()
17+
var routeItemColor = 0
1418

1519
init {
1620
binding.recyclerviewTimeLine.adapter = adapter
1721
binding.recyclerviewTimeLine.setHasFixedSize(true)
18-
binding.recyclerviewTimeLine.addItemDecoration(object: RecyclerView.ItemDecoration() {
19-
override fun getItemOffsets(
20-
outRect: Rect,
21-
view: View,
22-
parent: RecyclerView,
23-
state: RecyclerView.State
24-
) {
25-
if (parent.getChildAdapterPosition(view) != RecyclerView.NO_POSITION) {
26-
outRect.set(0, 0, -10, 0)
27-
}
28-
}
29-
})
3022
}
3123

3224
fun bind(itinerary: Itinerary) {
3325
binding.textViewExpectedRequiredTime.text = secondToHourAndMinute(itinerary.totalTime)
26+
val routeItems = mutableListOf<RouteItem>()
27+
28+
itinerary.routes.drop(1).forEachIndexed { index, route ->
29+
if (route.mode == MoveType.TRANSFER) {
30+
return@forEachIndexed
31+
}
32+
val (typeName, mode) = if (index == itinerary.routes.size - 2) {
33+
Pair("하차", R.drawable.ic_star_white)
34+
} else {
35+
Pair(getTypeName(route), getRouteItemMode(route))
36+
}
37+
38+
routeItems.add(
39+
RouteItem(
40+
name = route.start.name,
41+
coordinate = route.start.coordinate,
42+
mode = mode,
43+
distance = getRouteItemDistance(route),
44+
travelTime = route.sectionTime.toInt(),
45+
lastTime = "",
46+
beforeColor = getRouteItemColor(route, false),
47+
currentColor = getRouteItemColor(route, true),
48+
type = RouteItemType.PATH,
49+
typeName = typeName,
50+
)
51+
)
52+
}
53+
adapter.submitList(routeItems)
54+
binding.timeLineContainer.post {
55+
binding.timeLineContainer.submitList(itinerary.routes)
56+
}
57+
}
58+
59+
private fun getRouteItemDistance(route: Route): Double {
60+
return if (route.mode == MoveType.TRANSFER) {
61+
val startPoint = android.location.Location("Start")
62+
val endPoint = android.location.Location("End")
63+
64+
startPoint.latitude = route.start.coordinate.latitude.toDouble()
65+
startPoint.longitude = route.start.coordinate.longitude.toDouble()
66+
endPoint.latitude = route.end.coordinate.latitude.toDouble()
67+
endPoint.longitude = route.end.coordinate.longitude.toDouble()
68+
startPoint.distanceTo(endPoint).toDouble()
69+
} else {
70+
route.distance
71+
}
72+
}
73+
74+
private fun getTypeName(route: Route): String {
75+
return when (route) {
76+
is WalkRoute -> "도보"
77+
is TransportRoute -> getSubwayTypeName(route)
78+
else -> ""
79+
}
80+
}
81+
82+
private fun getSubwayTypeName(route: TransportRoute): String {
83+
return when (route.mode) {
84+
MoveType.SUBWAY -> route.routeInfo.replace("수도권", "")
85+
MoveType.BUS -> route.routeInfo.split(":")[1]
86+
else -> route.routeInfo
87+
}
88+
}
89+
90+
private fun getRouteItemColor(route: Route, isCurrent: Boolean): Int {
91+
return if (isCurrent) {
92+
when (route) {
93+
is TransportRoute -> Color.parseColor("#${route.routeColor}")
94+
is WalkRoute -> ContextCompat.getColor(binding.root.context, R.color.main_yellow)
95+
else -> ContextCompat.getColor(binding.root.context, R.color.main_lighter_grey)
96+
}
97+
} else {
98+
if (routeItemColor != 0) {
99+
routeItemColor
100+
} else {
101+
getRouteItemColor(route, true)
102+
}
103+
}
104+
}
34105

35-
adapter.submitList(itinerary.routes)
106+
private fun getRouteItemMode(route: Route): Int {
107+
return when (route.mode) {
108+
MoveType.WALK, MoveType.TRANSFER -> R.drawable.ic_walk_white
109+
MoveType.BUS -> R.drawable.ic_bus_white
110+
MoveType.SUBWAY -> R.drawable.ic_subway_white
111+
else -> R.drawable.ic_star_white
112+
}
36113
}
37114

38115
private fun secondToHourAndMinute(second: Int): String {

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

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)