Skip to content

Commit 1016077

Browse files
committed
feat: 지도에서 선택한 출발지, 도착지 경로 화면으로 전달하기
1 parent 877455e commit 1016077

File tree

8 files changed

+89
-50
lines changed

8 files changed

+89
-50
lines changed

presentation/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id 'org.jetbrains.kotlin.android'
44
id 'androidx.navigation.safeargs'
55
id 'kotlin-kapt'
6+
id 'kotlin-parcelize'
67
id 'com.google.dagger.hilt.android'
78
}
89

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.stop.model.route
22

3+
import android.os.Parcelable
4+
import kotlinx.parcelize.Parcelize
5+
6+
@Parcelize
37
data class Coordinate(
48
val latitude: String,
59
val longitude: String,
6-
)
10+
) : Parcelable
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.stop.model.route
22

3+
import android.os.Parcelable
4+
import kotlinx.parcelize.Parcelize
5+
6+
@Parcelize
37
data class Place(
48
val name: String,
59
val coordinate: Coordinate,
6-
)
10+
) : Parcelable

presentation/src/main/java/com/stop/ui/map/MapFragment.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ class MapFragment : Fragment(), MapHandler {
117117
*/
118118

119119
binding.layoutPanel.findViewById<View>(R.id.view_panel_start).setOnClickListener {
120-
binding.root.findNavController().navigate(R.id.action_mapFragment_to_routeFragment)
120+
val action = MapFragmentDirections.actionMapFragmentToRouteFragment().setStart(placeSearchViewModel.panelInfo)
121+
binding.root.findNavController().navigate(action)
121122
}
122123

123124
binding.layoutPanel.findViewById<View>(R.id.view_panel_end).setOnClickListener {
124-
binding.root.findNavController().navigate(R.id.action_mapFragment_to_routeFragment)
125+
val action = MapFragmentDirections.actionMapFragmentToRouteFragment().setEnd(placeSearchViewModel.panelInfo)
126+
binding.root.findNavController().navigate(action)
125127
}
126128
}
127129

presentation/src/main/java/com/stop/ui/placesearch/PlaceSearchViewModel.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.stop.domain.usecase.geoLocation.GeoLocationUseCase
1212
import com.stop.domain.usecase.nearplace.GetNearPlacesUseCase
1313
import com.stop.model.Event
1414
import com.stop.model.Location
15+
import com.stop.model.route.Coordinate
1516
import dagger.hilt.android.lifecycle.HiltViewModel
1617
import kotlinx.coroutines.channels.Channel
1718
import kotlinx.coroutines.flow.MutableStateFlow
@@ -29,6 +30,8 @@ class PlaceSearchViewModel @Inject constructor(
2930

3031
var currentLocation = Location(0.0, 0.0)
3132

33+
var panelInfo: com.stop.model.route.Place? = null
34+
3235
private val _nearPlaceList = MutableStateFlow<List<Place>>(emptyList())
3336
val nearPlaceList: StateFlow<List<Place>> = _nearPlaceList
3437

@@ -95,11 +98,22 @@ class PlaceSearchViewModel @Inject constructor(
9598
fun getGeoLocationInfo(latitude: Double, longitude: Double) {
9699
viewModelScope.launch {
97100
_geoLocation.value = geoLocationUseCase.getGeoLocationInfo(latitude, longitude)
101+
102+
readySendValue(latitude, longitude)
98103
_panelVisibility.value = View.VISIBLE
99104
getDistance(latitude, longitude)
100105
}
101106
}
102107

108+
private fun readySendValue(latitude: Double, longitude: Double) {
109+
val clickedValue = _geoLocation.value ?: return
110+
111+
panelInfo = com.stop.model.route.Place(
112+
clickedValue.title,
113+
Coordinate(latitude.toString(), longitude.toString())
114+
)
115+
}
116+
103117
private fun getDistance(latitude: Double, longitude: Double) {
104118
val startPoint = android.location.Location("Start")
105119
val endPoint = android.location.Location("End")

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import android.view.ViewGroup
88
import android.widget.Toast
99
import androidx.fragment.app.activityViewModels
1010
import androidx.navigation.findNavController
11+
import androidx.navigation.fragment.navArgs
1112
import com.stop.R
1213
import com.stop.databinding.FragmentRouteBinding
1314
import com.stop.domain.model.route.tmap.custom.Itinerary
1415
import com.stop.model.ErrorType
15-
import com.stop.model.route.Coordinate
16-
import com.stop.model.route.Place
1716
import dagger.hilt.android.AndroidEntryPoint
1817

1918
@AndroidEntryPoint
@@ -25,6 +24,8 @@ class RouteFragment : Fragment() {
2524

2625
private val viewModel: RouteViewModel by activityViewModels()
2726

27+
private val args: RouteFragmentArgs by navArgs()
28+
2829
private lateinit var adapter: RouteAdapter
2930

3031
override fun onCreateView(
@@ -39,6 +40,7 @@ class RouteFragment : Fragment() {
3940
super.onViewCreated(view, savedInstanceState)
4041

4142
setBinding()
43+
setListener()
4244
setRecyclerView()
4345
setStartAndDestinationText()
4446
setObserve()
@@ -49,8 +51,19 @@ class RouteFragment : Fragment() {
4951
binding.viewModel = viewModel
5052
}
5153

54+
private fun setListener() {
55+
binding.textViewOrigin.setOnClickListener {
56+
val action = RouteFragmentDirections.actionRouteFragmentToPlaceSearchFragment()
57+
binding.root.findNavController().navigate(action)
58+
}
59+
binding.textViewDestination.setOnClickListener {
60+
val action = RouteFragmentDirections.actionRouteFragmentToPlaceSearchFragment()
61+
binding.root.findNavController().navigate(action)
62+
}
63+
}
64+
5265
private fun setRecyclerView() {
53-
adapter = RouteAdapter(object: OnItineraryClickListener {
66+
adapter = RouteAdapter(object : OnItineraryClickListener {
5467
override fun onItineraryClick(itinerary: Itinerary) {
5568
/**
5669
* UI가 ViewModel을 직접 호출하면 안 되지만, 테스트를 위해 막차 조회 함수를 호출했습니다.
@@ -72,7 +85,7 @@ class RouteFragment : Fragment() {
7285

7386
viewModel.errorMessage.observe(viewLifecycleOwner) {
7487
it.getContentIfNotHandled()?.let { errorType ->
75-
val message = when(errorType) {
88+
val message = when (errorType) {
7689
ErrorType.NO_START -> getString(R.string.no_start_input)
7790
ErrorType.NO_END -> getString(R.string.no_end_input)
7891
}
@@ -82,13 +95,18 @@ class RouteFragment : Fragment() {
8295
}
8396

8497
viewModel.lastTimeResponse.observe(viewLifecycleOwner) {
85-
binding.root.findNavController().navigate(R.id.action_routeFragment_to_routeDetailFragment)
98+
binding.root.findNavController()
99+
.navigate(R.id.action_routeFragment_to_routeDetailFragment)
86100
}
87101
}
88102

89103
private fun setStartAndDestinationText() {
90-
viewModel.setOrigin(Place(ORIGIN_NAME, Coordinate(ORIGIN_Y, ORIGIN_X)))
91-
viewModel.setDestination(Place(DESTINATION_NAME, Coordinate(DESTINATION_Y, DESTINATION_X)))
104+
args.start?.let {
105+
viewModel.setOrigin(it)
106+
}
107+
args.end?.let {
108+
viewModel.setDestination(it)
109+
}
92110
viewModel.getRoute()
93111
}
94112

@@ -97,14 +115,4 @@ class RouteFragment : Fragment() {
97115

98116
super.onDestroyView()
99117
}
100-
101-
companion object {
102-
private const val ORIGIN_NAME = "이앤씨벤쳐드림타워3차"
103-
private const val ORIGIN_X = "126.893820"
104-
private const val ORIGIN_Y = "37.4865002"
105-
106-
private const val DESTINATION_NAME = "Naver1784"
107-
private const val DESTINATION_X = "127.105037"
108-
private const val DESTINATION_Y = "37.3584879"
109-
}
110118
}

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

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,63 +25,56 @@
2525
app:layout_constraintEnd_toEndOf="@id/guideline_end_vertical"
2626
app:layout_constraintTop_toTopOf="@id/guideline_start_horizontal" />
2727

28-
<com.google.android.material.textfield.TextInputLayout
29-
android:id="@+id/text_input_layout_origin"
28+
29+
<TextView
30+
android:id="@+id/text_view_origin"
3031
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
3132
android:layout_width="0dp"
3233
android:layout_height="wrap_content"
34+
android:paddingVertical="10dp"
35+
android:text="@{viewModel.origin.name}"
36+
android:background="@drawable/round_border"
3337
app:layout_constraintEnd_toStartOf="@id/button_swap_origin_with_destination"
3438
app:layout_constraintStart_toStartOf="@id/guideline_start_vertical"
35-
app:layout_constraintTop_toBottomOf="@id/button_back_to_home">
36-
37-
<com.google.android.material.textfield.TextInputEditText
38-
android:id="@+id/text_input_edit_text_origin"
39-
android:layout_width="match_parent"
40-
android:layout_height="wrap_content"
41-
android:text="@{viewModel.origin.name}"
42-
tools:text="이앤씨벤쳐드림타워3차" />
43-
44-
</com.google.android.material.textfield.TextInputLayout>
39+
app:layout_constraintTop_toBottomOf="@id/button_back_to_home"
40+
tools:text="이앤씨벤쳐드림타워3차" />
4541

4642
<androidx.appcompat.widget.AppCompatButton
4743
android:id="@+id/button_swap_origin_with_destination"
4844
style="@style/Widget.AppCompat.Button.Small"
4945
android:layout_width="wrap_content"
5046
android:layout_height="wrap_content"
5147
android:background="@drawable/ic_baseline_swap_vert_24"
52-
app:layout_constraintBottom_toBottomOf="@id/text_input_layout_origin"
48+
app:layout_constraintBottom_toBottomOf="@id/text_view_origin"
5349
app:layout_constraintDimensionRatio="1:1"
5450
app:layout_constraintEnd_toStartOf="@id/guideline_end_vertical"
55-
app:layout_constraintTop_toTopOf="@id/text_input_layout_origin" />
51+
app:layout_constraintTop_toTopOf="@id/text_view_origin" />
5652

57-
<com.google.android.material.textfield.TextInputLayout
58-
android:id="@+id/text_input_layout_destination"
53+
<TextView
54+
android:id="@+id/text_view_destination"
5955
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
6056
android:layout_width="0dp"
6157
android:layout_height="wrap_content"
58+
android:layout_marginTop="10dp"
59+
android:paddingVertical="10dp"
60+
android:background="@drawable/round_border"
61+
android:text="@{viewModel.destination.name}"
6262
app:layout_constraintEnd_toStartOf="@id/button_swap_origin_with_destination"
6363
app:layout_constraintStart_toStartOf="@id/guideline_start_vertical"
64-
app:layout_constraintTop_toBottomOf="@id/text_input_layout_origin">
65-
66-
<com.google.android.material.textfield.TextInputEditText
67-
android:id="@+id/text_input_edit_text_destination"
68-
android:layout_width="match_parent"
69-
android:layout_height="wrap_content"
70-
android:text="@{viewModel.destination.name}"
71-
tools:text="Naver1784" />
64+
app:layout_constraintTop_toBottomOf="@id/text_view_origin"
65+
tools:text="Naver1784" />
7266

73-
</com.google.android.material.textfield.TextInputLayout>
7467

7568
<androidx.appcompat.widget.AppCompatButton
7669
android:id="@+id/button_erase_origin_and_destination"
7770
style="@style/Widget.AppCompat.Button.Small"
7871
android:layout_width="wrap_content"
7972
android:layout_height="wrap_content"
8073
android:background="@drawable/ic_baseline_replay_24"
81-
app:layout_constraintBottom_toBottomOf="@id/text_input_layout_destination"
74+
app:layout_constraintBottom_toBottomOf="@id/text_view_destination"
8275
app:layout_constraintDimensionRatio="1:1"
8376
app:layout_constraintEnd_toStartOf="@id/guideline_end_vertical"
84-
app:layout_constraintTop_toTopOf="@id/text_input_layout_destination" />
77+
app:layout_constraintTop_toTopOf="@id/text_view_destination" />
8578

8679
<androidx.recyclerview.widget.RecyclerView
8780
android:id="@+id/recyclerview_route"
@@ -92,7 +85,7 @@
9285
app:layout_constraintBottom_toBottomOf="parent"
9386
app:layout_constraintEnd_toStartOf="@id/guideline_end_vertical"
9487
app:layout_constraintStart_toStartOf="@id/guideline_start_vertical"
95-
app:layout_constraintTop_toBottomOf="@id/text_input_layout_destination"
88+
app:layout_constraintTop_toBottomOf="@id/text_view_destination"
9689
tools:listitem="@layout/route_item" />
9790

9891
<androidx.constraintlayout.widget.Guideline

presentation/src/main/res/navigation/nav_graph.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/nav_graph"
6-
app:startDestination="@id/alarmSetting">
6+
app:startDestination="@id/mapFragment">
77

88
<fragment
99
android:id="@+id/mapFragment"
@@ -75,6 +75,19 @@
7575
<action
7676
android:id="@+id/action_routeFragment_to_routeDetailFragment"
7777
app:destination="@id/routeDetailFragment" />
78+
<argument
79+
android:name="start"
80+
app:argType="com.stop.model.route.Place"
81+
app:nullable="true"
82+
android:defaultValue="@null" />
83+
<argument
84+
android:name="end"
85+
app:argType="com.stop.model.route.Place"
86+
app:nullable="true"
87+
android:defaultValue="@null" />
88+
<action
89+
android:id="@+id/action_routeFragment_to_placeSearchFragment"
90+
app:destination="@id/placeSearchFragment" />
7891
</fragment>
7992
<fragment
8093
android:id="@+id/missionFragment"

0 commit comments

Comments
 (0)