Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/YAP-63] 온보딩 시스템 알림권한 설정을 구현합니다. #50

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ android {
namespace = "com.yapp.orbit"

defaultConfig {
applicationId = "com.yapp.orbit"
versionCode = 1
versionName = "1.0"
targetSdk = 34
}

buildTypes {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
android:name=".OrbitApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.yapp.common.navigation.destination.HomeDestination
import com.yapp.common.navigation.destination.OnboardingDestination
import com.yapp.common.navigation.destination.TopLevelDestination

class OrbitNavigator(
val navController: NavHostController,
) {
val startDestination = HomeDestination.Route.route
val startDestination = OnboardingDestination.Route.route

private val currentDestination: NavDestination?
@Composable get() = navController
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions feature/onboarding/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ dependencies {
implementation(libs.orbit.viewmodel)
implementation(libs.coil.compose)
implementation(libs.coil.gif)
implementation(libs.accompanist.permission)
}
Original file line number Diff line number Diff line change
@@ -1,76 +1,144 @@
package com.kms.onboarding

import android.content.Intent
import android.net.Uri
import android.provider.Settings
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.PermissionStatus
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberPermissionState
import com.kms.onboarding.component.OnBoardingTopAppBar
import com.yapp.common.navigation.OrbitNavigator
import com.yapp.designsystem.theme.OrbitTheme
import com.yapp.ui.component.button.OrbitButton
import com.yapp.ui.utils.heightForScreenPercentage
import feature.onboarding.R

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun OnboardingAccessRoute(
navigator: OrbitNavigator,
viewModel: OnboardingViewModel,
) {
val state by viewModel.container.stateFlow.collectAsStateWithLifecycle()
val permissionState = rememberPermissionState(
permission = android.Manifest.permission.POST_NOTIFICATIONS,
)
val context = LocalContext.current

LaunchedEffect(permissionState.status) {
if (permissionState.status.isGranted) {
Log.d("OnboardingAccessRoute", "Permission granted, navigating to next page")
viewModel.processAction(OnboardingContract.Action.NextStep)
}
}

OnboardingAccessScreen(
state = state,
currentStep = 6,
totalSteps = 6,
onNextClick = { viewModel.processAction(OnboardingContract.Action.NextStep) },
permissionStatus = permissionState.status,
onRequestPermission = {
if (!permissionState.status.isGranted) {
Log.d("OnboardingAccessRoute", "Launching permission request")
permissionState.launchPermissionRequest()
}
},
onNavigateToNext = {
viewModel.processAction(OnboardingContract.Action.NextStep)
},
onBackClick = { viewModel.processAction(OnboardingContract.Action.PreviousStep) },
onNavigateToSettings = {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.fromParts("package", context.packageName, null)
}
context.startActivity(intent)
},
)
}

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun OnboardingAccessScreen(
state: OnboardingContract.State,
currentStep: Int,
totalSteps: Int,
onNextClick: () -> Unit,
permissionStatus: PermissionStatus,
onRequestPermission: () -> Unit,
onNavigateToNext: () -> Unit,
onBackClick: () -> Unit,
onNavigateToSettings: () -> Unit,
) {
// TODO: 추후 실제 시스템 알림 Alert 에서 선택한 값에 따른 변경
val isToggled = remember { mutableStateOf(false) }
OnboardingScreen(
currentStep = currentStep,
totalSteps = totalSteps,
isButtonEnabled = true,
onNextClick = onNextClick,
onBackClick = onBackClick,
buttonLabel = "네, 알겠어요",
) {
val (text, imageRes) = when (isToggled.value) {
true -> Pair(
stringResource(id = R.string.onboarding_step7_text_refuse_title),
core.designsystem.R.drawable.ic_onboarding_authorization_refusal,
)
val defaultText = stringResource(id = R.string.onboarding_step7_text_default_title)
val refusalText = stringResource(id = R.string.onboarding_step7_text_refuse_title)

false -> Pair(
stringResource(id = R.string.onboarding_step7_text_default_title),
core.designsystem.R.drawable.ic_onboarding_authorization_guide,
)
val (text, imageRes) = remember(permissionStatus) {
when (permissionStatus) {
is PermissionStatus.Denied -> {
if (permissionStatus.shouldShowRationale) {
Pair(
refusalText,
core.designsystem.R.drawable.ic_onboarding_authorization_refusal,
)
} else {
Pair(
defaultText,
core.designsystem.R.drawable.ic_onboarding_authorization_guide,
)
}
}

else -> Pair(defaultText, core.designsystem.R.drawable.ic_onboarding_authorization_guide)
}
}

Column(
modifier = Modifier
.fillMaxSize()
.background(OrbitTheme.colors.gray_900)
.statusBarsPadding()
.navigationBarsPadding()
.imePadding(),
) {
OnBoardingTopAppBar(
currentStep = currentStep,
totalSteps = totalSteps,
onBackClick = onBackClick,
showTopAppBarActions = true,
)

Column(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize()
.weight(1f),
) {
Spacer(modifier = Modifier.heightForScreenPercentage(0.05f))

Expand All @@ -84,25 +152,74 @@ fun OnboardingAccessScreen(

Spacer(modifier = Modifier.heightForScreenPercentage(0.123f))

Image(
painter = painterResource(id = imageRes),
contentDescription = null,
if (imageRes != 0) {
Image(
painter = painterResource(id = imageRes),
contentDescription = null,
modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally),
)
}
}

if (permissionStatus is PermissionStatus.Denied && permissionStatus.shouldShowRationale) {
Row(
modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally),
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween,
) {
OrbitButton(
label = "나중에 하기",
modifier = Modifier
.weight(1f)
.padding(end = 8.dp),
onClick = onNavigateToNext,
enabled = true,
containerColor = OrbitTheme.colors.gray_600,
contentColor = OrbitTheme.colors.white,
pressedContainerColor = OrbitTheme.colors.gray_500,
pressedContentColor = OrbitTheme.colors.white.copy(alpha = 0.7f),

)

OrbitButton(
label = "설정으로 가기",
onClick = onNavigateToSettings,
enabled = true,
modifier = Modifier
.weight(1f)
.padding(start = 8.dp),
)
}
} else {
OrbitButton(
label = "네. 알겠어요",
modifier = Modifier
.padding(horizontal = 20.dp)
.padding(bottom = 12.dp),
onClick = onRequestPermission,
enabled = true,
)
}
}
}

@OptIn(ExperimentalPermissionsApi::class)
@Composable
@Preview
fun OnboardingAccessScreenPreview() {
OnboardingAccessScreen(
state = OnboardingContract.State(),
currentStep = 1,
totalSteps = 5,
onNextClick = {},
onBackClick = {},
)
OrbitTheme {
OnboardingAccessScreen(
state = OnboardingContract.State(),
currentStep = 6,
totalSteps = 6,
permissionStatus = PermissionStatus.Denied(shouldShowRationale = true),
onRequestPermission = {},
onNavigateToNext = {},
onBackClick = {},
onNavigateToSettings = {},
)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.kms.onboarding

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -65,10 +69,22 @@ fun OnboardingCompleteScreen1(
.paddingForScreenPercentage(topPercentage = 0.0147f, bottomPercentage = 0.1f),
textAlign = TextAlign.Center,
)
LottieAnimation(
modifier = Modifier.fillMaxSize(),
resId = core.designsystem.R.raw.step2,
)
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
LottieAnimation(
modifier = Modifier.fillMaxSize(),
resId = core.designsystem.R.raw.step2,
)
Image(
painter = painterResource(id = core.designsystem.R.drawable.ic_onboarding_shake_ten),
contentDescription = null,
modifier = Modifier.align(Alignment.BottomCenter)
.paddingForScreenPercentage(bottomPercentage = 0.03f),
)
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ espressoCore = "3.6.1"
material = "1.12.0"
process-pheonix = "3.0.0"
lottie = "6.1.0"
accompanist = "0.37.0"


[libraries]
Expand Down Expand Up @@ -148,6 +149,7 @@ material = { group = "com.google.android.material", name = "material", version.r

process-phoenix = { module = "com.jakewharton:process-phoenix", version.ref = "process-pheonix" }
lottie-compose = { group = "com.airbnb.android", name = "lottie-compose", version.ref= "lottie" }
accompanist-permission = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" }


[plugins]
Expand Down
Loading