|
| 1 | +package com.example.eventtracker.ui.home |
| 2 | + |
| 3 | +import androidx.compose.foundation.background |
| 4 | +import androidx.compose.foundation.border |
| 5 | +import androidx.compose.foundation.layout.Arrangement |
| 6 | +import androidx.compose.foundation.layout.Box |
| 7 | +import androidx.compose.foundation.layout.BoxWithConstraints |
| 8 | +import androidx.compose.foundation.layout.Column |
| 9 | +import androidx.compose.foundation.layout.Row |
| 10 | +import androidx.compose.foundation.layout.Spacer |
| 11 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 12 | +import androidx.compose.foundation.layout.height |
| 13 | +import androidx.compose.foundation.layout.offset |
| 14 | +import androidx.compose.foundation.layout.padding |
| 15 | +import androidx.compose.foundation.layout.width |
| 16 | +import androidx.compose.foundation.rememberScrollState |
| 17 | +import androidx.compose.foundation.shape.CircleShape |
| 18 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 19 | +import androidx.compose.foundation.verticalScroll |
| 20 | +import androidx.compose.material.icons.Icons |
| 21 | +import androidx.compose.material.icons.filled.Share |
| 22 | +import androidx.compose.material.icons.outlined.LocationOn |
| 23 | +import androidx.compose.material3.Button |
| 24 | +import androidx.compose.material3.ButtonDefaults |
| 25 | +import androidx.compose.material3.CenterAlignedTopAppBar |
| 26 | +import androidx.compose.material3.ExperimentalMaterial3Api |
| 27 | +import androidx.compose.material3.Icon |
| 28 | +import androidx.compose.material3.MaterialTheme |
| 29 | +import androidx.compose.material3.Scaffold |
| 30 | +import androidx.compose.material3.Text |
| 31 | +import androidx.compose.runtime.Composable |
| 32 | +import androidx.compose.ui.Modifier |
| 33 | +import androidx.compose.ui.draw.clip |
| 34 | +import androidx.compose.ui.graphics.Color |
| 35 | +import androidx.compose.ui.graphics.graphicsLayer |
| 36 | +import androidx.compose.ui.layout.ContentScale |
| 37 | +import androidx.compose.ui.res.painterResource |
| 38 | +import androidx.compose.ui.text.font.FontWeight |
| 39 | +import androidx.compose.ui.tooling.preview.Preview |
| 40 | +import androidx.compose.ui.unit.dp |
| 41 | +import androidx.compose.ui.unit.max |
| 42 | +import coil.compose.AsyncImage |
| 43 | +import com.example.eventtracker.R |
| 44 | +import com.example.eventtracker.model.EventData |
| 45 | +import com.example.eventtracker.ui.theme.EventTrackerTheme |
| 46 | + |
| 47 | +@Composable |
| 48 | +fun EventDetailScreen(modifier: Modifier = Modifier, event: EventData) { |
| 49 | + Scaffold(topBar = { EventDetailScreenTopBar() }) { |
| 50 | + EventDetailScreenContent(modifier = Modifier.padding(it), event = event) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +@OptIn(ExperimentalMaterial3Api::class) |
| 55 | +@Composable |
| 56 | +fun EventDetailScreenTopBar(modifier: Modifier = Modifier) { |
| 57 | + CenterAlignedTopAppBar( |
| 58 | + title = { |
| 59 | + Text( |
| 60 | + text = "Event Detail", |
| 61 | + fontWeight = FontWeight.Bold |
| 62 | + ) |
| 63 | + }, |
| 64 | + actions = { |
| 65 | + Icon( |
| 66 | + imageVector = Icons.Default.Share, |
| 67 | + contentDescription = "Event Detail", |
| 68 | + ) |
| 69 | + }, |
| 70 | + modifier = modifier |
| 71 | + ) |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | +@Composable |
| 76 | +fun EventDetailScreenContent(modifier: Modifier = Modifier, event: EventData) { |
| 77 | + Column( |
| 78 | + modifier = modifier |
| 79 | + .verticalScroll(rememberScrollState()) |
| 80 | + ) { |
| 81 | + BoxWithConstraints(modifier = Modifier.fillMaxWidth()) { |
| 82 | + Box( |
| 83 | + modifier = Modifier |
| 84 | + .width(maxWidth) |
| 85 | + ) { |
| 86 | + AsyncImage( |
| 87 | + model = event.image, |
| 88 | + error = painterResource(id = R.drawable.default_image), |
| 89 | + contentDescription = null, |
| 90 | + modifier = Modifier.fillMaxWidth(), |
| 91 | + contentScale = ContentScale.Crop |
| 92 | + ) |
| 93 | + } |
| 94 | + } |
| 95 | + Column( |
| 96 | + modifier = Modifier |
| 97 | + .fillMaxWidth() |
| 98 | + .padding(16.dp) |
| 99 | + ) { |
| 100 | + Text( |
| 101 | + text = event.name, |
| 102 | + fontWeight = FontWeight.Bold, |
| 103 | + style = MaterialTheme.typography.titleLarge |
| 104 | + ) |
| 105 | + Spacer(modifier = Modifier.height(8.dp)) |
| 106 | + Text( |
| 107 | + text = "${event.date}, ${event.time}", |
| 108 | + modifier = Modifier |
| 109 | + ) |
| 110 | + Spacer(modifier = Modifier.height(8.dp)) |
| 111 | + Row(modifier = Modifier.fillMaxWidth()) { |
| 112 | + Icon( |
| 113 | + imageVector = Icons.Outlined.LocationOn, |
| 114 | + contentDescription = "Event Location", |
| 115 | + tint = Color.Black, |
| 116 | + modifier = Modifier |
| 117 | + .clip(RoundedCornerShape(8.dp)) |
| 118 | + .background(Color(211, 211, 211, 130)) |
| 119 | + .padding(4.dp) |
| 120 | + |
| 121 | + ) |
| 122 | + |
| 123 | + Spacer(modifier = Modifier.width(8.dp)) |
| 124 | + Text(text = event.location, modifier = Modifier.weight(1f)) |
| 125 | + } |
| 126 | + Spacer(modifier = Modifier.height(16.dp)) |
| 127 | + Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(10.dp)) { |
| 128 | + Button( |
| 129 | + onClick = { /*TODO*/ }, |
| 130 | + modifier = Modifier.weight(1f), |
| 131 | + colors = ButtonDefaults.buttonColors(Color(211, 211, 211, 130)) |
| 132 | + ) { |
| 133 | + Text(text = "Save", color = Color.Black, fontWeight = FontWeight.SemiBold) |
| 134 | + } |
| 135 | + Button( |
| 136 | + onClick = { /*TODO*/ }, |
| 137 | + modifier = Modifier.weight(1f), |
| 138 | + colors = ButtonDefaults.buttonColors(Color(13, 125, 242)) |
| 139 | + ) { |
| 140 | + Text(text = "Attend", fontWeight = FontWeight.SemiBold) |
| 141 | + } |
| 142 | + } |
| 143 | + Spacer(modifier = Modifier.height(16.dp)) |
| 144 | + Text( |
| 145 | + text = "About the Event", |
| 146 | + style = MaterialTheme.typography.titleLarge, |
| 147 | + fontWeight = FontWeight.Bold |
| 148 | + ) |
| 149 | + Spacer(modifier = Modifier.height(8.dp)) |
| 150 | + Text(text = event.description) |
| 151 | + } |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +@Preview(showBackground = true, showSystemUi = true) |
| 156 | +@Composable |
| 157 | +fun EventDetailScreenPreview(modifier: Modifier = Modifier) { |
| 158 | + EventTrackerTheme { |
| 159 | + EventDetailScreen(event = EventData()) |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | + |
| 164 | + |
0 commit comments