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/#52] 위치 권한 요청 다이얼로그 #72

Merged
merged 1 commit into from
Jan 19, 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: 2 additions & 0 deletions core/utils/feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ android {

dependencies {

implementation(project(":core:designsystem"))

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import kotlinx.coroutines.withContext
/**
* 위치 권한을 확인하고 요청하는 컴포저블
* @param onPermissionGranted 권한이 허용되었을 때 실행할 동작
* TODO : 다이얼로그 컴포넌트 생성 후 수정
*/
@OptIn(ExperimentalPermissionsApi::class)
@Composable
Expand All @@ -36,18 +35,13 @@ fun CheckAndRequestLocationPermission(
}
}
)

val permissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permMap ->
if (permMap[Manifest.permission.ACCESS_FINE_LOCATION] == true) {
onPermissionGranted()
showPermissionDialog = false
}
}

// if (showPermissionDialog)
// AconConfirmDialog(...)
if (showPermissionDialog)
AconPermissionDialog(
onPermissionGranted = {
showPermissionDialog = false
onPermissionGranted()
}
)

LaunchedEffect(trigger) {
withContext(Dispatchers.Main.immediate) {
Expand All @@ -56,10 +50,10 @@ fun CheckAndRequestLocationPermission(
} else {
if (locationPermissionState.shouldShowRationale) {
showPermissionDialog = true
// TODO : 다이얼로그의 버튼 클릭 시 아래 코드 실행
// permissionLauncher.launch(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION))
} else {
locationPermissionState.launchMultiplePermissionRequest()
if (trigger == 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 trigger는 권한을 의미하는 것인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

권한 요청 다이얼로그를 띄울 조건을 명시해준 것입니다!
사실 좋은 방식은 아닌 것 같은데, 사용하는 측에서 편하려면 (제 머리로는) 이게 최선이었어요 ㅠ_ㅠ

showPermissionDialog = true
} else locationPermissionState.launchMultiplePermissionRequest()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.acon.core.utils.feature.permission

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.provider.Settings
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.content.ContextCompat
import com.acon.core.designsystem.component.dialog.AconOneButtonDialog
import com.acon.core.utils.feature.R

@Composable
internal fun AconPermissionDialog(
onPermissionGranted: () -> Unit,
modifier: Modifier = Modifier
) {

val context = LocalContext.current
val settingsLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
if (ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
) { onPermissionGranted() }
}

AconOneButtonDialog(
title = stringResource(R.string.no_permission_title),
content = stringResource(R.string.no_permission_content),
buttonContent = stringResource(R.string.go_to_setting),
onDismissRequest = {},
onClickConfirm = {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.parse("package:${context.packageName}")
}
settingsLauncher.launch(intent)
}
)
}

@Preview
@Composable
private fun AconPermissionDialogPreview() {
AconPermissionDialog({})
}
6 changes: 6 additions & 0 deletions core/utils/feature/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="no_permission_title">\'acon\'에 대해 위치접근\n 권한이 없습니다</string>
<string name="no_permission_content">설정에서 정확한 위치 권한을 허용해주세요</string>
<string name="go_to_setting">설정으로 가기</string>
</resources>