diff --git a/app/src/main/java/com/runnect/runnect/data/dto/SearchResultEntity.kt b/app/src/main/java/com/runnect/runnect/data/dto/SearchResultEntity.kt index 76279cc67..38671873c 100644 --- a/app/src/main/java/com/runnect/runnect/data/dto/SearchResultEntity.kt +++ b/app/src/main/java/com/runnect/runnect/data/dto/SearchResultEntity.kt @@ -9,5 +9,4 @@ data class SearchResultEntity( val fullAddress: String, val name: String, val locationLatLng: LatLng?, - val mode: String ) : Parcelable diff --git a/app/src/main/java/com/runnect/runnect/data/repository/DepartureSearchRepositoryImpl.kt b/app/src/main/java/com/runnect/runnect/data/repository/DepartureSearchRepositoryImpl.kt index 93f2801e5..5692ca2aa 100644 --- a/app/src/main/java/com/runnect/runnect/data/repository/DepartureSearchRepositoryImpl.kt +++ b/app/src/main/java/com/runnect/runnect/data/repository/DepartureSearchRepositoryImpl.kt @@ -22,7 +22,6 @@ class DepartureSearchRepositoryImpl @Inject constructor(private val departureSou fullAddress = makeMainAddress(it), name = it.name ?: "", locationLatLng = LatLng(it.noorLat.toDouble(), it.noorLon.toDouble()), - mode = "searchLocation" //현위치, 지도에서 출발과 구분하기 위한 식별자 ) } return changedData diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index 835bd0ebc..641b43cf7 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -43,9 +43,10 @@ import com.runnect.runnect.databinding.BottomsheetRequireCourseNameBinding 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.search.SearchActivity.Companion.EXTRA_DEPARTURE_SET_MODE import com.runnect.runnect.presentation.state.UiState -import com.runnect.runnect.util.multipart.ContentUriRequestBody 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 @@ -77,6 +78,7 @@ class DrawActivity : private lateinit var animDown: Animation private lateinit var animUp: Animation private lateinit var searchResult: SearchResultEntity + private lateinit var departureSetMode: String private lateinit var captureUri: Uri private val coords = mutableListOf() @@ -108,7 +110,10 @@ class DrawActivity : private fun getSearchIntent() { searchResult = - intent.getParcelableExtra(EXTRA_SEARCH_RESULT) ?: throw Exception("데이터가 존재하지 않습니다.") + intent.getParcelableExtra(EXTRA_SEARCH_RESULT) + ?: throw Exception("unknown-search-result") + departureSetMode = intent.getStringExtra(EXTRA_DEPARTURE_SET_MODE) + ?: throw Exception("unknown-departure-set-mode") } private fun initMapView() { @@ -135,17 +140,19 @@ class DrawActivity : setLocationChangedListener() setCameraFinishedListener() } + private fun initMode() { - when (searchResult.mode) { + when (departureSetMode) { "searchLocation" -> initSearchLocationMode() "currentLocation" -> initCurrentLocationMode() "customLocation" -> initCustomLocationMode() } } + private fun initSearchLocationMode() { isSearchLocationMode = true - with(binding){ + with(binding) { tvGuide.isVisible = false btnDraw.text = CREATE_COURSE } @@ -168,6 +175,7 @@ class DrawActivity : } } } + private fun initCurrentLocationMode() { isCurrentLocationMode = true isMarkerAvailable = true @@ -180,6 +188,7 @@ class DrawActivity : hideDeparture() showDrawCourse() } + private fun initCustomLocationMode() { isCustomLocationMode = true @@ -245,6 +254,7 @@ class DrawActivity : val cameraPosition = naverMap.cameraPosition return cameraPosition.target // 중심 좌표 } + private fun setLocationChangedListener() { naverMap.addOnLocationChangeListener { location -> currentLocation = LatLng(location.latitude, location.longitude) @@ -256,7 +266,7 @@ class DrawActivity : //같은 scope 안에 넣었으니 setDepartureLatLng 다음에 drawCourse가 실행되는 것이 보장됨 //이때 isFirstInit의 초기값을 true로 줘서 최초 1회는 실행되게 하고 이후 drawCourse 내에서 isFirstInit 값을 false로 바꿔줌 //뒤의 조건을 안 달아주면 다른 mode에서는 버튼을 클릭하기도 전에 drawCourse()가 돌 거라 안 됨. - if(isFirstInit && isCurrentLocationMode){ + if (isFirstInit && isCurrentLocationMode) { drawCourse(departureLatLng = departureLatLng) } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt index 335e3d1ea..098814066 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt @@ -81,15 +81,6 @@ class SearchActivity : binding.recyclerViewSearch.adapter = searchAdapter } - override fun selectItem(item: SearchResultEntity) { - startActivity( - Intent(this, DrawActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) - putExtra(EXTRA_SEARCH_RESULT, item) //mode == "searchLocation" - } - ) - } - private fun showEmptyView() { with(binding) { ivNoSearchResult.isVisible = true @@ -187,28 +178,26 @@ class SearchActivity : } } - fun startCurrentLocation() { + private fun navigateToCourseDrawScreen(mode: String, searchResult: SearchResultEntity? = null) { startActivity( Intent(this, DrawActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) - putExtra( - EXTRA_SEARCH_RESULT, - SearchResultEntity(fullAddress = "", name = "", locationLatLng = null, mode = "currentLocation") - ) + putExtra(EXTRA_SEARCH_RESULT, searchResult) + putExtra(EXTRA_DEPARTURE_SET_MODE, mode) } ) } - fun startCustomLocation() { - startActivity( - Intent(this, DrawActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) - putExtra( - EXTRA_SEARCH_RESULT, - SearchResultEntity(fullAddress = "", name = "", locationLatLng = null, mode = "customLocation") - ) - } - ) + override fun startSearchLocation(data: SearchResultEntity) { + navigateToCourseDrawScreen(mode = "searchLocation", searchResult = data) + } + + private fun startCurrentLocation() { + navigateToCourseDrawScreen(mode = "currentLocation") + } + + private fun startCustomLocation() { + navigateToCourseDrawScreen(mode = "customLocation") } //키보드 밖 터치 시, 키보드 내림 @@ -228,6 +217,7 @@ class SearchActivity : companion object { const val EXTRA_SEARCH_RESULT = "searchResult" + const val EXTRA_DEPARTURE_SET_MODE = "departureSetMode" } } \ No newline at end of file diff --git a/app/src/main/java/com/runnect/runnect/presentation/search/adapter/SearchAdapter.kt b/app/src/main/java/com/runnect/runnect/presentation/search/adapter/SearchAdapter.kt index 274e80fec..578602ba9 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/search/adapter/SearchAdapter.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/search/adapter/SearchAdapter.kt @@ -18,11 +18,9 @@ class SearchAdapter(private val searchClickListener: OnSearchClick) : fun bindData(data: SearchResultEntity) { binding.searchResultEntity = data - } //여기도 dto 구독해서 ui 바인딩 하는 목적이라 낭비임. - fun bindViews(data: SearchResultEntity) { binding.root.setOnClickListener { - searchClickListener.selectItem(data) //data는 넣었고 구체적인 동작은 오버라이드할 때 + searchClickListener.startSearchLocation(data) } } @@ -35,7 +33,6 @@ class SearchAdapter(private val searchClickListener: OnSearchClick) : override fun onBindViewHolder(holder: SearchResultItemViewHolder, position: Int) { holder.bindData(currentList[position]) - holder.bindViews(currentList[position]) } class Differ : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/com/runnect/runnect/util/callback/OnSearchClick.kt b/app/src/main/java/com/runnect/runnect/util/callback/OnSearchClick.kt index ec73cfa7c..16987554d 100644 --- a/app/src/main/java/com/runnect/runnect/util/callback/OnSearchClick.kt +++ b/app/src/main/java/com/runnect/runnect/util/callback/OnSearchClick.kt @@ -3,5 +3,5 @@ package com.runnect.runnect.util.callback import com.runnect.runnect.data.dto.SearchResultEntity interface OnSearchClick { - fun selectItem(item: SearchResultEntity) + fun startSearchLocation(item: SearchResultEntity) } \ No newline at end of file