Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💄 Fix UI bug for sessions #308

Merged
merged 1 commit into from
Apr 29, 2024
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 @@ -20,6 +20,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -61,7 +63,27 @@ fun AgendaColumn(
),
shape = RoundedCornerShape(16.dp),
) {
sessions.forEach { uiSession ->
sessions.forEachIndexed { index, uiSession ->
val sessionBeforeIsServiceSession = remember {
derivedStateOf {
if (index > 0) {
sessions[index - 1].isServiceSession
} else {
false
}
}
}

val sessionAfterIsServiceSession = remember {
derivedStateOf {
if (index < sessions.lastIndex) {
sessions[sessions.lastIndex].isServiceSession
} else {
false
}
}
}

if (uiSession.isServiceSession) {
ServiceSessionRow(
uiSession,
Expand All @@ -73,7 +95,9 @@ fun AgendaColumn(
uiSession = uiSession,
onSessionClicked = onSessionClicked,
onSessionBookmarked = onSessionBookmarked,
onApplyForAppClinic = onApplyForAppClinicClicked
onApplyForAppClinic = onApplyForAppClinicClicked,
sessionBeforeIsServiceSession = sessionBeforeIsServiceSession.value,
sessionAfterIsServiceSession = sessionAfterIsServiceSession.value
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.BookmarkAdd
import androidx.compose.material.icons.rounded.BookmarkRemove
Expand All @@ -23,6 +24,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.androidmakers.ui.common.EmojiUtils
Expand Down Expand Up @@ -98,13 +100,32 @@ internal fun SessionRow(
onSessionClicked: (UISession) -> Unit,
onSessionBookmarked: (UISession, Boolean) -> Unit,
onApplyForAppClinic: () -> Unit,
sessionBeforeIsServiceSession: Boolean = false,
sessionAfterIsServiceSession: Boolean = false,
) {
val clipModifier = when {
sessionBeforeIsServiceSession -> Modifier.clip(
shape = RoundedCornerShape(
topStart = 16.dp,
topEnd = 16.dp
)
)
sessionAfterIsServiceSession -> Modifier.clip(
shape = RoundedCornerShape(
bottomStart = 16.dp,
bottomEnd = 16.dp
)
)
else -> Modifier
}

ListItem(
modifier = modifier.clickable(
onClick = {
onSessionClicked.invoke(uiSession)
}
),
)
.then(clipModifier),
colors = ListItemDefaults.colors(
containerColor = backgroundColor(uiSession),
),
Expand Down Expand Up @@ -209,7 +230,12 @@ fun UISession.formattedDuration(): String {
@Preview
@Composable
private fun AgendaRowPreview() {
SessionRow(fakeUiSession, onSessionClicked = {}, onSessionBookmarked = { _,_ -> }, onApplyForAppClinic = {})
SessionRow(
fakeUiSession,
onSessionClicked = {},
onSessionBookmarked = { _, _ -> },
onApplyForAppClinic = {}
)
}

private val fakeUiSession = UISession(
Expand Down
Loading