Skip to content

Commit

Permalink
Merge branch 'feat/#179-map-location-search' of https://github.com/SO…
Browse files Browse the repository at this point in the history
…PT-all/35-APPJAM-ANDROID-SPOONY into feat/#179-map-location-search
  • Loading branch information
Hyobeen-Park committed Jan 24, 2025
2 parents 7cd2dd1 + 7067381 commit c5db302
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 512 deletions.
13 changes: 7 additions & 6 deletions app/src/main/java/com/spoony/spoony/core/database/SearchDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.spoony.spoony.core.database

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.spoony.spoony.core.database.entity.SearchEntity
Expand All @@ -26,14 +27,14 @@ interface SearchDao {

// 검색어 추가 시, 최근 6개만 유지하도록 처리
@Transaction
suspend fun addSearchWithLimit(searchEntity: SearchEntity) {
// 검색어 추가
insertSearch(searchEntity)
suspend fun addSearchWithLimit(searchText: String) {
// 검색어 삽입
insertSearch(SearchEntity(text = searchText))

// 총 검색어 수가 6개를 초과하면 오래된 검색어 삭제
val allSearches = getAllSearches() // 모든 검색어 가져오기
// 6개 초과 검색어 삭제
val allSearches = getAllSearches()
if (allSearches.size > 6) {
val excessSearches = allSearches.drop(6) // 초과된 검색어
val excessSearches = allSearches.drop(6)
excessSearches.forEach { deleteSearchById(it.id) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ class MapRepositoryImpl @Inject constructor(

override suspend fun addSearch(searchText: String) =
runCatching {
searchDao.addSearchWithLimit(SearchEntity(text = searchText))
searchDao.addSearchWithLimit(searchText)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.spoony.spoony.presentation.explore.navigation.Explore
import com.spoony.spoony.presentation.explore.navigation.navigateToExplore
import com.spoony.spoony.presentation.map.locationMap.navigation.navigateToLocationMap
import com.spoony.spoony.presentation.map.navigaion.Map
import com.spoony.spoony.presentation.map.navigaion.navigateToMap
import com.spoony.spoony.presentation.map.search.navigation.navigateToMapSearch
Expand All @@ -27,7 +26,7 @@ class MainNavigator(
@Composable get() = navController
.currentBackStackEntryAsState().value?.destination

val startDestination = Map
val startDestination = Map()

val currentTab: MainTab?
@Composable get() = MainTab.find { tab ->
Expand All @@ -47,7 +46,7 @@ class MainNavigator(
}

when (tab) {
MainTab.MAP -> navController.navigateToMap(navOptions)
MainTab.MAP -> navController.navigateToMap(navOptions = navOptions)
MainTab.REGISTER -> navController.navigateToRegister(navOptions)
MainTab.EXPLORE -> navController.navigateToExplore(navOptions)
}
Expand Down Expand Up @@ -108,14 +107,15 @@ class MainNavigator(
locationName: String? = null,
scale: String? = null,
latitude: String? = null,
longitude: String? = null
longitude: String? = null,
) {
navController.navigateToLocationMap(
navController.navigateToMap(
locationId = locationId,
locationName = locationName,
scale = scale,
latitude = latitude,
longitude = longitude
longitude = longitude,
navOptions = navOptions
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.spoony.spoony.core.designsystem.component.snackbar.TextSnackbar
import com.spoony.spoony.core.designsystem.event.LocalSnackBarTrigger
import com.spoony.spoony.presentation.explore.navigation.exploreNavGraph
import com.spoony.spoony.presentation.main.component.MainBottomBar
import com.spoony.spoony.presentation.map.locationMap.navigation.locationMapNavGraph
import com.spoony.spoony.presentation.map.navigaion.mapNavGraph
import com.spoony.spoony.presentation.map.search.navigation.mapSearchNavGraph
import com.spoony.spoony.presentation.placeDetail.navigation.placeDetailNavGraph
Expand Down Expand Up @@ -145,13 +144,6 @@ fun MainScreen(
)
}
)

locationMapNavGraph(
paddingValues = paddingValues,
navigateToPlaceDetail = navigator::navigateToPlaceDetail,
navigateToExplore = navigator::navigateToExplore,
navigateUp = navigator::navigateUp
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum class MainTab(
selectedIconResource = R.drawable.ic_map_main400_24,
unselectedIconResource = R.drawable.ic_map_gray400_24,
label = "내 지도",
route = Map
route = Map()
),
EXPLORE(
selectedIconResource = R.drawable.ic_explore_main400_24,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.spoony.spoony.presentation.map

import android.view.Gravity
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOut
Expand Down Expand Up @@ -76,6 +75,7 @@ import com.spoony.spoony.presentation.map.model.LocationModel
import io.morfly.compose.bottomsheet.material3.rememberBottomSheetScaffoldState
import io.morfly.compose.bottomsheet.material3.rememberBottomSheetState
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList

@Composable
Expand Down Expand Up @@ -133,7 +133,7 @@ fun MapRoute(
onPlaceItemClick = viewModel::getPlaceInfo,
onPlaceCardClick = navigateToPlaceDetail,
navigateToMapSearch = navigateToMapSearch,
onBackButtonClick = navigateUp
onBackButtonClick = viewModel::resetSelectedPlace
)
}

Expand All @@ -159,7 +159,7 @@ fun MapScreen(
onBackButtonClick: () -> Unit
) {
val sheetState = rememberBottomSheetState(
initialValue = AdvancedSheetState.Collapsed,
initialValue = if(placeList.isNotEmpty()) AdvancedSheetState.Collapsed else AdvancedSheetState.PartiallyExpanded,
defineValues = {
AdvancedSheetState.Collapsed at height(20)
AdvancedSheetState.PartiallyExpanded at height(50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,54 @@ package com.spoony.spoony.presentation.map
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.toRoute
import com.spoony.spoony.core.state.UiState
import com.spoony.spoony.core.util.USER_ID
import com.spoony.spoony.domain.repository.AuthRepository
import com.spoony.spoony.domain.repository.MapRepository
import com.spoony.spoony.domain.repository.PostRepository
import com.spoony.spoony.presentation.map.model.LocationModel
import com.spoony.spoony.presentation.map.navigaion.Map
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class MapViewModel @Inject constructor(
private val postRepository: PostRepository,
private val mapRepository: MapRepository,
private val authRepository: AuthRepository
private val authRepository: AuthRepository,
savedStateHandle: SavedStateHandle,
) : ViewModel() {
private var _state: MutableStateFlow<MapState> = MutableStateFlow(MapState())
val state: StateFlow<MapState>
get() = _state.asStateFlow()

init {
getUserInfo()

with(savedStateHandle.toRoute<Map>()) {
if (locationId == null) return@with

getAddedPlaceListByLocation(locationId = locationId)
_state.update {
it.copy(
locationModel = LocationModel(
placeName = locationName,
placeId = locationId,
scale = scale?.toDouble() ?: state.value.locationModel.scale,
latitude = latitude?.toDouble() ?: state.value.locationModel.latitude,
longitude = longitude?.toDouble() ?: state.value.locationModel.longitude
)
)
}
}
}

fun getPlaceInfo(placeId: Int) {
Expand All @@ -57,7 +77,9 @@ class MapViewModel @Inject constructor(
it.copy(
placeCount = response.count,
addedPlaceList = if (response.count == 0) {
UiState.Empty
UiState.Success(
response.placeList.toImmutableList()
)
} else {
UiState.Success(
response.placeList.toImmutableList()
Expand Down Expand Up @@ -85,7 +107,9 @@ class MapViewModel @Inject constructor(
_state.update {
it.copy(
addedPlaceList = if (response.isEmpty()) {
UiState.Empty
UiState.Success(
response.toImmutableList()
)
} else {
UiState.Success(
response.toImmutableList()
Expand Down
Loading

0 comments on commit c5db302

Please sign in to comment.