Skip to content

Commit

Permalink
feat: 홈화면 지도에서 안심구역 표시
Browse files Browse the repository at this point in the history
  • Loading branch information
kyujin0911 committed Jun 20, 2024
1 parent dce88a9 commit 8626a40
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.ac.tukorea.whereareu.data.api.nok

import kr.ac.tukorea.whereareu.data.model.ResponseBody
import kr.ac.tukorea.whereareu.data.model.nok.home.SafeAreaInfoResponse
import kr.ac.tukorea.whereareu.data.model.nok.safearea.GetCoordRequest
import kr.ac.tukorea.whereareu.data.model.nok.safearea.response.GetSafeAreaGroupResponse
import kr.ac.tukorea.whereareu.data.model.nok.safearea.response.GetSafeAreaResponse
Expand Down Expand Up @@ -30,4 +31,7 @@ interface SafeAreaService {

@POST("address/conversion")
suspend fun getCoord(@Body request: GetCoordRequest): Response<ResponseBody<GetCoordResponse>>

@GET("safeArea/info/all")
suspend fun getSafeAreaInfoAll(@Query("dementiaKey") dementiaKey: String): Response<ResponseBody<SafeAreaInfoResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kr.ac.tukorea.whereareu.data.model.nok.home

data class SafeArea(
val areaName: String,
val latitude: Double,
val longitude: Double,
val radius: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kr.ac.tukorea.whereareu.data.model.nok.home

data class SafeAreaInfoResponse(
val safeAreas: List<SafeArea>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.ac.tukorea.whereareu.data.repository.nok.safearea

import kr.ac.tukorea.whereareu.data.model.nok.home.SafeAreaInfoResponse
import kr.ac.tukorea.whereareu.data.model.nok.safearea.GetCoordRequest
import kr.ac.tukorea.whereareu.data.model.nok.safearea.response.GetSafeAreaGroupResponse
import kr.ac.tukorea.whereareu.data.model.nok.safearea.response.GetSafeAreaResponse
Expand All @@ -16,6 +17,8 @@ interface SafeAreaRepository {
suspend fun registerSafeAreaGroup(request: RegisterSafeAreaGroupRequest): NetworkResult<RegisterSafeAreaGroupResponse>
suspend fun fetchSafeAreaAll(dementiaKey: String): NetworkResult<GetSafeAreaResponse>

suspend fun fetchSafeAreaInfoAll(dementiaKey: String): NetworkResult<SafeAreaInfoResponse>

suspend fun fetchSafeAreaGroup(dementiaKey: String, groupKey: String): NetworkResult<GetSafeAreaGroupResponse>

suspend fun fetchCoord(request: GetCoordRequest): NetworkResult<GetCoordResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kr.ac.tukorea.whereareu.data.repository.nok.safearea

import kr.ac.tukorea.whereareu.data.api.nok.SafeAreaService
import kr.ac.tukorea.whereareu.data.model.ResponseBody
import kr.ac.tukorea.whereareu.data.model.nok.home.SafeAreaInfoResponse
import kr.ac.tukorea.whereareu.data.model.nok.safearea.GetCoordRequest
import kr.ac.tukorea.whereareu.data.model.nok.safearea.response.GetSafeAreaGroupResponse
import kr.ac.tukorea.whereareu.data.model.nok.safearea.response.GetSafeAreaResponse
Expand Down Expand Up @@ -29,6 +30,10 @@ class SafeAreaRepositoryImpl @Inject constructor(
return handleApi({api.getSafeAreaAll(dementiaKey)}) { response: ResponseBody<GetSafeAreaResponse> -> response.result}
}

override suspend fun fetchSafeAreaInfoAll(dementiaKey: String): NetworkResult<SafeAreaInfoResponse> {
return handleApi({api.getSafeAreaInfoAll(dementiaKey)}) { response: ResponseBody<SafeAreaInfoResponse> -> response.result}
}

override suspend fun fetchSafeAreaGroup(
dementiaKey: String,
groupKey: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import com.naver.maps.map.overlay.Marker

data class PredictMetaData(
val markers: MutableList<Marker> = mutableListOf(),
val circleOverlay: CircleOverlay = CircleOverlay()
val circleOverlay: CircleOverlay = CircleOverlay(),
val safeMarkers: MutableList<Marker> = mutableListOf(),
val safeCircleOverlays: MutableList<CircleOverlay> = mutableListOf(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ import com.naver.maps.map.CameraAnimation
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.MapFragment
import com.naver.maps.map.NaverMap
import com.naver.maps.map.NaverMapOptions
import com.naver.maps.map.OnMapReadyCallback
import com.naver.maps.map.overlay.CircleOverlay
import com.naver.maps.map.overlay.Marker
import com.naver.maps.map.overlay.OverlayImage
import com.naver.maps.map.overlay.PathOverlay
import com.naver.maps.map.util.FusedLocationSource
import com.naver.maps.map.util.MarkerIcons
import com.naver.maps.map.widget.LocationButtonView
import com.naver.maps.map.widget.ZoomControlView
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -82,6 +85,7 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
private val tag = "NokMainActivity:"
private val isFirstNavigationEvent = mutableListOf(true, true, true)
private var isRequireStopHomeFragmentJob = true
private lateinit var locationSource: FusedLocationSource
private fun getUpdateLocationJob(duration: Long): Job {
return lifecycleScope.launch {
while (true) {
Expand Down Expand Up @@ -240,6 +244,7 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
naverMap?.moveCamera(CameraUpdate.zoomTo(14.0))

with(safeAreMetaData) {
naverMap?.locationSource = locationSource
binding.bottomSheetTopIv.isVisible = false
isSettingSafeArea = true
settingMarker.isVisible = true
Expand Down Expand Up @@ -692,6 +697,38 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
behavior.state = event.behavior
naverMap?.moveCamera(CameraUpdate.scrollTo(event.coord))
}

is NokHomeViewModel.PredictEvent.FetchSafeArea -> {
event.groupList.forEach {
val latLng = LatLng(it.latitude, it.longitude)
predictMetaData.safeMarkers.add(
Marker().apply {
setMarker(
latLng,
MarkerIcons.YELLOW,
it.areaName,
naverMap
)
}
)
predictMetaData.safeCircleOverlays.add(
CircleOverlay().apply {
radius = it.radius.times(1000)
center = latLng
outlineWidth = 5
outlineColor = ContextCompat.getColor(
this@NokMainActivity,
R.color.deep_yellow
)
color = ContextCompat.getColor(
this@NokMainActivity,
R.color.transparent_yellow
)
map = naverMap
}
)
}
}
}
}

Expand Down Expand Up @@ -823,6 +860,8 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
binding.viewModel = homeViewModel
binding.safeAreaVm = safeAreaViewModel
homeViewModel.fetchUserInfo()
locationSource =
FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE)
initBottomSheet()
initMap()
initNavigator()
Expand All @@ -841,13 +880,15 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
private fun initMap() {
val fm = supportFragmentManager
val mapFragment = fm.findFragmentById(R.id.map_fragment) as MapFragment?
?: MapFragment.newInstance().also {
?: MapFragment.newInstance(NaverMapOptions().locationButtonEnabled(false)).also {
fm.beginTransaction().add(R.id.map_fragment, it).commit()
}
mapFragment.getMapAsync { map ->
map.uiSettings.isZoomControlEnabled = false
//val locationButton: LocationButtonView = findViewById(R.id.navermap_location_button)
val zoomControlView: ZoomControlView = findViewById(R.id.zoom)
zoomControlView.map = map
//locationButton.map = map
naverMap = map
}
}
Expand Down Expand Up @@ -921,6 +962,17 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
}
}

if (destination.id != R.id.nokHomeFragment){
predictMetaData.safeMarkers.forEach {
it.map = null
}
predictMetaData.safeCircleOverlays.forEach {
it.map = null
}
predictMetaData.safeMarkers.clear()
predictMetaData.safeCircleOverlays.clear()
}

if (destination.id !in listOf(
R.id.safeAreaFragment,
R.id.safeAreaDetailFragment,
Expand Down Expand Up @@ -1063,6 +1115,9 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
const val MEANINGFUL_PLACE = 0
const val HOME = 1
const val SAFE_AREA = 2

private const val LOCATION_PERMISSION_REQUEST_CODE = 1000

}

private fun removeMeaningfulPlaceMarker() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kr.ac.tukorea.whereareu.presentation.nok.home

import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.fragment.app.activityViewModels
Expand Down Expand Up @@ -93,6 +94,7 @@ class NokHomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home

binding.view = this
binding.viewModel = viewModel
viewModel.fetchSafeAreaAll()
checkLocationPermission()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ import kotlinx.coroutines.launch
import kr.ac.tukorea.whereareu.data.model.DementiaKeyRequest
import kr.ac.tukorea.whereareu.data.model.kakao.address.AddressResponse
import kr.ac.tukorea.whereareu.data.model.nok.home.LocationInfoResponse
import kr.ac.tukorea.whereareu.data.model.nok.home.SafeArea
import kr.ac.tukorea.whereareu.data.model.nok.safearea.SafeAreaGroup
import kr.ac.tukorea.whereareu.data.repository.kakao.KakaoRepositoryImpl
import kr.ac.tukorea.whereareu.data.repository.naver.NaverRepositoryImpl
import kr.ac.tukorea.whereareu.data.repository.nok.home.NokHomeRepositoryImpl
import kr.ac.tukorea.whereareu.data.repository.nok.safearea.SafeAreaRepository
import kr.ac.tukorea.whereareu.data.repository.nok.safearea.SafeAreaRepositoryImpl
import kr.ac.tukorea.whereareu.domain.home.LastLocation
import kr.ac.tukorea.whereareu.domain.home.MeaningfulPlaceInfo
import kr.ac.tukorea.whereareu.domain.home.DementiaStatusInfo
import kr.ac.tukorea.whereareu.domain.home.PoliceStationInfo
import kr.ac.tukorea.whereareu.domain.home.PredictLocation
import kr.ac.tukorea.whereareu.presentation.nok.safearea.SafeAreaViewModel
import kr.ac.tukorea.whereareu.util.network.onError
import kr.ac.tukorea.whereareu.util.network.onException
import kr.ac.tukorea.whereareu.util.network.onFail
Expand All @@ -37,6 +42,7 @@ import kotlin.system.measureTimeMillis
@HiltViewModel
class NokHomeViewModel @Inject constructor(
private val nokHomeRepository: NokHomeRepositoryImpl,
private val safeAreaRepository: SafeAreaRepositoryImpl,
private val naverRepository: NaverRepositoryImpl,
private val kakaoRepository: KakaoRepositoryImpl,
) : ViewModel() {
Expand Down Expand Up @@ -98,6 +104,8 @@ class NokHomeViewModel @Inject constructor(
data class MapView(val behavior: Int, val coord: LatLng) : PredictEvent()

data class StopPredict(val isPredicted: Boolean) : PredictEvent()

data class FetchSafeArea(val groupList: List<SafeArea>): PredictEvent()
}
private val userMeaningfulPlace = mutableListOf<MeaningfulPlaceInfo>()

Expand Down Expand Up @@ -310,4 +318,59 @@ class NokHomeViewModel @Inject constructor(
Log.d("predict exception", it.toString())
}
}

fun fetchSafeAreaAll() {
viewModelScope.launch {
safeAreaRepository.fetchSafeAreaInfoAll(_dementiaKey.value).onSuccess {response ->
if(response.safeAreas.isEmpty()){
return@launch
}
eventPredict(PredictEvent.FetchSafeArea(response.safeAreas))

//val safeAreaList = mutableListOf<SafeArea>()
//val groupNameList = response.safeAreaList.map { it.groupName}.filterNot { it == "notGrouped" }

/*response.safeAreaList.forEach { _safeAreaList ->
val temp = if (_safeAreaList.groupName == "notGrouped") {
_safeAreaList.safeAreas.map { safeArea ->
SafeArea(
"",
_safeAreaList.groupKey,
safeArea.areaKey,
safeArea.areaName,
safeArea.latitude,
safeArea.longitude,
safeArea.radius,
SafeAreaRVA.SAFE_AREA
)
}
} else {
_safeAreaList.safeAreas.map {
SafeArea(
_safeAreaList.groupName,
_safeAreaList.groupKey,
"",
"",
0.0,
0.0,
0,
SafeAreaRVA.SAFE_AREA_GROUP
)
}
}
safeAreaList.addAll(temp)
}
safeAreaList.sortWith(
compareBy(
{it.viewType},
{it.groupName},
{it.areaName}
)
)*/
//savedStateHandle["safeAreaGroupList"] = groupList
//Log.d("safeArea List", safeAreaList.toString())
Log.d("fetchSafeArea", response.toString())
}
}
}
}
5 changes: 4 additions & 1 deletion frontend/app/src/main/res/layout/activity_nok_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
android:id="@+id/map_fragment"
android:name="com.naver.maps.map.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
app:navermap_locationButtonEnabled="false"
/>

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down Expand Up @@ -610,6 +612,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">


<com.naver.maps.map.widget.LogoView
android:id="@+id/navermap_logo"
android:layout_width="wrap_content"
Expand Down

0 comments on commit 8626a40

Please sign in to comment.