Skip to content

Commit

Permalink
Merge pull request #89 from Korea-Certified-Store/feature/re-search-b…
Browse files Browse the repository at this point in the history
…y-keyword-button(#82)

현위치에서 키워드로 재검색, 검색 시 필터 초기화
  • Loading branch information
jeeminimini authored Feb 21, 2024
2 parents 2f4cb13 + a3bb0db commit f814f4a
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ fun InitScreen(
onCallStoreChanged: (String) -> Unit,
onSplashScreenShowAble: (Boolean) -> Unit,
navController: NavHostController,
searchText: String?,
isFirstRun: Boolean,
isOnboardingScreenShowAble: Boolean,
onOnboardingScreenShowAble: (Boolean) -> Unit,
Expand All @@ -29,7 +28,6 @@ fun InitScreen(
onCallStoreChanged,
onSplashScreenShowAble,
navController,
searchText,
mapViewModel
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.example.presentation.ui.map.MapViewModel
import com.example.presentation.ui.navigation.Screen
import com.example.presentation.ui.search.SearchScreen
import com.example.presentation.ui.theme.Android_KCSTheme
import com.example.presentation.util.MainConstants.SEARCH_KEY
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -64,16 +63,10 @@ class MainActivity : ComponentActivity() {
composable(
route = Screen.Main.route
) {
val searchText = remember {
navController.previousBackStackEntry?.savedStateHandle?.get<String>(
SEARCH_KEY
)
}
InitScreen(
onCallStoreChanged,
onSplashScreenShowAble,
navController,
searchText,
isFirstRun,
isOnboardingScreenShowAble,
onOnboardingScreenShowAble,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import com.example.domain.model.map.ShowMoreCount
Expand All @@ -22,12 +23,15 @@ import com.example.presentation.ui.map.MapViewModel
import com.example.presentation.ui.map.NaverMapScreen
import com.example.presentation.ui.map.call.StoreCallDialog
import com.example.presentation.ui.map.filter.FilterComponent
import com.example.presentation.ui.map.filter.FilterViewModel
import com.example.presentation.ui.map.list.StoreListBottomSheet
import com.example.presentation.ui.map.reload.ReloadOrShowMoreButton
import com.example.presentation.ui.map.summary.DimScreen
import com.example.presentation.ui.map.summary.StoreSummaryBottomSheet
import com.example.presentation.ui.search.ReSearchButtonComponent
import com.example.presentation.ui.search.StoreSearchComponent
import com.example.presentation.util.MainConstants
import com.example.presentation.util.MainConstants.SEARCH_KEY
import com.example.presentation.util.MainConstants.UN_MARKER
import com.example.presentation.util.MapScreenType
import com.naver.maps.map.compose.ExperimentalNaverMapApi
Expand All @@ -38,8 +42,8 @@ fun MainScreen(
onCallStoreChanged: (String) -> Unit,
onSplashScreenShowAble: (Boolean) -> Unit,
navController: NavHostController,
searchText: String?,
mapViewModel: MapViewModel
mapViewModel: MapViewModel,
filterViewModel : FilterViewModel = hiltViewModel()
) {
val (clickedStoreInfo, onStoreInfoChanged) = remember {
mutableStateOf(
Expand Down Expand Up @@ -69,10 +73,6 @@ fun MainScreen(
mutableStateOf(false)
}

val (isKindFilterClicked, onKindFilterChanged) = remember { mutableStateOf(false) }
val (isGreatFilterClicked, onGreatFilterChanged) = remember { mutableStateOf(false) }
val (isSafeFilterClicked, onSafeFilterChanged) = remember { mutableStateOf(false) }

val (screenCoordinate, onScreenChanged) = remember {
mutableStateOf(
ScreenCoordinate(
Expand Down Expand Up @@ -117,6 +117,8 @@ fun MainScreen(

val (isReloadOrShowMoreShowAble, onReloadOrShowMoreChanged) = remember { mutableStateOf(false) }

val (isReSearchButtonClicked, onReSearchButtonChanged) = remember { mutableStateOf(false) }

val (isScreenCoordinateChanged, onGetNewScreenCoordinateChanged) = remember {
mutableStateOf(
false
Expand All @@ -132,6 +134,14 @@ fun MainScreen(
}
val (isBackPressed, onBackPressedChanged) = remember { mutableStateOf(false) }

val isSearchTextExist = navController.previousBackStackEntry?.savedStateHandle?.contains(
SEARCH_KEY
) ?: false

val searchText = navController.previousBackStackEntry?.savedStateHandle?.get<String>(
SEARCH_KEY
)

NaverMapScreen(
isMarkerClicked,
onBottomSheetChanged,
Expand Down Expand Up @@ -161,38 +171,45 @@ fun MainScreen(
isBackPressed,
onBackPressedChanged,
mapViewModel,
navController
navController,
isReSearchButtonClicked
)

if (isReloadOrShowMoreShowAble) {
ReloadOrShowMoreButton(
isMarkerClicked,
currentSummaryInfoHeight,
isMapGestured,
onShowMoreCountChanged,
onReloadButtonChanged,
onMarkerChanged,
onBottomSheetChanged,
isLoading,
showMoreCount,
mapViewModel
)
if (isSearchTextExist) {
ReSearchButtonComponent(
isMarkerClicked,
currentSummaryInfoHeight,
isMapGestured,
onReSearchButtonChanged,
onMarkerChanged,
onBottomSheetChanged,
isLoading,
)
} else {
ReloadOrShowMoreButton(
isMarkerClicked,
currentSummaryInfoHeight,
isMapGestured,
onShowMoreCountChanged,
onReloadButtonChanged,
onMarkerChanged,
onBottomSheetChanged,
isLoading,
showMoreCount,
mapViewModel
)
}
}

StoreSearchComponent(
searchText,
onSearchComponentChanged,
onSearchTerminationButtonChanged
onSearchTerminationButtonChanged,
mapViewModel
)

FilterComponent(
isKindFilterClicked,
onKindFilterChanged,
isGreatFilterClicked,
onGreatFilterChanged,
isSafeFilterClicked,
onSafeFilterChanged,
mapViewModel,
onFilterStateChanged
)

Expand Down Expand Up @@ -238,8 +255,20 @@ fun MainScreen(
onCallDialogChanged(false)
}

val mapCenterCoordinate by mapViewModel.mapCenterCoordinate.collectAsStateWithLifecycle()
if (isReSearchButtonClicked && isScreenCoordinateChanged) {
filterViewModel.updateIsFilteredMarker(false)
mapViewModel.searchStore(
mapCenterCoordinate.longitude,
mapCenterCoordinate.latitude,
searchText ?: ""
)
onReSearchButtonChanged(false)
onGetNewScreenCoordinateChanged(false)
}

if ((isReloadButtonClicked && isScreenCoordinateChanged)) {
mapViewModel.updateIsFilteredMarker(false)
filterViewModel.updateIsFilteredMarker(false)
onErrorToastChanged("")
mapViewModel.getStoreDetail(
nwLong = screenCoordinate.northWest.longitude,
Expand Down Expand Up @@ -277,14 +306,15 @@ fun MainScreen(
@Composable
fun PressBack(
mapViewModel: MapViewModel,
onBackPressedChanged: (Boolean) -> Unit
onBackPressedChanged: (Boolean) -> Unit,
) {
val mapScreenType by mapViewModel.mapScreenType.collectAsStateWithLifecycle()
val context = LocalContext.current
var backPressedTime = 0L

BackHandler {
if (mapScreenType == MapScreenType.SEARCH) {
mapViewModel.updateIsSearchTerminated(true)
onBackPressedChanged(true)
mapViewModel.updateMapScreenType(MapScreenType.MAIN)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import com.example.domain.util.Resource
import com.example.presentation.model.Coordinate
import com.example.presentation.model.LocationTrackingButton
import com.example.presentation.util.MainConstants.FAIL_TO_LOAD_DATA
import com.example.presentation.util.MainConstants.GREAT_STORE
import com.example.presentation.util.MainConstants.INITIALIZE_ABLE
import com.example.presentation.util.MainConstants.KIND_STORE
import com.example.presentation.util.MainConstants.SAFE_STORE
import com.example.presentation.util.MapScreenType
import com.example.presentation.util.UiState
import com.naver.maps.geometry.LatLng
Expand All @@ -38,8 +35,6 @@ class MapViewModel @Inject constructor(
private val _ableToShowSplashScreen = MutableStateFlow(true)
val ableToShowSplashScreen: StateFlow<Boolean> = _ableToShowSplashScreen

private val filterSet = mutableSetOf<String>()

private val _storeDetailModelData =
MutableStateFlow<UiState<List<List<StoreDetail>>>>(UiState.Loading)
val storeDetailModelData: StateFlow<UiState<List<List<StoreDetail>>>> =
Expand Down Expand Up @@ -80,9 +75,6 @@ class MapViewModel @Inject constructor(
private val _isSearchTerminated = MutableStateFlow(false)
val isSearchTerminated: StateFlow<Boolean> = _isSearchTerminated

private val _isFilteredMarker = MutableStateFlow(false)
val isFilteredMarker: StateFlow<Boolean> = _isFilteredMarker

fun showMoreStore(count: Int) {
val newItem: List<StoreDetail> = when (val uiState = _storeDetailModelData.value) {
is UiState.Success -> uiState.data.getOrNull(count) ?: emptyList()
Expand All @@ -97,19 +89,6 @@ class MapViewModel @Inject constructor(
_ableToShowSplashScreen.value = false
}

fun getFilterSet(): Set<String> {
return if (filterSet.isEmpty()) setOf(SAFE_STORE, GREAT_STORE, KIND_STORE)
else filterSet.toSet()
}

fun updateFilterSet(certificationName: String, isClicked: Boolean) {
if (isClicked) {
filterSet.add(certificationName)
} else {
filterSet.remove(certificationName)
}
}

fun setLocationTrackingMode(): LocationTrackingButton {
return if (isLocationPermissionGranted.value) {
LocationTrackingButton.FOLLOW
Expand Down Expand Up @@ -243,8 +222,4 @@ class MapViewModel @Inject constructor(
fun updateIsSearchTerminated(isTerminated: Boolean) {
_isSearchTerminated.value = isTerminated
}

fun updateIsFilteredMarker(isFilteredMarker: Boolean) {
_isFilteredMarker.value = isFilteredMarker
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import com.example.domain.model.map.ShowMoreCount
Expand All @@ -28,6 +29,7 @@ import com.example.presentation.model.LocationTrackingButton
import com.example.presentation.model.ScreenCoordinate
import com.example.presentation.model.StoreDetail
import com.example.presentation.model.StoreType
import com.example.presentation.ui.map.filter.FilterViewModel
import com.example.presentation.ui.map.location.CurrentLocationComponent
import com.example.presentation.ui.map.marker.StoreMarker
import com.example.presentation.ui.map.reload.setReloadButtonBottomPadding
Expand Down Expand Up @@ -91,7 +93,9 @@ fun NaverMapScreen(
isBackPressed: Boolean,
onBackPressedChanged: (Boolean) -> Unit,
mapViewModel: MapViewModel,
navController: NavHostController
navController: NavHostController,
isReSearchButtonClicked: Boolean,
filterViewModel: FilterViewModel = hiltViewModel()
) {
val cameraPositionState = rememberCameraPositionState {}

Expand Down Expand Up @@ -157,7 +161,7 @@ fun NaverMapScreen(
if (isInitializationLocation && mapViewModel.ableToShowSplashScreen.value) {
onSplashScreenShowAble(false)
}
mapViewModel.updateIsFilteredMarker(true)
filterViewModel.updateIsFilteredMarker(true)
onLoadingChanged(false)
onCurrentMapChanged(false)
onShowMoreCountChanged(ShowMoreCount(0, state.data.size))
Expand Down Expand Up @@ -187,11 +191,12 @@ fun NaverMapScreen(

when (val state = searchStore) {
is UiState.Loading -> {
// Todo : 검색 시 로딩 뷰 구현
onLoadingChanged(true)
}

is UiState.Success -> {
mapViewModel.updateIsFilteredMarker(true)
onLoadingChanged(false)
filterViewModel.updateIsFilteredMarker(true)
onCurrentMapChanged(false)
onReloadOrShowMoreChanged(false)

Expand Down Expand Up @@ -221,7 +226,8 @@ fun NaverMapScreen(
}
}

val isFilteredMarker by mapViewModel.isFilteredMarker.collectAsStateWithLifecycle()
val isFilteredMarker by filterViewModel.isFilteredMarker.collectAsStateWithLifecycle()

if (isFilteredMarker) {
FilteredMarkers(
mapViewModel,
Expand All @@ -248,6 +254,15 @@ fun NaverMapScreen(
onLocationButtonChanged(LocationTrackingButton.NO_FOLLOW)
}
}
if (isReSearchButtonClicked) {
mapViewModel.updateMapCenterCoordinate(
Coordinate(
cameraPositionState.position.target.latitude,
cameraPositionState.position.target.longitude
)
)
onGetNewScreenCoordinateChanged(true)
}
if (isReloadButtonClicked) {
GetScreenCoordinate(cameraPositionState, onScreenChanged)
onGetNewScreenCoordinateChanged(true)
Expand All @@ -260,7 +275,9 @@ fun NaverMapScreen(
)
)
mapViewModel.updateMapZoomLevel(cameraPositionState.position.zoom)
mapViewModel.updateMapScreenType(MapScreenType.MAIN)
navController.navigate(Screen.Search.route)
filterViewModel.updateAllFilterUnClicked()
onSearchComponentChanged(false)
}
if (isBackPressed) {
Expand Down Expand Up @@ -320,13 +337,14 @@ fun FilteredMarkers(
onStoreInfoChanged: (StoreDetail) -> Unit,
clickedMarkerId: Long,
onMarkerChanged: (Long) -> Unit,
filterViewModel: FilterViewModel = hiltViewModel()
) {
val storeDetailData by mapViewModel.flattenedStoreDetailList.collectAsStateWithLifecycle()
storeDetailData.filter { info ->
mapViewModel.getFilterSet().intersect(info.certificationName.toSet()).isNotEmpty()
filterViewModel.getFilterSet().intersect(info.certificationName.toSet()).isNotEmpty()
}.forEach { info ->
val storeType =
when (mapViewModel.getFilterSet().intersect(info.certificationName.toSet())
when (filterViewModel.getFilterSet().intersect(info.certificationName.toSet())
.last()) {
KIND_STORE -> StoreType.KIND
GREAT_STORE -> StoreType.GREAT
Expand Down Expand Up @@ -496,7 +514,8 @@ private fun CheckSearchTerminationButtonClicked(
onSearchTerminationButtonChanged: (Boolean) -> Unit,
onReloadButtonChanged: (Boolean) -> Unit,
mapCenterCoordinate: Coordinate,
mapZoomLevel: Double
mapZoomLevel: Double,
filterViewModel: FilterViewModel = hiltViewModel()
) {
if (isSearchTerminationButtonClicked) {
mapViewModel.updateMapCenterCoordinate(
Expand All @@ -520,6 +539,7 @@ private fun CheckSearchTerminationButtonClicked(

LaunchedEffect(key1 = isSearchTerminated) {
if (isSearchTerminated) {
filterViewModel.updateAllFilterUnClicked()
movePrevCamera(cameraPositionState, mapCenterCoordinate, mapZoomLevel)
onReloadButtonChanged(true)
mapViewModel.updateIsSearchTerminated(false)
Expand Down
Loading

0 comments on commit f814f4a

Please sign in to comment.