Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] 출발지 모드 세팅 / Enum Class 활용 #272

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ import com.runnect.runnect.presentation.MainActivity
import com.runnect.runnect.presentation.countdown.CountDownActivity
import com.runnect.runnect.presentation.login.LoginActivity
import com.runnect.runnect.presentation.state.UiState
import com.runnect.runnect.util.multipart.ContentUriRequestBody
import com.runnect.runnect.util.DepartureSetMode
import com.runnect.runnect.util.extension.setActivityDialog
import com.runnect.runnect.util.multipart.ContentUriRequestBody
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.android.synthetic.main.custom_dialog_make_course.view.btn_run
import kotlinx.android.synthetic.main.custom_dialog_make_course.view.btn_storage
Expand Down Expand Up @@ -135,17 +136,21 @@ class DrawActivity :
setLocationChangedListener()
setCameraFinishedListener()
}

private fun initMode() {
when (searchResult.mode) {
"searchLocation" -> initSearchLocationMode()
"currentLocation" -> initCurrentLocationMode()
"customLocation" -> initCustomLocationMode()
DepartureSetMode.SEARCH.mode -> initSearchLocationMode()
DepartureSetMode.CURRENT.mode -> initCurrentLocationMode()
DepartureSetMode.CUSTOM.mode -> initCustomLocationMode()
Comment on lines +142 to +144
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SEARCH, CURRENT, CUSTOM 뒤에 붙는 .mode가 불필요하게 코드를 길어지게 만들어 조금 거슬리는 느낌도 들었습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum 클래스를 사용하면 관련된 상수들을 집합처럼 묶어서 관리할 수 있으므로 가독성이 올라갈 것이라고 생각했습니다!

음 현재 DepartureSetMode 클래스에 mode 라는 변수가 꼭 필요한가요?? 아래처럼 이넘 클래스를 구현하면 중복되는 코드가 줄어들 거 같습니다!

enum class DepartureSetMode {
    SEARCH,
    CURRENT,
    CUSTOM
}

참고로 이 블로그 글을 읽어보면, 상수와 관련된 변수나 함수의 관리를 일원화 할 수 있다는 점에서도 enum class 사용을 권장하는 거 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

링크 감사합니다! 제가 enum 클래스 안에 변수를 만들어준 이유는, 분기처리가 searchResult.mode란 값에 따라 이루어져야 하기 때문입니다. enum 클래스에 어떠한 변수 값 할당 없이 이걸 구현할 수 있나요?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Parcelize
data class SearchResultEntity(
    val fullAddress: String,
    val name: String,
    val locationLatLng: LatLng?,
    val mode: String
) : Parcelable

위의 코드에서 mode 타입을 String 대신에 DepartureSetMode 타입으로 선언하면 되지 않을까 싶습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 예전에 mode라는 속성이 이 data class 안에 같이 포함되는 게 부적절해보인다고 같이 얘기나눴어서 #274 pr에서 걷어냈습니다! 기억나실까요?! 그때의 의견이 지금도 유효한지 궁금합니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 동의합니다! 관련 코드에 대한 리뷰 #274 PR에 코멘트로 남겨뒀습니다!

else -> throw IllegalArgumentException("Unknown mode: ${searchResult.mode}")
}
}


private fun initSearchLocationMode() {
isSearchLocationMode = true

with(binding){
with(binding) {
tvGuide.isVisible = false
btnDraw.text = CREATE_COURSE
}
Expand All @@ -168,6 +173,7 @@ class DrawActivity :
}
}
}

private fun initCurrentLocationMode() {
isCurrentLocationMode = true
isMarkerAvailable = true
Expand All @@ -180,6 +186,7 @@ class DrawActivity :
hideDeparture()
showDrawCourse()
}

private fun initCustomLocationMode() {
isCustomLocationMode = true

Expand Down Expand Up @@ -245,6 +252,7 @@ class DrawActivity :
val cameraPosition = naverMap.cameraPosition
return cameraPosition.target // 중심 좌표
}

private fun setLocationChangedListener() {
naverMap.addOnLocationChangeListener { location ->
currentLocation = LatLng(location.latitude, location.longitude)
Expand All @@ -256,7 +264,7 @@ class DrawActivity :
//같은 scope 안에 넣었으니 setDepartureLatLng 다음에 drawCourse가 실행되는 것이 보장됨
//이때 isFirstInit의 초기값을 true로 줘서 최초 1회는 실행되게 하고 이후 drawCourse 내에서 isFirstInit 값을 false로 바꿔줌
//뒤의 조건을 안 달아주면 다른 mode에서는 버튼을 클릭하기도 전에 drawCourse()가 돌 거라 안 됨.
if(isFirstInit && isCurrentLocationMode){
if (isFirstInit && isCurrentLocationMode) {
drawCourse(departureLatLng = departureLatLng)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.runnect.runnect.util

enum class DepartureSetMode(val mode: String) {
SEARCH("searchLocation"),
CURRENT("currentLocation"),
CUSTOM("customLocation")
}
Loading