Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ fun OndoseeNavHost(
navigateToBack = navController::popBackStack
)
locationManagementScreen(navigateToBack = navController::popBackStack)
addLocationScreen(navigateToBack = navController::popBackStack)
addLocationScreen(
navigateToLocationManagement = navController::navigateToLocationManagement,
navigateToBack = navController::popBackStack
)
weeklyWeatherScreen(
hazeState = hazeState,
navigateToLocation = navController::navigateToLocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LocationsDataSourceImpl @Inject constructor(
locations.updateData {
val builder = it.toBuilder()

if (builder.locationList.size < 4 && builder.locationList.none { it.toDomain() == location }) {
if (builder.locationList.size <= 4 && builder.locationList.none { it.toDomain() == location }) {
builder.addLocation(location.toData())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.ohnalmwo.design_system.component.dialog

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.ohnalmwo.design_system.theme.OndoseeTheme.colors
import com.ohnalmwo.design_system.theme.OndoseeTheme.typography

@Composable
fun OndoseeDialog(
openDialog: Boolean,
title: String,
content: String,
firstText: String,
secondText: String?,
onFirstClick: () -> Unit,
onSecondClick: () -> Unit
) {
var openDialog by remember { mutableStateOf(openDialog) }

if (openDialog) {
Dialog(onDismissRequest = { openDialog = false }) {
Card(
modifier = Modifier.width(280.dp),
shape = RoundedCornerShape(12.dp)
) {
Column(modifier = Modifier.background(colors.BACKGROUND)) {
Column(
modifier = Modifier
.fillMaxWidth()
.background(colors.BACKGROUND)
.padding(top = 16.dp, start = 16.dp, end = 16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = title,
color = colors.THEME_BLACK,
style = typography.textLarge,
fontWeight = FontWeight.Bold,
)
Text(
text = content,
color = colors.SECONDARY,
style = typography.textLarge,
fontWeight = FontWeight.Normal,
)
}
Row(
Modifier
.fillMaxWidth()
.height(64.dp)
.padding(end = 8.dp)
.background(colors.BACKGROUND),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
TextButton(
modifier = Modifier
.weight(1f)
.height(60.dp),
onClick = {
openDialog = false
onFirstClick()
}
) {
Text(
text = firstText,
color = colors.INFORMATION,
style = typography.textLarge,
fontWeight = FontWeight.Bold,
)
}
secondText?.let {
TextButton(
modifier = Modifier
.weight(1f)
.height(60.dp),
onClick = {
openDialog = false
onSecondClick()
}
) {
Text(
text = secondText,
color = colors.INFORMATION,
style = typography.textLarge,
fontWeight = FontWeight.Medium,
)
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ abstract class ColorTheme {
abstract val WHITE: Color

abstract val BACKGROUND: Color
abstract val INFORMATION: Color
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ object DarkColor : ColorTheme() {
override val WHITE = Color(0xFFFFFFFF)

override var BACKGROUND = Color(0xFF171717)
override var INFORMATION = Color(0xFF2573F3)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ object LightColor : ColorTheme() {
override val WHITE = Color(0xFFFFFFFF)

override var BACKGROUND = Color(0xFFF9FAFA)
override var INFORMATION = Color(0xFF007AFF)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.ohnalmwo.design_system.component.button.OndoseeBackButton
import com.ohnalmwo.design_system.component.dialog.OndoseeDialog
import com.ohnalmwo.design_system.component.textfield.SearchTextField
import com.ohnalmwo.design_system.theme.OndoseeTheme.colors
import com.ohnalmwo.location.component.LocationList
Expand All @@ -26,6 +27,7 @@ import kotlinx.coroutines.delay

@Composable
fun AddLocationRoute(
navigateToLocationManagement: () -> Unit,
navigateToBack: () -> Unit,
viewModel: LocationViewModel = hiltViewModel()
) {
Expand All @@ -44,6 +46,7 @@ fun AddLocationRoute(
LaunchedEffect(effect) {
effect.collect { action ->
when (action) {
is LocationEffect.NavigateToLocationManagement -> navigateToLocationManagement()
is LocationEffect.NavigateToBack -> navigateToBack()
else -> Unit
}
Expand All @@ -54,6 +57,8 @@ fun AddLocationRoute(
state = state,
onSearchValueChange = { viewModel.sendEvent(LocationEvent.OnSearchValueChange(it)) },
onListItemClick = viewModel::setSavedLocations,
setDialog = { viewModel.sendEvent(LocationEvent.SetLogoutDialog(it)) },
navigateToLocationManagement = { viewModel.sendEffect(LocationEffect.NavigateToLocationManagement) },
navigateToBack = { viewModel.sendEffect(LocationEffect.NavigateToBack) }
)
}
Expand All @@ -63,6 +68,8 @@ fun AddLocationScreen(
state: LocationState,
onSearchValueChange: (String) -> Unit,
onListItemClick: (LocationInfo) -> Unit,
setDialog: (Boolean) -> Unit,
navigateToLocationManagement: () -> Unit,
navigateToBack: () -> Unit
) {
Column(
Expand Down Expand Up @@ -90,8 +97,28 @@ fun AddLocationScreen(
LocationList(
searchQuery = state.search,
locations = state.locations.locations,
onClick = onListItemClick
onClick = {
if (state.localLocations.size >= 5) setDialog(true)
else onListItemClick(it)
}
)
}
}

if (state.openDialog) {
OndoseeDialog(
openDialog = state.openDialog,
title = "μœ„μΉ˜ λͺ©λ‘μ΄ 가득 μ°ΌμŠ΅λ‹ˆλ‹€.",
content = "λ‹€λ₯Έ μœ„μΉ˜λ₯Ό μ‚­μ œν•˜μ‹œκ² μ–΄μš”?",
firstText = "μœ„μΉ˜ λͺ©λ‘μœΌλ‘œ",
secondText = "μ·¨μ†Œ",
onFirstClick = {
setDialog(false)
navigateToLocationManagement()
},
onSecondClick = {
setDialog(false)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ fun NavController.navigateToAddLocation(navOptions: NavOptions? = null) {
}

fun NavGraphBuilder.addLocationScreen(
navigateToLocationManagement: () -> Unit,
navigateToBack: () -> Unit
) {
composable<Route.Location.AddLocation> {
AddLocationRoute(navigateToBack = navigateToBack)
AddLocationRoute(
navigateToLocationManagement = navigateToLocationManagement,
navigateToBack = navigateToBack
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LocationScreenReducer : Reducer<LocationScreenReducer.LocationState, Locat
data class GetLocationCoordinate(val isLoading: Boolean, val locations: Location) : LocationEvent()
data class GetSavedLocations(val isLoading: Boolean, val localLocations: List<LocationInfo>) : LocationEvent()
data object SetSavedLocations : LocationEvent()
data class SetLogoutDialog(val openDialog: Boolean) : LocationEvent()
data class GetMultipleWeatherSignificant(val isLoading: Boolean, val locationsWeatherSignificant: List<Weather>) : LocationEvent()
data class OnSearchValueChange(val search: String) : LocationEvent()
}
Expand All @@ -30,15 +31,17 @@ class LocationScreenReducer : Reducer<LocationScreenReducer.LocationState, Locat
val locations: Location,
val localLocations: List<LocationInfo>,
val locationsWeatherSignificant: List<Weather>,
val search: String
val search: String,
val openDialog: Boolean,
) : Reducer.ViewState {
companion object {
fun initial() = LocationState(
isLoading = true,
locations = Location.default(),
localLocations = emptyList(),
locationsWeatherSignificant = listOf(Weather.default()),
search = ""
search = "",
openDialog = false
)
}
}
Expand All @@ -63,6 +66,11 @@ class LocationScreenReducer : Reducer<LocationScreenReducer.LocationState, Locat
is LocationEvent.SetSavedLocations -> {
previousState to LocationEffect.NavigateToBack
}
is LocationEvent.SetLogoutDialog -> {
previousState.copy(
openDialog = event.openDialog
) to null
}
is LocationEvent.GetMultipleWeatherSignificant -> {
previousState.copy(
isLoading = event.isLoading,
Expand Down