Skip to content

Commit

Permalink
Blur background when working houts section is expanded (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriisurzhykov authored May 31, 2024
2 parents 4796f04 + 912c0bd commit df16a26
Showing 1 changed file with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
Expand Down Expand Up @@ -77,17 +78,34 @@ internal fun LocationDetails(
modifier: Modifier = Modifier
) {
val state: State by viewModel.detailsResponse.collectAsStateWithLifecycle(lifecycleOwner = androidx.compose.ui.platform.LocalLifecycleOwner.current)
BackgroundImage(modifier = Modifier.fillMaxSize())
var blurContent by remember { mutableStateOf(false) }
BackgroundImage(blurContent = blurContent, modifier = Modifier.fillMaxSize())
if (state != State.None) {
Content(state = state, modifier = modifier.fillMaxSize())
Content(state = state, modifier = modifier.fillMaxSize()) { expanded ->
blurContent = expanded
}
}
}

@Composable
internal fun Content(state: State, modifier: Modifier = Modifier) {
fun BackgroundImage(blurContent: Boolean, modifier: Modifier = Modifier) {
AsyncImage(
model = R.drawable.screen_background,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = if (blurContent) modifier.blur(radiusX = 15.dp, radiusY = 15.dp) else modifier
)
}

@Composable
internal fun Content(
state: State,
modifier: Modifier = Modifier,
onExpand: (Boolean) -> Unit = {}
) {
Column(modifier = modifier) {
if (state is State.Success && state.location != null) {
LocationDetailsMain(state.location)
LocationDetailsMain(state.location, onExpand = onExpand)
}
if (state is State.Loading) {
CircularProgressIndicator(
Expand All @@ -96,12 +114,12 @@ internal fun Content(state: State, modifier: Modifier = Modifier) {
.padding(DefaultPadding)
)
if (state.location != null) {
LocationDetailsMain(location = state.location)
LocationDetailsMain(location = state.location, onExpand = onExpand)
}
}
if (state is State.Error) {
if (state.location != null) {
LocationDetailsMain(location = state.location)
LocationDetailsMain(location = state.location, onExpand = onExpand)
}
state.error?.let {
Toast.makeText(LocalContext.current, it.message.orEmpty(), Toast.LENGTH_SHORT)
Expand All @@ -112,7 +130,7 @@ internal fun Content(state: State, modifier: Modifier = Modifier) {
}

@Composable
internal fun LocationDetailsMain(location: Location) {
internal fun LocationDetailsMain(location: Location, onExpand: (Boolean) -> Unit = {}) {
Text(
text = location.locationName,
style = TextStyle(
Expand All @@ -126,7 +144,7 @@ internal fun LocationDetailsMain(location: Location) {
)

Box(modifier = Modifier.fillMaxSize()) {
OperatingHoursBox(location = location)
OperatingHoursBox(location = location, onExpand = onExpand)
Box(
modifier = Modifier
.padding(bottom = 16.dp)
Expand All @@ -138,7 +156,11 @@ internal fun LocationDetailsMain(location: Location) {
}

@Composable
internal fun OperatingHoursBox(location: Location, modifier: Modifier = Modifier) {
internal fun OperatingHoursBox(
location: Location,
modifier: Modifier = Modifier,
onExpand: (Boolean) -> Unit = {}
) {
var expanded by remember { mutableStateOf(false) }
val expandIconAngle = remember { Animatable(0f) }

Expand Down Expand Up @@ -179,6 +201,7 @@ internal fun OperatingHoursBox(location: Location, modifier: Modifier = Modifier
),
onClick = {
expanded = !expanded
onExpand.invoke(expanded)
})
.padding(DefaultPadding),
contentAlignment = Alignment.CenterStart
Expand Down Expand Up @@ -341,16 +364,6 @@ fun LocationStatusTextView(text: String, modifier: Modifier = Modifier) {
)
}

@Composable
fun BackgroundImage(modifier: Modifier = Modifier) {
AsyncImage(
model = R.drawable.screen_background,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier
)
}

@Composable
fun WorkingHourView(workingDay: WorkingDay) {
val textWeight = if (workingDay.weekDay == LocalDate.now().dayOfWeek) {
Expand Down

0 comments on commit df16a26

Please sign in to comment.