Skip to content

Commit

Permalink
Include event details (#1402)
Browse files Browse the repository at this point in the history
* Include event details

* Update padding details

---------

Co-authored-by: Ashley Davies <[email protected]>
  • Loading branch information
ashdavies and ashdavies authored Dec 15, 2024
1 parent bcfe6f6 commit 9583ae3
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 88 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package io.ashdavies.party.events

import androidx.compose.foundation.background
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.material.icons.Icons
import androidx.compose.material.icons.outlined.Event
import androidx.compose.material.icons.outlined.MyLocation
import androidx.compose.material3.Card
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import okio.ByteString.Companion.encode

@Composable
internal fun EventsDetailPane(
event: Event,
modifier: Modifier = Modifier,
) {
Scaffold(
modifier = modifier,
topBar = { EventsTopBar(event.name) },
) { contentPadding ->
Column(Modifier.padding(contentPadding)) {
Card(
modifier = Modifier.padding(
horizontal = 16.dp,
vertical = 8.dp,
),
) {
EventsDetailImage(
imageUrl = event.imageUrl,
name = event.name,
)
}

Card(
modifier = Modifier
.fillMaxWidth()
.padding(
horizontal = 16.dp,
vertical = 8.dp,
),
) {
EventsDetailDate(
dateStart = event.dateStart,
dateEnd = event.dateEnd,
)

EventsDetailLocation(
location = event.location,
)
}
}
}
}

@Composable
private fun EventsDetailImage(
imageUrl: String?,
name: String,
modifier: Modifier = Modifier,
) {
AsyncImage(
model = imageUrl,
contentDescription = null,
modifier = modifier
.background(randomColor(name))
.fillMaxWidth()
.height(200.dp),
placeholder = null,
)
}

@Composable
private fun EventsDetailDate(
dateStart: String,
dateEnd: String,
modifier: Modifier = Modifier,
) {
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = Icons.Outlined.Event,
contentDescription = null,
modifier = Modifier.padding(16.dp),
)

Column {
Text("$dateStart - $dateEnd")
}
}
}

@Composable
private fun EventsDetailLocation(
location: String,
modifier: Modifier = Modifier,
) {
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = Icons.Outlined.MyLocation,
contentDescription = null,
modifier = Modifier.padding(16.dp),
)

Column {
Text(location)
}
}
}

private fun randomColor(seed: String) = with(seed.encode().md5()) {
Color(
red = get(0).toUByte().toInt(),
green = get(1).toUByte().toInt(),
blue = get(2).toUByte().toInt(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.stringResource

@Composable
@OptIn(ExperimentalMaterial3Api::class)
internal fun EventsTopBar(
title: StringResource,
actions: @Composable RowScope.() -> Unit,
title: String,
modifier: Modifier = Modifier,
actions: @Composable RowScope.() -> Unit = { },
) {
CenterAlignedTopAppBar(
title = {
Text(
text = stringResource(title),
text = title,
color = MaterialTheme.colorScheme.onBackground,
style = MaterialTheme.typography.titleLarge,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import io.ashdavies.party.gallery.SyncState
import io.ashdavies.party.material.BottomSheetScaffold
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import org.jetbrains.compose.resources.stringResource
import playground.conferences_app.generated.resources.Res
import playground.conferences_app.generated.resources.past_events

Expand Down Expand Up @@ -123,11 +124,8 @@ internal object GalleryScreen : Parcelable, Screen {
}
}

@OptIn(
ExperimentalFoundationApi::class,
ExperimentalMaterial3Api::class,
)
@Composable
@OptIn(ExperimentalMaterial3Api::class)
internal fun PastEventListScreen(
state: GalleryScreen.State,
manager: StorageManager,
Expand All @@ -141,7 +139,7 @@ internal fun PastEventListScreen(
BottomSheetScaffold(
sheetContent = { GallerySheetContent(eventSink) },
modifier = modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = { EventsTopBar(Res.string.past_events, actions = { }) },
topBar = { EventsTopBar(stringResource(Res.string.past_events)) },
floatingActionButton = {
FadeVisibility(isGalleryCaptureEnabled) {
GalleryActionButton(
Expand Down Expand Up @@ -224,7 +222,6 @@ private fun GalleryExpandedItem(
}

@Composable
@ExperimentalFoundationApi
internal fun GalleryGrid(
itemList: ImmutableList<GalleryScreen.State.StandardItem>,
onExpand: (Int) -> Unit,
Expand Down Expand Up @@ -253,7 +250,7 @@ internal fun GalleryGrid(
}

@Composable
@ExperimentalFoundationApi
@OptIn(ExperimentalFoundationApi::class)
internal fun GalleryItem(
item: GalleryScreen.State.StandardItem,
onSelect: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private val Today = Clock.System.now()

@Composable
@OptIn(ExperimentalMaterial3Api::class)
internal fun UpcomingEventsList(
internal fun UpcomingEventsPane(
state: UpcomingEventsScreen.State,
onClick: (Event) -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -86,7 +86,7 @@ internal fun UpcomingEventsList(
modifier = modifier,
topBar = {
EventsTopBar(
title = Res.string.upcoming_events,
title = stringResource(Res.string.upcoming_events),
actions = {
IconButton(onClick = { error("Crashlytics") }) {
Icon(Icons.Default.Warning, contentDescription = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import io.ashdavies.paging.LazyPagingItems
import io.ashdavies.parcelable.Parcelable
import io.ashdavies.parcelable.Parcelize
import io.ashdavies.party.events.Event
import io.ashdavies.party.events.EventsDetail
import io.ashdavies.party.events.EventsDetailPane

@Parcelize
internal object UpcomingEventsScreen : Parcelable, Screen {
Expand All @@ -40,7 +40,7 @@ internal fun UpcomingEventsScreen(
value = navigator.scaffoldValue,
listPane = {
AnimatedPane {
UpcomingEventsList(
UpcomingEventsPane(
state = state,
onClick = navigator::navigateToDetail,
)
Expand All @@ -49,7 +49,7 @@ internal fun UpcomingEventsScreen(
detailPane = {
AnimatedPane {
navigator.currentDestination?.content?.let {
EventsDetail(it)
EventsDetailPane(it)
}
}
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class EventsDetailTests {
@PreviewDayNight
private fun EventsDetailPreview() {
MaterialPreviewTheme {
EventsDetail(DroidconBerlin)
EventsDetailPane(DroidconBerlin)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.ashdavies.paging.collectAsLazyPagingItems
import io.ashdavies.party.tooling.MaterialPreviewTheme
import io.ashdavies.party.tooling.PreviewDayNight
import io.ashdavies.party.upcoming.UpcomingEventsScreen
import io.ashdavies.party.upcoming.UpcomingEventsList
import io.ashdavies.party.upcoming.UpcomingEventsPane
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf

Expand All @@ -19,7 +19,7 @@ internal class EventsListTests {
@PreviewDayNight
private fun EventsListPreview(data: List<Event> = DroidconEvents) {
MaterialPreviewTheme {
UpcomingEventsList(
UpcomingEventsPane(
state = UpcomingEventsScreen.State(lazyPagingItems(flowOf(PagingData.from(data)))),
onClick = { },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.ashdavies.identity.IdentityState
import io.ashdavies.party.profile.ProfileActionButton
import io.ashdavies.party.tooling.MaterialPreviewTheme
import io.ashdavies.party.tooling.PreviewDayNight
import org.jetbrains.compose.resources.stringResource
import playground.conferences_app.generated.resources.Res
import playground.conferences_app.generated.resources.upcoming_events

Expand All @@ -15,7 +16,7 @@ internal class EventsTopBarTests {
private fun EventsTopBarPreview() {
MaterialPreviewTheme {
EventsTopBar(
title = Res.string.upcoming_events,
title = stringResource(Res.string.upcoming_events),
actions = {
ProfileActionButton(
identityState = IdentityState.Unauthenticated,
Expand Down

0 comments on commit 9583ae3

Please sign in to comment.