Skip to content

Commit 0634efd

Browse files
Merge pull request #63 from boostcampwm-2022/demo
Fragment ๊ฐ„์— Navigation ๋ฐ์ดํ„ฐ ์—ฐ๊ฒฐ
2 parents dc25100 + db72f11 commit 0634efd

File tree

9 files changed

+94
-51
lines changed

9 files changed

+94
-51
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class MapFragment : Fragment(), MapHandler {
107107

108108
private fun initNavigateAction() {
109109
binding.textViewSearch.setOnClickListener {
110-
binding.root.findNavController().navigate(R.id.action_mapFragment_to_placeSearchFragment)
110+
binding.root.findNavController()
111+
.navigate(R.id.action_mapFragment_to_placeSearchFragment)
111112
}
112113

113114
/*
@@ -117,11 +118,13 @@ class MapFragment : Fragment(), MapHandler {
117118
*/
118119

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

123125
binding.layoutPanel.findViewById<View>(R.id.view_panel_end).setOnClickListener {
124-
binding.root.findNavController().navigate(R.id.action_mapFragment_to_routeFragment)
126+
val action = MapFragmentDirections.actionMapFragmentToRouteFragment().setEnd(placeSearchViewModel.panelInfo)
127+
binding.root.findNavController().navigate(action)
125128
}
126129
}
127130

@@ -153,7 +156,11 @@ class MapFragment : Fragment(), MapHandler {
153156
event.getContentIfNotHandled()?.let { clickPlace ->
154157
val clickTMapPoint = TMapPoint(clickPlace.centerLat, clickPlace.centerLon)
155158

156-
tMap.tMapView.setCenterPoint(clickTMapPoint.latitude, clickTMapPoint.longitude, true)
159+
tMap.tMapView.setCenterPoint(
160+
clickTMapPoint.latitude,
161+
clickTMapPoint.longitude,
162+
true
163+
)
157164
tMap.addMarker(Marker.PLACE_MARKER, Marker.PLACE_MARKER_IMG, clickTMapPoint)
158165
setPanel(clickTMapPoint)
159166
}

โ€Ž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: 23 additions & 16 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
}
@@ -89,8 +102,12 @@ class RouteFragment : Fragment() {
89102
}
90103

91104
private fun setStartAndDestinationText() {
92-
viewModel.setOrigin(Place(ORIGIN_NAME, Coordinate(ORIGIN_Y, ORIGIN_X)))
93-
viewModel.setDestination(Place(DESTINATION_NAME, Coordinate(DESTINATION_Y, DESTINATION_X)))
105+
args.start?.let {
106+
viewModel.setOrigin(it)
107+
}
108+
args.end?.let {
109+
viewModel.setDestination(it)
110+
}
94111
viewModel.getRoute()
95112
}
96113

@@ -99,14 +116,4 @@ class RouteFragment : Fragment() {
99116

100117
super.onDestroyView()
101118
}
102-
103-
companion object {
104-
private const val ORIGIN_NAME = "์ด์•ค์”จ๋ฒค์ณ๋“œ๋ฆผํƒ€์›Œ3์ฐจ"
105-
private const val ORIGIN_X = "126.893820"
106-
private const val ORIGIN_Y = "37.4865002"
107-
108-
private const val DESTINATION_NAME = "Naver1784"
109-
private const val DESTINATION_X = "127.105037"
110-
private const val DESTINATION_Y = "37.3584879"
111-
}
112119
}

โ€Žpresentation/src/main/res/layout/fragment_place_search.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
3535
android:layout_width="0dp"
3636
android:layout_height="wrap_content"
37-
android:layout_marginTop="8dp"
37+
android:layout_marginTop="50dp"
3838
app:endIconMode="clear_text"
3939
app:layout_constraintEnd_toEndOf="@id/guide_line_end"
4040
app:layout_constraintStart_toStartOf="@id/guide_line_start"

โ€Ž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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)