|
1 | 1 | package com.mbta.tid.mbta_app.android.onboarding |
2 | 2 |
|
| 3 | +import androidx.compose.animation.animateColor |
3 | 4 | import androidx.compose.animation.core.EaseInOut |
4 | 5 | import androidx.compose.animation.core.RepeatMode |
5 | 6 | import androidx.compose.animation.core.animateFloat |
6 | 7 | import androidx.compose.animation.core.infiniteRepeatable |
7 | 8 | import androidx.compose.animation.core.rememberInfiniteTransition |
8 | 9 | import androidx.compose.animation.core.tween |
| 10 | +import androidx.compose.animation.core.updateTransition |
9 | 11 | import androidx.compose.foundation.Image |
10 | 12 | import androidx.compose.foundation.background |
| 13 | +import androidx.compose.foundation.border |
| 14 | +import androidx.compose.foundation.isSystemInDarkTheme |
11 | 15 | import androidx.compose.foundation.layout.Arrangement |
| 16 | +import androidx.compose.foundation.layout.Box |
| 17 | +import androidx.compose.foundation.layout.Column |
12 | 18 | import androidx.compose.foundation.layout.Row |
13 | 19 | import androidx.compose.foundation.layout.Spacer |
14 | 20 | import androidx.compose.foundation.layout.height |
| 21 | +import androidx.compose.foundation.layout.offset |
15 | 22 | import androidx.compose.foundation.layout.padding |
| 23 | +import androidx.compose.foundation.layout.requiredSize |
16 | 24 | import androidx.compose.foundation.layout.size |
| 25 | +import androidx.compose.foundation.layout.width |
| 26 | +import androidx.compose.foundation.shape.CircleShape |
17 | 27 | import androidx.compose.foundation.shape.RoundedCornerShape |
| 28 | +import androidx.compose.material.icons.Icons |
| 29 | +import androidx.compose.material.icons.filled.KeyboardArrowDown |
| 30 | +import androidx.compose.material3.Icon |
| 31 | +import androidx.compose.material3.Switch |
18 | 32 | import androidx.compose.material3.Text |
19 | 33 | import androidx.compose.runtime.Composable |
| 34 | +import androidx.compose.runtime.LaunchedEffect |
20 | 35 | import androidx.compose.runtime.getValue |
21 | 36 | import androidx.compose.runtime.mutableStateOf |
| 37 | +import androidx.compose.runtime.remember |
22 | 38 | import androidx.compose.runtime.saveable.rememberSaveable |
23 | 39 | import androidx.compose.runtime.setValue |
24 | 40 | import androidx.compose.ui.Alignment |
25 | 41 | import androidx.compose.ui.Modifier |
| 42 | +import androidx.compose.ui.draw.alpha |
| 43 | +import androidx.compose.ui.draw.clip |
| 44 | +import androidx.compose.ui.draw.scale |
| 45 | +import androidx.compose.ui.graphics.Color |
26 | 46 | import androidx.compose.ui.platform.LocalConfiguration |
27 | 47 | import androidx.compose.ui.platform.LocalDensity |
28 | 48 | import androidx.compose.ui.res.colorResource |
29 | 49 | import androidx.compose.ui.res.painterResource |
30 | 50 | import androidx.compose.ui.res.stringResource |
| 51 | +import androidx.compose.ui.semantics.contentDescription |
| 52 | +import androidx.compose.ui.semantics.heading |
| 53 | +import androidx.compose.ui.semantics.paneTitle |
| 54 | +import androidx.compose.ui.semantics.semantics |
| 55 | +import androidx.compose.ui.text.font.FontFamily |
| 56 | +import androidx.compose.ui.text.font.FontWeight |
31 | 57 | import androidx.compose.ui.tooling.preview.Preview |
32 | 58 | import androidx.compose.ui.unit.dp |
33 | 59 | import androidx.compose.ui.unit.sp |
| 60 | +import com.airbnb.lottie.compose.LottieAnimation |
| 61 | +import com.airbnb.lottie.compose.LottieCompositionSpec |
| 62 | +import com.airbnb.lottie.compose.animateLottieCompositionAsState |
| 63 | +import com.airbnb.lottie.compose.rememberLottieComposition |
34 | 64 | import com.google.accompanist.permissions.ExperimentalPermissionsApi |
35 | 65 | import com.google.accompanist.permissions.isGranted |
36 | 66 | import com.mbta.tid.mbta_app.android.MyApplicationTheme |
37 | 67 | import com.mbta.tid.mbta_app.android.R |
| 68 | +import com.mbta.tid.mbta_app.android.component.StarIcon |
38 | 69 | import com.mbta.tid.mbta_app.android.location.LocationDataManager |
| 70 | +import com.mbta.tid.mbta_app.android.util.FormattedAlert |
39 | 71 | import com.mbta.tid.mbta_app.android.util.SettingsCache |
40 | 72 | import com.mbta.tid.mbta_app.android.util.Typography |
| 73 | +import com.mbta.tid.mbta_app.model.Alert |
| 74 | +import com.mbta.tid.mbta_app.model.AlertSummary |
41 | 75 | import com.mbta.tid.mbta_app.model.OnboardingScreen |
| 76 | +import com.mbta.tid.mbta_app.repositories.MockSettingsRepository |
42 | 77 | import com.mbta.tid.mbta_app.repositories.Settings |
| 78 | +import com.mbta.tid.mbta_app.utils.EasternTimeInstant |
| 79 | +import kotlin.time.Duration.Companion.seconds |
| 80 | +import kotlinx.coroutines.delay |
| 81 | +import kotlinx.datetime.Month |
43 | 82 | import org.koin.compose.koinInject |
| 83 | +import org.koin.core.context.startKoin |
| 84 | +import org.koin.dsl.module |
| 85 | +import org.koin.mp.KoinPlatformTools |
44 | 86 |
|
45 | 87 | @OptIn(ExperimentalPermissionsApi::class) |
46 | 88 | @Composable |
@@ -182,6 +224,9 @@ fun OnboardingScreenView( |
182 | 224 | } |
183 | 225 | } |
184 | 226 | } |
| 227 | + OnboardingScreen.NotificationsBeta -> { |
| 228 | + NotificationsBetaPage(advance) |
| 229 | + } |
185 | 230 | OnboardingScreen.StationAccessibility -> { |
186 | 231 | OnboardingPieces.PageBox(painterResource(R.mipmap.onboarding_background_map)) { |
187 | 232 | OnboardingContentColumn { |
@@ -219,9 +264,225 @@ fun OnboardingScreenView( |
219 | 264 | } |
220 | 265 | } |
221 | 266 |
|
| 267 | +private enum class NotificationsScreenState { |
| 268 | + Initial, |
| 269 | + AfterFavorite, |
| 270 | + AfterSchedule, |
| 271 | + Final, |
| 272 | +} |
| 273 | + |
| 274 | +@Composable |
| 275 | +private fun NotificationsBetaPage(advance: () -> Unit) { |
| 276 | + var screenState by remember { mutableStateOf(NotificationsScreenState.Initial) } |
| 277 | + val transition = updateTransition(screenState, label = "state") |
| 278 | + LaunchedEffect(null) { |
| 279 | + delay(2.seconds) |
| 280 | + screenState = NotificationsScreenState.AfterFavorite |
| 281 | + delay(2.seconds) |
| 282 | + screenState = NotificationsScreenState.AfterSchedule |
| 283 | + delay(2.seconds) |
| 284 | + screenState = NotificationsScreenState.Final |
| 285 | + } |
| 286 | + OnboardingPieces.PageBox( |
| 287 | + colorResource(if (isSystemInDarkTheme()) R.color.fill1 else R.color.fill2) |
| 288 | + ) { |
| 289 | + Column( |
| 290 | + Modifier.align(Alignment.TopCenter) |
| 291 | + .offset(y = (-200).dp) |
| 292 | + .scale(0.6f) |
| 293 | + .background(colorResource(R.color.key), RoundedCornerShape(32.dp)) |
| 294 | + .border(16.dp, Color.Black, RoundedCornerShape(32.dp)) |
| 295 | + .padding(8.dp) |
| 296 | + ) { |
| 297 | + val isDarkMode = isSystemInDarkTheme() |
| 298 | + Spacer(Modifier.height(250.dp)) |
| 299 | + Row( |
| 300 | + Modifier.padding(16.dp) |
| 301 | + .background( |
| 302 | + if (isDarkMode) Color.Black.copy(alpha = 0.5f) |
| 303 | + else Color.White.copy(alpha = 0.75f), |
| 304 | + RoundedCornerShape(26.dp), |
| 305 | + ) |
| 306 | + .padding(horizontal = 16.dp, vertical = 14.dp), |
| 307 | + horizontalArrangement = Arrangement.spacedBy(16.dp), |
| 308 | + verticalAlignment = Alignment.CenterVertically, |
| 309 | + ) { |
| 310 | + Box(Modifier.size(36.dp).clip(CircleShape)) { |
| 311 | + Image( |
| 312 | + painterResource(R.drawable.ic_launcher_background), |
| 313 | + contentDescription = null, |
| 314 | + modifier = Modifier.requiredSize(48.dp), |
| 315 | + ) |
| 316 | + Image( |
| 317 | + painterResource(R.drawable.ic_launcher_foreground), |
| 318 | + contentDescription = null, |
| 319 | + modifier = Modifier.requiredSize(48.dp), |
| 320 | + ) |
| 321 | + } |
| 322 | + |
| 323 | + Column { |
| 324 | + Row( |
| 325 | + horizontalArrangement = Arrangement.spacedBy(4.dp), |
| 326 | + verticalAlignment = Alignment.CenterVertically, |
| 327 | + ) { |
| 328 | + Text( |
| 329 | + "Orange Line", |
| 330 | + color = colorResource(R.color.text), |
| 331 | + fontSize = 16.sp, |
| 332 | + fontWeight = FontWeight.SemiBold, |
| 333 | + fontFamily = FontFamily.Default, |
| 334 | + ) |
| 335 | + Spacer(Modifier.weight(1f)) |
| 336 | + Text( |
| 337 | + "now", |
| 338 | + Modifier.alpha(0.6f), |
| 339 | + color = colorResource(R.color.text), |
| 340 | + fontSize = 14.sp, |
| 341 | + fontFamily = FontFamily.Default, |
| 342 | + ) |
| 343 | + Icon( |
| 344 | + Icons.Default.KeyboardArrowDown, |
| 345 | + contentDescription = null, |
| 346 | + Modifier.alpha(0.6f).size(18.dp), |
| 347 | + ) |
| 348 | + } |
| 349 | + val alert = |
| 350 | + FormattedAlert( |
| 351 | + alert = null, |
| 352 | + alertSummary = |
| 353 | + AlertSummary( |
| 354 | + effect = Alert.Effect.Suspension, |
| 355 | + location = |
| 356 | + AlertSummary.Location.SuccessiveStops( |
| 357 | + startStopName = "Back Bay", |
| 358 | + endStopName = "Wellington", |
| 359 | + ), |
| 360 | + timeframe = |
| 361 | + AlertSummary.Timeframe.ThisWeek( |
| 362 | + EasternTimeInstant(2026, Month.JANUARY, 25, 12, 0) |
| 363 | + ), |
| 364 | + ), |
| 365 | + ) |
| 366 | + Text( |
| 367 | + alert.alertCardMajorBody.toString(), |
| 368 | + color = colorResource(R.color.text), |
| 369 | + fontSize = 16.sp, |
| 370 | + fontWeight = FontWeight.Light, |
| 371 | + fontFamily = FontFamily.Default, |
| 372 | + ) |
| 373 | + } |
| 374 | + } |
| 375 | + Spacer(Modifier.height(32.dp)) |
| 376 | + } |
| 377 | + OnboardingContentColumn { |
| 378 | + val header = stringResource(R.string.promo_notifications_header) |
| 379 | + // setting explicit paneTitle resets focus to the text rather than the continue button |
| 380 | + // when navigating to the next screen |
| 381 | + // https://issuetracker.google.com/issues/272065229#comment8 |
| 382 | + Spacer(Modifier.weight(1f)) |
| 383 | + Column( |
| 384 | + Modifier.semantics { paneTitle = header }, |
| 385 | + verticalArrangement = Arrangement.spacedBy(32.dp), |
| 386 | + ) { |
| 387 | + val headerDescription = |
| 388 | + stringResource(R.string.new_feature_screen_reader_header_prefix, header) |
| 389 | + Text( |
| 390 | + header, |
| 391 | + modifier = |
| 392 | + Modifier.semantics { |
| 393 | + contentDescription = headerDescription |
| 394 | + heading() |
| 395 | + }, |
| 396 | + color = colorResource(R.color.text), |
| 397 | + style = Typography.title1Bold, |
| 398 | + ) |
| 399 | + Row( |
| 400 | + horizontalArrangement = Arrangement.spacedBy(12.dp), |
| 401 | + verticalAlignment = Alignment.CenterVertically, |
| 402 | + ) { |
| 403 | + val starColor by |
| 404 | + transition.animateColor { |
| 405 | + if (it >= NotificationsScreenState.AfterFavorite) |
| 406 | + colorResource(R.color.key) |
| 407 | + else colorResource(R.color.text).copy(alpha = 0.4f) |
| 408 | + } |
| 409 | + val textAlpha by |
| 410 | + transition.animateFloat { |
| 411 | + if (it >= NotificationsScreenState.AfterFavorite) 1f else 0.4f |
| 412 | + } |
| 413 | + StarIcon( |
| 414 | + starred = screenState >= NotificationsScreenState.AfterFavorite, |
| 415 | + color = starColor, |
| 416 | + modifier = Modifier.width(52.dp), |
| 417 | + size = 36.dp, |
| 418 | + ) |
| 419 | + Text( |
| 420 | + stringResource(R.string.promo_notifications_step1), |
| 421 | + modifier = Modifier.alpha(textAlpha), |
| 422 | + color = colorResource(R.color.text), |
| 423 | + style = Typography.title3, |
| 424 | + ) |
| 425 | + } |
| 426 | + Row( |
| 427 | + horizontalArrangement = Arrangement.spacedBy(12.dp), |
| 428 | + verticalAlignment = Alignment.CenterVertically, |
| 429 | + ) { |
| 430 | + val textAlpha by |
| 431 | + transition.animateFloat { |
| 432 | + if (it >= NotificationsScreenState.AfterSchedule) 1f else 0.4f |
| 433 | + } |
| 434 | + Switch( |
| 435 | + checked = screenState >= NotificationsScreenState.AfterSchedule, |
| 436 | + onCheckedChange = null, |
| 437 | + ) |
| 438 | + Text( |
| 439 | + stringResource(R.string.promo_notifications_step2), |
| 440 | + modifier = Modifier.alpha(textAlpha), |
| 441 | + color = colorResource(R.color.text), |
| 442 | + style = Typography.title3, |
| 443 | + ) |
| 444 | + } |
| 445 | + val textAlpha by |
| 446 | + transition.animateFloat { |
| 447 | + if (it >= NotificationsScreenState.Final) 1f else 0.4f |
| 448 | + } |
| 449 | + Text( |
| 450 | + stringResource(R.string.promo_notifications_body), |
| 451 | + modifier = Modifier.alpha(textAlpha), |
| 452 | + color = colorResource(R.color.text), |
| 453 | + style = Typography.title3, |
| 454 | + ) |
| 455 | + } |
| 456 | + Box(Modifier.weight(1f), contentAlignment = Alignment.BottomCenter) { |
| 457 | + val composition by |
| 458 | + rememberLottieComposition( |
| 459 | + LottieCompositionSpec.RawRes( |
| 460 | + if (isSystemInDarkTheme()) R.raw.notification_pop_dark |
| 461 | + else R.raw.notification_pop_light |
| 462 | + ) |
| 463 | + ) |
| 464 | + val progress by |
| 465 | + animateLottieCompositionAsState( |
| 466 | + composition, |
| 467 | + isPlaying = screenState >= NotificationsScreenState.Final, |
| 468 | + ) |
| 469 | + LottieAnimation( |
| 470 | + composition, |
| 471 | + progress = { progress }, |
| 472 | + Modifier.align(Alignment.BottomCenter), |
| 473 | + ) |
| 474 | + Column { OnboardingPieces.KeyButton(R.string.got_it, onClick = advance) } |
| 475 | + } |
| 476 | + } |
| 477 | + } |
| 478 | +} |
| 479 | + |
222 | 480 | @Preview(name = "Feedback") |
223 | 481 | @Composable |
224 | 482 | private fun OnboardingScreenViewFeedbackPreview() { |
| 483 | + if (KoinPlatformTools.defaultContext().getOrNull() == null) { |
| 484 | + startKoin { modules(module { single { SettingsCache(MockSettingsRepository()) } }) } |
| 485 | + } |
225 | 486 | MyApplicationTheme { |
226 | 487 | OnboardingScreenView( |
227 | 488 | OnboardingScreen.Feedback, |
@@ -255,6 +516,21 @@ private fun OnboardingScreenViewLocationPreview() { |
255 | 516 | } |
256 | 517 | } |
257 | 518 |
|
| 519 | +@Preview(name = "Notifications Beta") |
| 520 | +@Composable |
| 521 | +private fun OnboardingScreenViewNotificationsBetaPreview() { |
| 522 | + if (KoinPlatformTools.defaultContext().getOrNull() == null) { |
| 523 | + startKoin { modules(module { single { SettingsCache(MockSettingsRepository()) } }) } |
| 524 | + } |
| 525 | + MyApplicationTheme { |
| 526 | + OnboardingScreenView( |
| 527 | + OnboardingScreen.NotificationsBeta, |
| 528 | + advance = {}, |
| 529 | + locationDataManager = LocationDataManager(), |
| 530 | + ) |
| 531 | + } |
| 532 | +} |
| 533 | + |
258 | 534 | @Preview(name = "StationAccessibility") |
259 | 535 | @Composable |
260 | 536 | private fun OnboardingScreenViewStationAccessibiityPreview() { |
|
0 commit comments