Skip to content

Commit

Permalink
#86 fix : 마커 로딩시 로딩 다이얼로그 추가,내 음식점 갯수 제한 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
BENDENG1 committed Dec 13, 2023
1 parent 9a4cf47 commit 6a8c569
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package com.avengers.nibobnebob.presentation.ui.main.home
import android.Manifest
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.ActivityCompat
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.avengers.nibobnebob.R
import com.avengers.nibobnebob.app.App
import com.avengers.nibobnebob.databinding.FragmentHomeBinding
import com.avengers.nibobnebob.presentation.base.BaseFragment
import com.avengers.nibobnebob.presentation.customview.RecommendRestaurantDialog
Expand Down Expand Up @@ -124,6 +122,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),

is HomeEvents.RemoveMarkers -> removeAllMarker()
is HomeEvents.ShowSnackMessage -> showSnackBar(event.msg)

is HomeEvents.ShowLoading -> showLoading(requireContext())
is HomeEvents.DismissLoading -> dismissLoading()
}
}
}
Expand Down Expand Up @@ -269,13 +270,13 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home),
markerList.clear()
}

private fun finishApp(){
private fun finishApp() {
var backPressTime = 0L
requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if(System.currentTimeMillis() - backPressTime <= 2000) {
if (System.currentTimeMillis() - backPressTime <= 2000) {
parentViewModel.finishApp()
} else{
} else {
backPressTime = System.currentTimeMillis()
showToastMessage("뒤로가기 버튼을 한 번 더 누르면 종료됩니다.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.lang.Math.pow
Expand Down Expand Up @@ -74,6 +76,9 @@ sealed class HomeEvents {
data class ShowSnackMessage(
val msg: String
) : HomeEvents()

data object ShowLoading : HomeEvents()
data object DismissLoading : HomeEvents()
}

@HiltViewModel
Expand Down Expand Up @@ -220,7 +225,9 @@ class HomeViewModel @Inject constructor(
radius = uiState.value.cameraRadius.toString(),
longitude = uiState.value.cameraLongitude.toString(),
latitude = uiState.value.cameraLatitude.toString()
).onEach {
).onStart {
_events.emit(HomeEvents.ShowLoading)
}.onEach {
_events.emit(HomeEvents.RemoveMarkers)
when (it) {
is BaseState.Success -> {
Expand All @@ -240,12 +247,18 @@ class HomeViewModel @Inject constructor(
}
}
_events.emit(HomeEvents.SetNewMarkers)
}.onCompletion {
_events.emit(HomeEvents.DismissLoading)
}.launchIn(viewModelScope)

}

private fun myRestaurantList() {
myRestaurantListUseCase().onEach {
myRestaurantListUseCase(
limit = 500
).onStart {
_events.emit(HomeEvents.ShowLoading)
}.onEach {
_events.emit(HomeEvents.RemoveMarkers)
when (it) {
is BaseState.Success -> {
Expand All @@ -266,15 +279,19 @@ class HomeViewModel @Inject constructor(
is BaseState.Error -> _events.emit(HomeEvents.ShowSnackMessage(ERROR_MSG))
}
_events.emit(HomeEvents.SetNewMarkers)
}.onCompletion {
_events.emit(HomeEvents.DismissLoading)
}.launchIn(viewModelScope)
}

private fun userRestaurantList() {
restaurantRepository.filterRestaurantList(
_uiState.value.curFilter,
"${_uiState.value.curLatitude} ${_uiState.value.curLongitude}",
50000
).onEach {
filter = _uiState.value.curFilter,
location = "${_uiState.value.curLatitude} ${_uiState.value.curLongitude}",
radius = 50000
).onStart {
_events.emit(HomeEvents.ShowLoading)
}.onEach {
_events.emit(HomeEvents.RemoveMarkers)
when (it) {
is BaseState.Success -> {
Expand All @@ -291,6 +308,8 @@ class HomeViewModel @Inject constructor(
is BaseState.Error -> _events.emit(HomeEvents.ShowSnackMessage(ERROR_MSG))
}
_events.emit(HomeEvents.SetNewMarkers)
}.onCompletion {
_events.emit(HomeEvents.DismissLoading)
}.launchIn(viewModelScope)
}

Expand Down

0 comments on commit 6a8c569

Please sign in to comment.