Skip to content

Commit d75e6a5

Browse files
committed
feat: 출발지, 도착지가 입력되지 않았을 때, 토스트 메시지 표시
1 parent 7265c7e commit d75e6a5

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.stop.model
2+
3+
enum class ErrorType {
4+
NO_START, NO_END,
5+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import androidx.fragment.app.Fragment
55
import android.view.LayoutInflater
66
import android.view.View
77
import android.view.ViewGroup
8+
import android.widget.Toast
89
import androidx.fragment.app.viewModels
10+
import com.stop.R
911
import com.stop.databinding.FragmentRouteBinding
1012
import com.stop.domain.model.route.tmap.custom.Itinerary
13+
import com.stop.model.ErrorType
1114
import com.stop.model.route.Coordinate
1215
import com.stop.model.route.Place
1316
import dagger.hilt.android.AndroidEntryPoint
@@ -66,6 +69,17 @@ class RouteFragment : Fragment() {
6669
}
6770
adapter.submitList(it)
6871
}
72+
73+
viewModel.errorMessage.observe(viewLifecycleOwner) {
74+
it.getContentIfNotHandled()?.let { errorType ->
75+
val message = when(errorType) {
76+
ErrorType.NO_START -> getString(R.string.no_start_input)
77+
ErrorType.NO_END -> getString(R.string.no_end_input)
78+
}
79+
80+
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
81+
}
82+
}
6983
}
7084

7185
private fun setStartAndDestinationText() {

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import com.stop.domain.model.route.tmap.RouteRequest
99
import com.stop.domain.model.route.tmap.custom.Itinerary
1010
import com.stop.domain.usecase.route.GetLastTransportTimeUseCase
1111
import com.stop.domain.usecase.route.GetRouteUseCase
12+
import com.stop.model.ErrorType
13+
import com.stop.model.Event
1214
import com.stop.model.route.Place
1315
import dagger.hilt.android.lifecycle.HiltViewModel
1416
import kotlinx.coroutines.Dispatchers
@@ -19,7 +21,7 @@ import javax.inject.Inject
1921
class RouteViewModel @Inject constructor(
2022
private val getRouteUseCase: GetRouteUseCase,
2123
private val getLastTransportTimeUseCase: GetLastTransportTimeUseCase,
22-
): ViewModel() {
24+
) : ViewModel() {
2325

2426
private val _origin = MutableLiveData<Place>()
2527
val origin: LiveData<Place>
@@ -37,9 +39,20 @@ class RouteViewModel @Inject constructor(
3739
val lastTimeResponse: LiveData<TransportLastTimeInfo>
3840
get() = _lastTimeResponse
3941

42+
private val _errorMessage = MutableLiveData<Event<ErrorType>>()
43+
val errorMessage: LiveData<Event<ErrorType>>
44+
get() = _errorMessage
45+
4046
fun getRoute() {
41-
val originValue = _origin.value ?: return
42-
val destinationValue = _destination.value ?: return
47+
val originValue = _origin.value ?: let {
48+
_errorMessage.value = Event(ErrorType.NO_START)
49+
return
50+
}
51+
52+
val destinationValue = _destination.value ?: let {
53+
_errorMessage.value = Event(ErrorType.NO_END)
54+
return
55+
}
4356

4457
val routeRequest = RouteRequest(
4558
startX = originValue.coordinate.longitude,
@@ -55,7 +68,8 @@ class RouteViewModel @Inject constructor(
5568

5669
fun calculateLastTransportTime(itinerary: Itinerary) {
5770
viewModelScope.launch(Dispatchers.IO) {
58-
val lastTimeInfo = getLastTransportTimeUseCase.getLastTransportTime(itinerary) ?: return@launch
71+
val lastTimeInfo =
72+
getLastTransportTimeUseCase.getLastTransportTime(itinerary) ?: return@launch
5973

6074
_lastTimeResponse.postValue(lastTimeInfo)
6175
}

presentation/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@
2929
<string name="quit">종료</string>
3030
<string name="minus">-</string>
3131
<string name="plus">+</string>
32+
<string name="no_start_input">출발지가 입력되지 않았습니다.</string>
33+
<string name="no_end_input">도착지가 입력되지 않았습니다.</string>
3234
</resources>

0 commit comments

Comments
 (0)