|
| 1 | +package com.el.yello.presentation.getalarm.screen |
| 2 | + |
| 3 | +import android.Manifest |
| 4 | +import android.content.pm.PackageManager |
| 5 | +import android.os.Build |
| 6 | +import androidx.activity.compose.rememberLauncherForActivityResult |
| 7 | +import androidx.activity.result.contract.ActivityResultContracts |
| 8 | +import androidx.compose.foundation.Image |
| 9 | +import androidx.compose.foundation.background |
| 10 | +import androidx.compose.foundation.layout.Arrangement |
| 11 | +import androidx.compose.foundation.layout.Column |
| 12 | +import androidx.compose.foundation.layout.PaddingValues |
| 13 | +import androidx.compose.foundation.layout.Row |
| 14 | +import androidx.compose.foundation.layout.Spacer |
| 15 | +import androidx.compose.foundation.layout.fillMaxSize |
| 16 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 17 | +import androidx.compose.foundation.layout.height |
| 18 | +import androidx.compose.foundation.layout.padding |
| 19 | +import androidx.compose.foundation.layout.size |
| 20 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 21 | +import androidx.compose.material3.Button |
| 22 | +import androidx.compose.material3.ButtonDefaults |
| 23 | +import androidx.compose.material3.Scaffold |
| 24 | +import androidx.compose.material3.Text |
| 25 | +import androidx.compose.runtime.Composable |
| 26 | +import androidx.compose.runtime.LaunchedEffect |
| 27 | +import androidx.compose.ui.Alignment |
| 28 | +import androidx.compose.ui.Modifier |
| 29 | +import androidx.compose.ui.layout.ContentScale |
| 30 | +import androidx.compose.ui.platform.LocalContext |
| 31 | +import androidx.compose.ui.res.painterResource |
| 32 | +import androidx.compose.ui.res.stringResource |
| 33 | +import androidx.compose.ui.text.font.FontWeight |
| 34 | +import androidx.compose.ui.text.style.TextAlign |
| 35 | +import androidx.compose.ui.tooling.preview.Preview |
| 36 | +import androidx.compose.ui.unit.dp |
| 37 | +import androidx.compose.ui.unit.sp |
| 38 | +import androidx.core.content.ContextCompat |
| 39 | +import androidx.hilt.navigation.compose.hiltViewModel |
| 40 | +import com.el.yello.R |
| 41 | +import com.el.yello.presentation.getalarm.contract.GetAlarmSideEffect |
| 42 | +import com.el.yello.presentation.getalarm.viewmodel.GetAlarmViewModel |
| 43 | +import com.example.ui.compose.theme.Black |
| 44 | +import com.example.ui.compose.theme.Grayscale500 |
| 45 | +import com.example.ui.compose.theme.PretendardFontFamily |
| 46 | +import com.example.ui.compose.theme.White |
| 47 | +import com.example.ui.compose.theme.YelloMain500 |
| 48 | +import com.example.ui.compose.theme.YelloTheme |
| 49 | +import org.orbitmvi.orbit.compose.collectSideEffect |
| 50 | + |
| 51 | +@Composable |
| 52 | +fun GetAlarmRoute( |
| 53 | + viewModel: GetAlarmViewModel = hiltViewModel(), |
| 54 | + isFromOnBoarding: Boolean, |
| 55 | + isCodeTextEmpty: Boolean, |
| 56 | + navigateToTutorial: () -> Unit |
| 57 | +) { |
| 58 | + val context = LocalContext.current |
| 59 | + |
| 60 | + val requestPermissionLauncher = rememberLauncherForActivityResult( |
| 61 | + ActivityResultContracts.RequestPermission() |
| 62 | + ) { isGranted -> |
| 63 | + viewModel.onPermissionResult(isGranted) |
| 64 | + } |
| 65 | + |
| 66 | + LaunchedEffect(Unit) { |
| 67 | + viewModel.initGetAlarm(isFromOnBoarding, isCodeTextEmpty) |
| 68 | + } |
| 69 | + |
| 70 | + viewModel.collectSideEffect { |
| 71 | + when (it) { |
| 72 | + GetAlarmSideEffect.NavigateToTutorial -> navigateToTutorial() |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + GetAlarmScreen( |
| 77 | + onStartYelloClick = { |
| 78 | + viewModel.onStartYelloClickEvent() |
| 79 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { |
| 80 | + if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED |
| 81 | + ) { |
| 82 | + viewModel.onPermissionResult(true) |
| 83 | + } else { |
| 84 | + requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) |
| 85 | + } |
| 86 | + } else { |
| 87 | + viewModel.onPermissionResult(true) |
| 88 | + } |
| 89 | + } |
| 90 | + ) |
| 91 | +} |
| 92 | + |
| 93 | +@Composable |
| 94 | +fun GetAlarmScreen( |
| 95 | + onStartYelloClick: () -> Unit = {} |
| 96 | +) { |
| 97 | + Scaffold( |
| 98 | + modifier = Modifier |
| 99 | + .fillMaxSize() |
| 100 | + .background(Black) |
| 101 | + ) { paddingValues -> |
| 102 | + Column( |
| 103 | + modifier = Modifier |
| 104 | + .fillMaxSize() |
| 105 | + .background(Black) |
| 106 | + .padding(paddingValues) |
| 107 | + .padding(horizontal = 16.dp), |
| 108 | + horizontalAlignment = Alignment.CenterHorizontally |
| 109 | + ) { |
| 110 | + Spacer( |
| 111 | + modifier = Modifier.height(104.dp) |
| 112 | + ) |
| 113 | + |
| 114 | + // 제목, 하트 아이콘 |
| 115 | + Row( |
| 116 | + horizontalArrangement = Arrangement.Center, |
| 117 | + verticalAlignment = Alignment.CenterVertically |
| 118 | + ) { |
| 119 | + Text( |
| 120 | + text = stringResource(id = R.string.onboarding_tv_startapp_title), |
| 121 | + fontSize = 24.sp, |
| 122 | + fontFamily = PretendardFontFamily, |
| 123 | + fontWeight = FontWeight.Bold, |
| 124 | + color = White, |
| 125 | + textAlign = TextAlign.Center |
| 126 | + ) |
| 127 | + Image( |
| 128 | + modifier = Modifier |
| 129 | + .padding(start = 2.dp) |
| 130 | + .size(24.dp), |
| 131 | + painter = painterResource(id = R.drawable.ic_onboarding_startapp_heart), |
| 132 | + contentDescription = "Heart Icon" |
| 133 | + ) |
| 134 | + } |
| 135 | + |
| 136 | + Spacer(modifier = Modifier.height(8.dp)) |
| 137 | + |
| 138 | + // 부제목 |
| 139 | + Text( |
| 140 | + text = stringResource(id = R.string.onboarding_tv_startapp_subtitle), |
| 141 | + fontSize = 14.sp, |
| 142 | + fontFamily = PretendardFontFamily, |
| 143 | + fontWeight = FontWeight.Medium, |
| 144 | + color = Grayscale500, |
| 145 | + textAlign = TextAlign.Center |
| 146 | + ) |
| 147 | + |
| 148 | + Spacer(modifier = Modifier.height(24.dp)) |
| 149 | + |
| 150 | + // 알림 아이콘 이미지 |
| 151 | + Image( |
| 152 | + modifier = Modifier |
| 153 | + .fillMaxWidth() |
| 154 | + .height(340.dp), |
| 155 | + painter = painterResource(id = R.drawable.img_tutorial_startapp), |
| 156 | + contentDescription = "Start App Image", |
| 157 | + contentScale = ContentScale.Crop |
| 158 | + ) |
| 159 | + |
| 160 | + Spacer(modifier = Modifier.weight(1f)) |
| 161 | + |
| 162 | + // 쪽지 알림 받기 버튼 |
| 163 | + Button( |
| 164 | + modifier = Modifier |
| 165 | + .fillMaxWidth() |
| 166 | + .padding(bottom = 34.dp), |
| 167 | + onClick = onStartYelloClick, |
| 168 | + colors = ButtonDefaults.buttonColors( |
| 169 | + containerColor = YelloMain500, |
| 170 | + contentColor = Black |
| 171 | + ), |
| 172 | + shape = RoundedCornerShape(100.dp), |
| 173 | + contentPadding = PaddingValues( |
| 174 | + horizontal = 16.dp, |
| 175 | + vertical = 18.dp |
| 176 | + ) |
| 177 | + ) { |
| 178 | + Text( |
| 179 | + text = stringResource(id = R.string.onboarding_tv_start_yello), |
| 180 | + fontSize = 15.sp, |
| 181 | + fontFamily = PretendardFontFamily, |
| 182 | + fontWeight = FontWeight.Bold |
| 183 | + ) |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | +@Preview(showBackground = true) |
| 190 | +@Composable |
| 191 | +fun GetAlarmScreenPreview() { |
| 192 | + YelloTheme { |
| 193 | + GetAlarmScreen() |
| 194 | + } |
| 195 | +} |
0 commit comments