|
| 1 | +package com.sameerasw.essentials.ui.components.sheets |
| 2 | + |
| 3 | +import androidx.compose.foundation.gestures.detectTapGestures |
| 4 | +import androidx.compose.foundation.layout.Arrangement |
| 5 | +import androidx.compose.foundation.layout.Column |
| 6 | +import androidx.compose.foundation.layout.Row |
| 7 | +import androidx.compose.foundation.layout.Spacer |
| 8 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 9 | +import androidx.compose.foundation.layout.height |
| 10 | +import androidx.compose.foundation.layout.padding |
| 11 | +import androidx.compose.foundation.layout.size |
| 12 | +import androidx.compose.material3.Button |
| 13 | +import androidx.compose.material3.ExperimentalMaterial3Api |
| 14 | +import androidx.compose.material3.MaterialTheme |
| 15 | +import androidx.compose.material3.ModalBottomSheet |
| 16 | +import androidx.compose.material3.SheetState |
| 17 | +import androidx.compose.material3.Text |
| 18 | +import androidx.compose.runtime.Composable |
| 19 | +import androidx.compose.runtime.getValue |
| 20 | +import androidx.compose.runtime.mutableStateOf |
| 21 | +import androidx.compose.runtime.remember |
| 22 | +import androidx.compose.runtime.setValue |
| 23 | +import androidx.compose.ui.Alignment |
| 24 | +import androidx.compose.ui.Modifier |
| 25 | +import androidx.compose.ui.input.pointer.pointerInput |
| 26 | +import androidx.compose.ui.platform.LocalView |
| 27 | +import androidx.compose.ui.res.painterResource |
| 28 | +import androidx.compose.ui.res.stringResource |
| 29 | +import androidx.compose.ui.text.font.FontWeight |
| 30 | +import androidx.compose.ui.text.style.TextAlign |
| 31 | +import androidx.compose.ui.unit.dp |
| 32 | +import coil.compose.AsyncImage |
| 33 | +import com.sameerasw.essentials.R |
| 34 | +import com.sameerasw.essentials.data.repository.SettingsRepository |
| 35 | +import com.sameerasw.essentials.utils.HapticUtil |
| 36 | +import com.sameerasw.essentials.viewmodels.MainViewModel |
| 37 | + |
| 38 | +@OptIn(ExperimentalMaterial3Api::class) |
| 39 | +@Composable |
| 40 | +fun PrankBottomSheet( |
| 41 | + viewModel: MainViewModel, |
| 42 | + sheetState: SheetState, |
| 43 | + onDismissRequest: () -> Unit |
| 44 | +) { |
| 45 | + var isRevealed by remember { mutableStateOf(false) } |
| 46 | + val view = LocalView.current |
| 47 | + |
| 48 | + ModalBottomSheet( |
| 49 | + onDismissRequest = { |
| 50 | + if (isRevealed) { |
| 51 | + onDismissRequest() |
| 52 | + } |
| 53 | + }, |
| 54 | + sheetState = sheetState, |
| 55 | + dragHandle = null |
| 56 | + ) { |
| 57 | + Column( |
| 58 | + modifier = Modifier |
| 59 | + .fillMaxWidth() |
| 60 | + .padding(24.dp), |
| 61 | + horizontalAlignment = Alignment.CenterHorizontally, |
| 62 | + verticalArrangement = Arrangement.spacedBy(16.dp) |
| 63 | + ) { |
| 64 | + // App Logo |
| 65 | + AsyncImage( |
| 66 | + model = R.mipmap.ic_launcher_round, |
| 67 | + contentDescription = null, |
| 68 | + modifier = Modifier.size(80.dp) |
| 69 | + ) |
| 70 | + |
| 71 | + if (!isRevealed) { |
| 72 | + // Prank Phase |
| 73 | + Text( |
| 74 | + text = stringResource(R.string.prank_trial_expired_title), |
| 75 | + style = MaterialTheme.typography.headlineSmall, |
| 76 | + fontWeight = FontWeight.Bold, |
| 77 | + textAlign = TextAlign.Center |
| 78 | + ) |
| 79 | + |
| 80 | + Text( |
| 81 | + text = stringResource(R.string.prank_trial_expired_desc), |
| 82 | + style = MaterialTheme.typography.bodyMedium, |
| 83 | + textAlign = TextAlign.Center, |
| 84 | + color = MaterialTheme.colorScheme.onSurfaceVariant |
| 85 | + ) |
| 86 | + |
| 87 | + Spacer(modifier = Modifier.height(8.dp)) |
| 88 | + |
| 89 | + Button( |
| 90 | + onClick = { |
| 91 | + HapticUtil.performHeavyHaptic(view) |
| 92 | + isRevealed = true |
| 93 | + }, |
| 94 | + modifier = Modifier.fillMaxWidth() |
| 95 | + ) { |
| 96 | + Text(text = stringResource(R.string.prank_button_premium)) |
| 97 | + } |
| 98 | + } else { |
| 99 | + // Reveal Phase |
| 100 | + Text( |
| 101 | + text = stringResource(R.string.prank_reveal_title), |
| 102 | + style = MaterialTheme.typography.headlineSmall, |
| 103 | + fontWeight = FontWeight.Bold, |
| 104 | + textAlign = TextAlign.Center, |
| 105 | + color = MaterialTheme.colorScheme.primary |
| 106 | + ) |
| 107 | + |
| 108 | + Text( |
| 109 | + text = stringResource(R.string.prank_reveal_desc), |
| 110 | + style = MaterialTheme.typography.bodyLarge, |
| 111 | + textAlign = TextAlign.Center |
| 112 | + ) |
| 113 | + |
| 114 | + Spacer(modifier = Modifier.height(8.dp)) |
| 115 | + |
| 116 | + Button( |
| 117 | + onClick = { |
| 118 | + onDismissRequest() |
| 119 | + }, |
| 120 | + modifier = Modifier |
| 121 | + .fillMaxWidth() |
| 122 | + .pointerInput(Unit) { |
| 123 | + detectTapGestures( |
| 124 | + onLongPress = { |
| 125 | + // Debug reset |
| 126 | + viewModel.settingsRepository.putBoolean( |
| 127 | + SettingsRepository.KEY_APRIL_FOOLS_SHOWN, |
| 128 | + false |
| 129 | + ) |
| 130 | + HapticUtil.performHeavyHaptic(view) |
| 131 | + android.widget.Toast.makeText(view.context, "Prank reset for testing", android.widget.Toast.LENGTH_SHORT).show() |
| 132 | + }, |
| 133 | + onTap = { |
| 134 | + HapticUtil.performUIHaptic(view) |
| 135 | + onDismissRequest() |
| 136 | + } |
| 137 | + ) |
| 138 | + } |
| 139 | + ) { |
| 140 | + Text(text = stringResource(R.string.action_continue)) |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + Spacer(modifier = Modifier.height(16.dp)) |
| 145 | + } |
| 146 | + } |
| 147 | +} |
0 commit comments