Skip to content

Commit

Permalink
#68 feat : Home BottomSheet 로직 구현
Browse files Browse the repository at this point in the history
Co-authored-by: BENDENG1 <[email protected]>
Co-authored-by: yy0ung <[email protected]>
  • Loading branch information
3 people committed Nov 21, 2023
1 parent fdc9e9e commit 1b072a3
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.NavController
import com.avengers.nibobnebob.R
import com.avengers.nibobnebob.databinding.FragmentHomeBinding
import com.avengers.nibobnebob.presentation.base.BaseFragment
import com.avengers.nibobnebob.presentation.ui.main.MainViewModel
import com.avengers.nibobnebob.presentation.util.restaurantSheet
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.LocationTrackingMode
import com.naver.maps.map.MapFragment
Expand Down Expand Up @@ -54,7 +56,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
initMapView()
}

private fun initMapView(){
private fun initMapView() {
val mapFragment = childFragmentManager.findFragmentById(R.id.map_fragment) as MapFragment?
?: MapFragment.newInstance().also {
childFragmentManager.beginTransaction().add(R.id.map_fragment, it).commit()
Expand All @@ -79,7 +81,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
setMarker()
}

private fun setMapListener(){
private fun setMapListener() {

// todo 화면 이동시 리스너
naverMap.addOnCameraChangeListener { reason, animated ->
Expand All @@ -100,10 +102,13 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
private fun initStateObserver() {
repeatOnStarted {
viewModel.uiState.collect {
when(it.locationTrackingState){
when (it.locationTrackingState) {
is TrackingState.TryOn -> requestLocationPermission()
is TrackingState.On -> naverMap.locationTrackingMode = LocationTrackingMode.Follow
is TrackingState.Off -> naverMap.locationTrackingMode = LocationTrackingMode.None
is TrackingState.On -> naverMap.locationTrackingMode =
LocationTrackingMode.Follow

is TrackingState.Off -> naverMap.locationTrackingMode =
LocationTrackingMode.None
}
}
}
Expand All @@ -112,12 +117,15 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
private fun requestLocationPermission() {
var permissionFlag = false
locationPermissionList.forEach { permission ->
permissionFlag = ContextCompat.checkSelfPermission(requireContext(),permission) == PackageManager.PERMISSION_GRANTED
permissionFlag = ContextCompat.checkSelfPermission(
requireContext(),
permission
) == PackageManager.PERMISSION_GRANTED
}

if(permissionFlag){
if (permissionFlag) {
checkLocationIsOn()
}else {
} else {
requestPermissionLauncher.launch(locationPermissionList)
Toast.makeText(requireContext(), "위치권한을 허용해주세요", Toast.LENGTH_SHORT).show()
}
Expand All @@ -126,13 +134,14 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { resultMap ->
val isAllGranted = locationPermissionList.all { resultMap[it] == true}
val isAllGranted = locationPermissionList.all { resultMap[it] == true }
if (isAllGranted) checkLocationIsOn()
else viewModel.trackingOff()
}

private fun checkLocationIsOn() {
val locationManager = requireContext().getSystemService(Context.LOCATION_SERVICE) as LocationManager
val locationManager =
requireContext().getSystemService(Context.LOCATION_SERVICE) as LocationManager
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
viewModel.trackingOn()
} else {
Expand All @@ -141,16 +150,29 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
viewModel.trackingOff()
}
}

// todo markerData model을 정의하여, 파라미터로 해당 데이터를 삽입
private fun setMarker(){
private fun setMarker() {
val marker = Marker()

// example
marker.position = LatLng(37.555594049034,126.96707115682)
marker.position = LatLng(37.555594049034, 126.96707115682)
marker.icon = OverlayImage.fromResource(R.drawable.ic_location_circle)
marker.map = naverMap

marker.setOnClickListener {
restaurantSheet(
context = requireContext(),
restaurantId = 0,
isWish = false,
onClickAddWishRestaurant = ::addWishTest,
onClickAddMyRestaurant = ::addRestaurantTest,
onClickGoReview = ::goReviewTest
).show()

true
}

// todo 마커의 포지션을 정함
// marker.position = LatLng(data.latitude,data.longitude)

Expand All @@ -164,11 +186,24 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
// marker.map = naverMap
}

private fun addWishTest(test: Int, test2: Boolean): Boolean {
return true
}

private fun addRestaurantTest(test: Int) {

}

private fun goReviewTest(test: Int) {

}


}

@BindingAdapter("trackingBtnDrawable")
fun bindTrackingBtnDrawable(btn: ImageButton, state: TrackingState){
when(state){
fun bindTrackingBtnDrawable(btn: ImageButton, state: TrackingState) {
when (state) {
is TrackingState.On -> btn.setImageResource(R.drawable.ic_location_on)
is TrackingState.Off -> btn.setImageResource(R.drawable.ic_location_off)
else -> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.avengers.nibobnebob.presentation.util

import android.content.Context
import android.view.LayoutInflater
import com.avengers.nibobnebob.R
import com.avengers.nibobnebob.databinding.BottomSheetRestaurantBinding
import com.google.android.material.bottomsheet.BottomSheetDialog


internal fun restaurantSheet(
context: Context,
restaurantId: Int,
isWish: Boolean,
onClickAddWishRestaurant: (Int, Boolean) -> Boolean,
onClickAddMyRestaurant: (Int) -> Unit,
onClickGoReview: (Int) -> Unit
): BottomSheetDialog {
val dialog = BottomSheetDialog(context)
val binding = BottomSheetRestaurantBinding.inflate(LayoutInflater.from(context))
dialog.setContentView(binding.root)

var isWishState = isWish

binding.btnAddMyRestaurant.setOnClickListener {
onClickAddMyRestaurant(restaurantId)
}

binding.btnAddWishRestaurant.setOnClickListener {
val result = onClickAddWishRestaurant(restaurantId, isWish)

if (result) {
isWishState = !isWishState

if (isWishState) {
binding.btnAddWishRestaurant.setBackgroundResource(R.drawable.ic_star_full)
} else {
binding.btnAddWishRestaurant.setBackgroundResource(R.drawable.ic_star_border)
}
}
}

binding.btnGoReview.setOnClickListener {
onClickGoReview(restaurantId)
}

return dialog
}
Loading

0 comments on commit 1b072a3

Please sign in to comment.