From 877e0fbde3cbaf8d8f241795a1d58836930241b4 Mon Sep 17 00:00:00 2001 From: DoDoBest Date: Mon, 12 Dec 2022 15:24:56 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20=EC=84=9C=EC=9A=B8=20=EB=B2=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A7=89=EC=B0=A8=20=EC=8B=9C=EA=B0=84=20=ED=8C=8C?= =?UTF-8?q?=EC=8B=B1=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/usecase/route/GetLastTransportTimeUseCaseImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/domain/src/main/java/com/stop/domain/usecase/route/GetLastTransportTimeUseCaseImpl.kt b/domain/src/main/java/com/stop/domain/usecase/route/GetLastTransportTimeUseCaseImpl.kt index 5e75c9e4..8d622946 100644 --- a/domain/src/main/java/com/stop/domain/usecase/route/GetLastTransportTimeUseCaseImpl.kt +++ b/domain/src/main/java/com/stop/domain/usecase/route/GetLastTransportTimeUseCaseImpl.kt @@ -378,7 +378,7 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor( lastTime += TIME_CORRECTION_VALUE } - val lastTimeString = lastTime.toString().chunked(2).joinToString(":") + val lastTimeString = lastTime.toString().padStart(6, '0').chunked(2).joinToString(":") return TransportLastTime( transportMoveType = TransportMoveType.BUS, @@ -521,7 +521,7 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor( lastTime += TIME_CORRECTION_VALUE } - val lastTimeString = lastTime.toString().chunked(2).joinToString(":") + val lastTimeString = lastTime.toString().padStart(6, '0').chunked(2).joinToString(":") return TransportLastTime( transportMoveType = TransportMoveType.BUS, From 33137ae437a857252444a2461390af1908985874 Mon Sep 17 00:00:00 2001 From: DoDoBest Date: Mon, 12 Dec 2022 16:35:43 +0900 Subject: [PATCH 2/7] =?UTF-8?q?style:=20=ED=95=A8=EC=88=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=AA=85=ED=99=95=ED=95=98=EA=B2=8C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- presentation/src/main/java/com/stop/ui/route/RouteFragment.kt | 4 ++-- .../src/main/java/com/stop/ui/route/RouteViewModel.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt b/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt index ce6db379..58059a45 100644 --- a/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt +++ b/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt @@ -99,7 +99,7 @@ class RouteFragment : Fragment() { navController.popBackStack(R.id.mapFragment, false) } binding.imageViewResearch.setOnClickListener { - routeViewModel.getRoute() + routeViewModel.patchRoute() } } @@ -163,7 +163,7 @@ class RouteFragment : Fragment() { requireArguments().clear() if (args?.start != null || args?.end != null) { - routeViewModel.getRoute() + routeViewModel.patchRoute() } } diff --git a/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt b/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt index 2c81e62a..e5554e6b 100644 --- a/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt +++ b/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt @@ -50,7 +50,7 @@ class RouteViewModel @Inject constructor( val isLoading: LiveData> get() = _isLoading - fun getRoute(isShowError: Boolean = true) { + fun patchRoute(isShowError: Boolean = true) { val originValue = _origin.value ?: let { if (!isShowError) { return @@ -92,7 +92,7 @@ class RouteViewModel @Inject constructor( _origin.value = _destination.value.also { _destination.value = _origin.value } - getRoute(false) + patchRoute(false) } fun calculateLastTransportTime(itinerary: Itinerary) { From 4ffaacee9c5f567c13966a2932a205e017ca9917 Mon Sep 17 00:00:00 2001 From: DoDoBest Date: Mon, 12 Dec 2022 17:28:24 +0900 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20socket=20time=20out=20exception,=20u?= =?UTF-8?q?nknown=20host=20excpetion=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/stop/data/di/NetworkModule.kt | 4 ++++ .../src/main/java/com/stop/model/ErrorType.kt | 3 +++ .../java/com/stop/ui/route/RouteViewModel.kt | 21 ++++++++++++++++--- presentation/src/main/res/values/strings.xml | 3 +++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/data/src/main/java/com/stop/data/di/NetworkModule.kt b/data/src/main/java/com/stop/data/di/NetworkModule.kt index 3c49d978..da055d9d 100644 --- a/data/src/main/java/com/stop/data/di/NetworkModule.kt +++ b/data/src/main/java/com/stop/data/di/NetworkModule.kt @@ -20,6 +20,7 @@ import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory +import java.util.concurrent.TimeUnit import javax.inject.Named import javax.inject.Singleton @@ -40,6 +41,9 @@ internal object NetworkModule { loggingInterceptor: HttpLoggingInterceptor, ): OkHttpClient { return OkHttpClient.Builder() + .connectTimeout(500, TimeUnit.SECONDS) + .writeTimeout(500, TimeUnit.SECONDS) + .readTimeout(500, TimeUnit.SECONDS) .addInterceptor(loggingInterceptor) .addInterceptor(customInterceptor) .build() diff --git a/presentation/src/main/java/com/stop/model/ErrorType.kt b/presentation/src/main/java/com/stop/model/ErrorType.kt index e84bf9aa..4582e909 100644 --- a/presentation/src/main/java/com/stop/model/ErrorType.kt +++ b/presentation/src/main/java/com/stop/model/ErrorType.kt @@ -12,4 +12,7 @@ enum class ErrorType(val stringResourcesId: Int) { AVAILABLE_BUS_NO_EXIST_YET(R.string.available_bus_no_exist_yet), BUS_DISAPPEAR_SUDDENLY(R.string.bus_disappear_suddenly), MISSION_SOMETHING_WRONG(R.string.mission_something_wrong), + SOCKET_TIMEOUT_EXCEPTION(R.string.socket_timeout_exception_please_retry), + UNKNOWN_EXCEPTION(R.string.unknown_exception_occur), + UNKNOWN_HOST_EXCEPTION(R.string.unknown_host_exception_occur), } \ No newline at end of file diff --git a/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt b/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt index e5554e6b..ba9d7130 100644 --- a/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt +++ b/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt @@ -14,7 +14,11 @@ import com.stop.model.ErrorType import com.stop.model.Event import com.stop.model.route.Place import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.CoroutineExceptionHandler +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import java.net.SocketTimeoutException +import java.net.UnknownHostException import javax.inject.Inject @HiltViewModel @@ -50,6 +54,16 @@ class RouteViewModel @Inject constructor( val isLoading: LiveData> get() = _isLoading + private val coroutineExceptionHandler = CoroutineExceptionHandler { _, throwable -> + val errorMessage = when (throwable) { + is SocketTimeoutException -> Event(ErrorType.SOCKET_TIMEOUT_EXCEPTION) + is UnknownHostException -> Event(ErrorType.UNKNOWN_HOST_EXCEPTION) + else -> Event(ErrorType.UNKNOWN_EXCEPTION) + } + _errorMessage.postValue(errorMessage) + _isLoading.postValue(Event(false)) + } + fun patchRoute(isShowError: Boolean = true) { val originValue = _origin.value ?: let { if (!isShowError) { @@ -75,7 +89,7 @@ class RouteViewModel @Inject constructor( endY = destinationValue.coordinate.latitude, ) - viewModelScope.launch { + viewModelScope.launch(Dispatchers.Default + coroutineExceptionHandler) { val itineraries = getRouteUseCase(routeRequest) if (itineraries.isEmpty()) { _errorMessage.value = Event(ErrorType.NO_ROUTE_RESULT) @@ -97,8 +111,9 @@ class RouteViewModel @Inject constructor( fun calculateLastTransportTime(itinerary: Itinerary) { checkClickedItinerary(itinerary) - viewModelScope.launch { - this@RouteViewModel._lastTimeResponse.value = Event(getLastTransportTimeUseCase(itinerary) ) + viewModelScope.launch(Dispatchers.Default + coroutineExceptionHandler) { + this@RouteViewModel._lastTimeResponse.value = + Event(getLastTransportTimeUseCase(itinerary)) } } diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index d0b966ec..69c621f2 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -80,4 +80,7 @@ 도착지 : %1$s 막차시간 : %1$s %1$d분 + API 서버가 응답하지 않습니다. 다시 시도해주세요. + 알 수 없는 에러가 발생했습니다. + 인터넷이 연결되어 있지 않거나, 페쇄망 호스트에 연결을 시도했습니다. \ No newline at end of file From afe20cc56c4ca357709db35006ee3fffbd474269 Mon Sep 17 00:00:00 2001 From: DoDoBest Date: Mon, 12 Dec 2022 18:07:14 +0900 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20=EC=9E=98=EB=AA=BB=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=ED=95=9C=20Timeout=20=EC=8B=9C=EA=B0=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/com/stop/data/di/NetworkModule.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/src/main/java/com/stop/data/di/NetworkModule.kt b/data/src/main/java/com/stop/data/di/NetworkModule.kt index da055d9d..3ef160ab 100644 --- a/data/src/main/java/com/stop/data/di/NetworkModule.kt +++ b/data/src/main/java/com/stop/data/di/NetworkModule.kt @@ -41,9 +41,9 @@ internal object NetworkModule { loggingInterceptor: HttpLoggingInterceptor, ): OkHttpClient { return OkHttpClient.Builder() - .connectTimeout(500, TimeUnit.SECONDS) - .writeTimeout(500, TimeUnit.SECONDS) - .readTimeout(500, TimeUnit.SECONDS) + .connectTimeout(5, TimeUnit.SECONDS) + .writeTimeout(5, TimeUnit.SECONDS) + .readTimeout(5, TimeUnit.SECONDS) .addInterceptor(loggingInterceptor) .addInterceptor(customInterceptor) .build() From 145188c8e60ea97cad134afc4c70fe0a8ce9a8bf Mon Sep 17 00:00:00 2001 From: DoDoBest Date: Mon, 12 Dec 2022 18:14:11 +0900 Subject: [PATCH 5/7] =?UTF-8?q?fix:=20viewModelScope=20background=20thread?= =?UTF-8?q?=EC=97=90=EC=84=9C=20postValue=EB=A1=9C=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/stop/ui/route/RouteViewModel.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt b/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt index ba9d7130..63a46eae 100644 --- a/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt +++ b/presentation/src/main/java/com/stop/ui/route/RouteViewModel.kt @@ -92,13 +92,13 @@ class RouteViewModel @Inject constructor( viewModelScope.launch(Dispatchers.Default + coroutineExceptionHandler) { val itineraries = getRouteUseCase(routeRequest) if (itineraries.isEmpty()) { - _errorMessage.value = Event(ErrorType.NO_ROUTE_RESULT) - _routeResponse.value = listOf() - _isLoading.value = Event(false) + _errorMessage.postValue(Event(ErrorType.NO_ROUTE_RESULT)) + _routeResponse.postValue(listOf()) + _isLoading.postValue(Event(false)) return@launch } - this@RouteViewModel._routeResponse.value = itineraries - _isLoading.value = Event(false) + this@RouteViewModel._routeResponse.postValue(itineraries) + _isLoading.postValue(Event(false)) } } @@ -112,8 +112,7 @@ class RouteViewModel @Inject constructor( fun calculateLastTransportTime(itinerary: Itinerary) { checkClickedItinerary(itinerary) viewModelScope.launch(Dispatchers.Default + coroutineExceptionHandler) { - this@RouteViewModel._lastTimeResponse.value = - Event(getLastTransportTimeUseCase(itinerary)) + this@RouteViewModel._lastTimeResponse.postValue(Event(getLastTransportTimeUseCase(itinerary))) } } From 3fe010729b3bae4d5b2bac09777be719f36cb524 Mon Sep 17 00:00:00 2001 From: DoDoBest Date: Tue, 13 Dec 2022 13:03:12 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20Navigation=20Component=20Backstack?= =?UTF-8?q?=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/alarmsetting/AlarmSettingFragment.kt | 3 +- .../main/java/com/stop/ui/map/MapFragment.kt | 20 ++---- .../java/com/stop/ui/route/RouteFragment.kt | 3 +- .../ui/routedetail/RouteDetailFragment.kt | 4 +- .../src/main/res/navigation/nav_graph.xml | 62 +++++++++++++++++-- .../main/res/navigation/route_nav_graph.xml | 47 -------------- 6 files changed, 65 insertions(+), 74 deletions(-) delete mode 100644 presentation/src/main/res/navigation/route_nav_graph.xml diff --git a/presentation/src/main/java/com/stop/ui/alarmsetting/AlarmSettingFragment.kt b/presentation/src/main/java/com/stop/ui/alarmsetting/AlarmSettingFragment.kt index 78e76904..080f702a 100644 --- a/presentation/src/main/java/com/stop/ui/alarmsetting/AlarmSettingFragment.kt +++ b/presentation/src/main/java/com/stop/ui/alarmsetting/AlarmSettingFragment.kt @@ -111,8 +111,7 @@ class AlarmSettingFragment : Fragment() { //alarmSettingViewModel.makeAlarmWorker(transportLastTime.timeToBoard) val navController = findNavController() - navController.setGraph(R.navigation.nav_graph) - navController.popBackStack(R.id.action_global_mapFragment, false) + navController.popBackStack(R.id.mapFragment, false) requireActivity().viewModelStore.clear() } diff --git a/presentation/src/main/java/com/stop/ui/map/MapFragment.kt b/presentation/src/main/java/com/stop/ui/map/MapFragment.kt index cea9c36f..6633ae02 100644 --- a/presentation/src/main/java/com/stop/ui/map/MapFragment.kt +++ b/presentation/src/main/java/com/stop/ui/map/MapFragment.kt @@ -7,6 +7,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.os.bundleOf import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.asLiveData @@ -16,7 +17,6 @@ import androidx.navigation.fragment.findNavController import com.google.android.material.bottomsheet.BottomSheetBehavior import com.skt.tmap.TMapPoint import com.stop.R -import com.stop.RouteNavGraphDirections import com.stop.alarm.SoundService import com.stop.databinding.FragmentMapBinding import com.stop.model.Location @@ -126,23 +126,13 @@ class MapFragment : Fragment(), MapHandler { } binding.homePanel.viewPanelStart.setOnClickListener { - findNavController().apply { - setGraph(R.navigation.route_nav_graph) - navigate( - RouteNavGraphDirections.actionGlobalRouteFragment() - .setStart(placeSearchViewModel.panelInfo) - ) - } + val bundle = bundleOf("start" to placeSearchViewModel.panelInfo) + findNavController().navigate(R.id.action_mapFragment_to_route_nav_graph, bundle) } binding.homePanel.viewPanelEnd.setOnClickListener { - findNavController().apply { - setGraph(R.navigation.route_nav_graph) - navigate( - RouteNavGraphDirections.actionGlobalRouteFragment() - .setEnd(placeSearchViewModel.panelInfo) - ) - } + val bundle = bundleOf("end" to placeSearchViewModel.panelInfo) + findNavController().navigate(R.id.action_mapFragment_to_route_nav_graph, bundle) } } diff --git a/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt b/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt index 58059a45..62e4892b 100644 --- a/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt +++ b/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt @@ -56,8 +56,7 @@ class RouteFragment : Fragment() { backPressedCallback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { val navController = findNavController() - navController.setGraph(R.navigation.nav_graph) - navController.popBackStack(R.id.action_global_mapFragment, false) + navController.popBackStack(R.id.mapFragment, false) } } requireActivity().onBackPressedDispatcher.addCallback(this, backPressedCallback) diff --git a/presentation/src/main/java/com/stop/ui/routedetail/RouteDetailFragment.kt b/presentation/src/main/java/com/stop/ui/routedetail/RouteDetailFragment.kt index 38b012d3..70807e18 100644 --- a/presentation/src/main/java/com/stop/ui/routedetail/RouteDetailFragment.kt +++ b/presentation/src/main/java/com/stop/ui/routedetail/RouteDetailFragment.kt @@ -6,7 +6,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.view.GravityCompat -import androidx.navigation.findNavController import androidx.navigation.fragment.findNavController import com.stop.R import androidx.navigation.navGraphViewModels @@ -74,8 +73,7 @@ class RouteDetailFragment : Fragment(), RouteDetailHandler { binding.imageViewClose.setOnClickListener { findNavController().apply { - setGraph(R.navigation.nav_graph) - popBackStack(R.id.action_global_mapFragment, false) + popBackStack(R.id.mapFragment, false) requireActivity().viewModelStore.clear() } } diff --git a/presentation/src/main/res/navigation/nav_graph.xml b/presentation/src/main/res/navigation/nav_graph.xml index c9bbbb12..40351cef 100644 --- a/presentation/src/main/res/navigation/nav_graph.xml +++ b/presentation/src/main/res/navigation/nav_graph.xml @@ -5,14 +5,26 @@ android:id="@+id/nav_graph" app:startDestination="@id/mapFragment"> - - + + + + @@ -36,9 +48,49 @@ app:destination="@id/mapFragment" /> - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - \ No newline at end of file From bc5d96f5ba7ee12184e19919897c543e28a0e7e5 Mon Sep 17 00:00:00 2001 From: DoDoBest Date: Tue, 13 Dec 2022 13:45:45 +0900 Subject: [PATCH 7/7] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=B3=80=EC=88=98=20=EC=84=A0=EC=96=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/stop/ui/route/RouteFragment.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt b/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt index 46648160..4de88251 100644 --- a/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt +++ b/presentation/src/main/java/com/stop/ui/route/RouteFragment.kt @@ -55,8 +55,7 @@ class RouteFragment : Fragment() { backPressedCallback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { - val navController = findNavController() - navController.popBackStack(R.id.mapFragment, false) + findNavController().popBackStack(R.id.mapFragment, false) } } requireActivity().onBackPressedDispatcher.addCallback(this, backPressedCallback) @@ -100,9 +99,6 @@ class RouteFragment : Fragment() { navController.setGraph(R.navigation.nav_graph) navController.popBackStack(R.id.mapFragment, false) } - binding.imageViewResearch.setOnClickListener { - routeViewModel.patchRoute() - } } private fun setRecyclerView() { @@ -178,9 +174,9 @@ class RouteFragment : Fragment() { val dialogView = layoutInflater.inflate(R.layout.dialog_progress, null) alertDialog = AlertDialog.Builder(requireContext()) - .setView(dialogView) - .setCancelable(false) - .create() + .setView(dialogView) + .setCancelable(false) + .create() alertDialog.window?.setBackgroundDrawableResource(R.color.transparent) routeViewModel.alertDialog = alertDialog }