Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gitsuhyun committed Aug 20, 2024
2 parents b226065 + 8c0d689 commit a46855f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class ListAdapter(private val itemList: List<ListMapModels>,







// ViewHolder 정의
class ListViewHolder(private val binding: ListItemBinding,
private val mapViewModel: MapViewModel)
Expand All @@ -44,7 +40,10 @@ class ListAdapter(private val itemList: List<ListMapModels>,
//거리, 평점, 시간 출력
binding.locationName.text = data.name
binding.distance.text = data.distance
binding.grade.text = "${data.score.toString()}(${data.scoreCount})"

//score를 소수점 두 번째까지 출력
val formattedscore = String.format("%.2f", data.score)
binding.grade.text = "$formattedscore(${data.scoreCount})"
binding.time.text = "${data.openTime} ~ ${data.closeTime}"


Expand All @@ -70,13 +69,14 @@ class ListAdapter(private val itemList: List<ListMapModels>,

Log.d("ListAdapter", "naviButton 클릭됨")

// Fragment의 ViewLifecycleOwner를 올바르게 가져옵니다.
// Fragment의 ViewLifecycleOwner 가져오기
val fragment = (binding.root.context as? androidx.fragment.app.Fragment)
val viewLifecycleOwner = fragment?.viewLifecycleOwner

if (viewLifecycleOwner != null) {
mapViewModel.getCurrentLocation.observe(viewLifecycleOwner, Observer { currentLocation ->
Log.d("ListAdapter", "현재 위치: $currentLocation")

// 목적지의 위도와 경도를 사용해서 길안내
data.latitude?.let { it1 ->
data.longitude?.let { it2 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ListFragment : BaseFragment<FragmentListBinding>({ FragmentListBinding.inf
// 구분선 초기 설정
private var isDecorationAdded = false



//현재 위치 초기값 설정
var currentLatitude: Double = 0.0
var currentLongitude: Double = 0.0

Expand All @@ -54,13 +57,19 @@ class ListFragment : BaseFragment<FragmentListBinding>({ FragmentListBinding.inf

//데이터 로드 함수 호출
loadData(accessToken, currentSortType)


//현재 위치 가져오기
MapLocation.getCurrentLocation(requireContext(), this, requireActivity()) {
location -> Log.d("CurrentLocation", "Latitude: ${location.latitude}, Longitude: ${location.longitude}")
currentLatitude = location.latitude
currentLongitude = location.longitude

mapViewModel.setCurrentLocation(location)

//주소창 텍스트를 현재 주소 기준으로 설정
binding.tvCurrentLocation.text = MapLocation.getGeoCoder(location.latitude, location.longitude, requireContext())

}


Expand Down Expand Up @@ -96,7 +105,6 @@ class ListFragment : BaseFragment<FragmentListBinding>({ FragmentListBinding.inf




//sos 기능
binding.cvSos.setOnClickListener {
showSOSDialog()
Expand All @@ -107,15 +115,13 @@ class ListFragment : BaseFragment<FragmentListBinding>({ FragmentListBinding.inf





}


private fun loadData(accessToken: String?, sortType: String) {


ListRepository.getListStation(accessToken!!, sortType, 0, 100, currentLatitude, currentLongitude)
ListRepository.getListStation(accessToken!!, sortType, 0, 50, currentLatitude, currentLongitude)

{ result ->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class ListInformationActivity : AppCompatActivity() {
if (stationInfo != null) {
binding.LocationName.text = stationInfo.name
binding.Distance.text = stationInfo.distance
binding.Grade.text = "${stationInfo.score}(${stationInfo.scoreCount})"

val formattedscore = String.format("%.2f", stationInfo.score)
binding.Grade.text = "$formattedscore(${stationInfo.scoreCount})"


} else {
Expand Down

0 comments on commit a46855f

Please sign in to comment.