-
Notifications
You must be signed in to change notification settings - Fork 1
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
권한 요청 및 gps, 네트워크 상태 관리 다이얼로그 추가 #49
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4ce42b6
:sparkles: gps 상태 관리 usecase 추가
yonghanJu e0b999c
:sparkles: network 상태 관리 usecase 추
yonghanJu a29cc4f
:sparkles: setting 연결 extension 함수 추가
yonghanJu ab0c958
:bookmark: kotlin compile target java 11로 변경
yonghanJu d7ba5be
:sparkles: 권한 요청 플로우 제거
yonghanJu 04d4a52
:sparkles: 상태바 내리기 확장함수 추가
yonghanJu 8b5dae4
:sparkles: 상태바 내리기 권한 추가
yonghanJu 2612454
:sparkles: permissionState, collectAsStateWithLifeCycle 의존성 추가
yonghanJu 3f5866b
:sparkles: AppManageDialog 구현
yonghanJu 9cfd619
:sparkles: 권한 및 설정 상태 관리 앱모듈로 변경
yonghanJu 86fdf67
:sparkles: 전체 동의 텍스트 색상 변경
yonghanJu 4be8eda
:sparkles: 전화번호 제거 및 중복 아이디 확인란 20dp -> 32dp 변경
yonghanJu ef889b0
:bookmark: 1.0.4 버전 release
yonghanJu 51a939c
:bookmark: accompanist 라이브러리 34 api로 변경
yonghanJu f0f76b2
:truck: #49 클래스 및 패키지 이름 변경
yonghanJu eed1801
:bug: #49 클래스명 변경
yonghanJu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
app/src/main/java/com/whyranoid/walkie/walkiedialog/AppManageDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package com.whyranoid.walkie.walkiedialog | ||
|
||
import android.Manifest | ||
import android.app.Activity | ||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.AlertDialog | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.google.accompanist.permissions.ExperimentalPermissionsApi | ||
import com.google.accompanist.permissions.isGranted | ||
import com.google.accompanist.permissions.rememberPermissionState | ||
import com.google.accompanist.permissions.shouldShowRationale | ||
import com.whyranoid.presentation.theme.WalkieColor | ||
import com.whyranoid.presentation.theme.WalkieTypography | ||
import com.whyranoid.presentation.util.openSettings | ||
import com.whyranoid.presentation.util.openStatusBar | ||
import org.koin.androidx.compose.koinViewModel | ||
|
||
/** | ||
* Provide dialog | ||
* | ||
* 권한, gps, 네트워크 상태에 따른 다이얼로그 보여주기 | ||
* | ||
* 분리한 이유: ExperimentalPermissionsApi 로써 언제든 변화 가능하기 때문에 메인 비지니스 로직, UI 로직에 포함시키지 않고 따로 분리 | ||
* | ||
*/ | ||
|
||
@RequiresApi(Build.VERSION_CODES.TIRAMISU) | ||
@OptIn(ExperimentalPermissionsApi::class) | ||
@Composable | ||
fun AppManageDialog() { | ||
val viewModel = koinViewModel<DialogViewModel>() | ||
val activity = LocalContext.current as Activity | ||
|
||
val locationPermissionState = rememberPermissionState( | ||
Manifest.permission.ACCESS_FINE_LOCATION, | ||
) { isGranted -> | ||
viewModel.setPermission(Manifest.permission.ACCESS_FINE_LOCATION, isGranted) | ||
} | ||
|
||
val storagePermissionState = rememberPermissionState( | ||
Manifest.permission.READ_EXTERNAL_STORAGE, | ||
) { isGranted -> | ||
viewModel.setPermission(Manifest.permission.READ_EXTERNAL_STORAGE, isGranted) | ||
} | ||
|
||
val locationDialogState = viewModel.locationPermissionDialogState.collectAsStateWithLifecycle() | ||
val storageDialogState = viewModel.storagePermissionDialogState.collectAsStateWithLifecycle() | ||
val gpsDialogState = | ||
viewModel.gpsDialogState.collectAsStateWithLifecycle(initialValue = DialogState.Initialized) | ||
val networkDialogState = | ||
viewModel.networkDialogState.collectAsStateWithLifecycle(initialValue = DialogState.Initialized) | ||
|
||
LaunchedEffect( | ||
locationDialogState.value, | ||
storageDialogState.value, | ||
gpsDialogState.value, | ||
networkDialogState.value, | ||
) { | ||
if (locationPermissionState.status.isGranted.not() && locationPermissionState.status.shouldShowRationale.not()) { | ||
locationPermissionState.launchPermissionRequest() | ||
} else if (storagePermissionState.status.isGranted.not() && storagePermissionState.status.shouldShowRationale.not()) { | ||
storagePermissionState.launchPermissionRequest() | ||
} | ||
} | ||
|
||
if (locationPermissionState.status.isGranted.not() && locationPermissionState.status.shouldShowRationale) { | ||
PermissionDialog( | ||
dialog = DialogContentProvider.LocationPermission, | ||
onAction = { activity.openSettings() }, | ||
modifier = Modifier.clip(RoundedCornerShape(20.dp)), | ||
) | ||
} else if (storagePermissionState.status.isGranted.not() && storagePermissionState.status.shouldShowRationale) { | ||
PermissionDialog( | ||
dialog = DialogContentProvider.StoragePermission, | ||
onAction = { activity.openSettings() }, | ||
modifier = Modifier.clip(RoundedCornerShape(20.dp)), | ||
) | ||
} else if (gpsDialogState.value is DialogState.InValid) { | ||
PermissionDialog( | ||
dialog = DialogContentProvider.GPS, | ||
onAction = { | ||
activity.openStatusBar() | ||
}, | ||
modifier = Modifier.clip(RoundedCornerShape(20.dp)), | ||
) | ||
} else if (networkDialogState.value is DialogState.InValid) { | ||
PermissionDialog( | ||
dialog = DialogContentProvider.Network, | ||
onAction = { | ||
activity.openStatusBar() | ||
}, | ||
modifier = Modifier.clip(RoundedCornerShape(20.dp)), | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun PermissionDialog( | ||
dialog: DialogContentProvider, | ||
onAction: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
AlertDialog( | ||
onDismissRequest = onAction, | ||
buttons = { | ||
Column(modifier = Modifier.fillMaxWidth()) { | ||
Text( | ||
text = "동의", | ||
style = WalkieTypography.SubTitle.copy(color = WalkieColor.Primary), | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier | ||
.align(Alignment.End) | ||
.clickable( | ||
indication = null, | ||
interactionSource = remember { MutableInteractionSource() }, | ||
) { | ||
onAction() | ||
} | ||
.padding(bottom = 20.dp) | ||
.padding(horizontal = 20.dp) | ||
.clip(RoundedCornerShape(12.dp)), | ||
) | ||
} | ||
}, | ||
title = { Text(dialog.title, style = WalkieTypography.SubTitle) }, | ||
text = { | ||
Text( | ||
text = dialog.description, | ||
style = WalkieTypography.Body1_Normal, | ||
) | ||
}, | ||
modifier = modifier, | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/whyranoid/walkie/walkiedialog/DialogContentProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.whyranoid.walkie.walkiedialog | ||
|
||
sealed class DialogContentProvider( | ||
val title: String, | ||
val description: String, | ||
) { | ||
object LocationPermission : | ||
DialogContentProvider( | ||
"위치 정보 제공 동의", | ||
"러닝 기능을 사용하려면 사용자의 위치 권한 동의가 반드시 필요해요.", | ||
) { | ||
const val PERMISSION = android.Manifest.permission.ACCESS_FINE_LOCATION | ||
} | ||
|
||
object StoragePermission : DialogContentProvider( | ||
"미디어 및 파일 접근 동의", | ||
"러닝 정보를 기록하려면 미디어 및 파일 접근 권한 동의가 반드시 필요해요.", | ||
) { | ||
const val PERMISSION = android.Manifest.permission.READ_EXTERNAL_STORAGE | ||
} | ||
|
||
object GPS : DialogContentProvider( | ||
"위치 상태 확인 요망", | ||
"러닝 기능을 사용하려면 위치 정보 상태가 켜져야해요.", | ||
) | ||
|
||
object Network : DialogContentProvider( | ||
"네트워크 상태 확인 요망", | ||
"러닝 기능을 사용하려면 네트워트가 연결되어야해요.", | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/whyranoid/walkie/walkiedialog/DialogState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.whyranoid.walkie.walkiedialog | ||
|
||
sealed class DialogState { | ||
object Initialized : DialogState() | ||
|
||
object Valid : DialogState() | ||
|
||
data class InValid(val dialogContentProvider: DialogContentProvider) : DialogState() | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/whyranoid/walkie/walkiedialog/DialogViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.whyranoid.walkie.walkiedialog | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.whyranoid.domain.usecase.broadcast.AddGpsListener | ||
import com.whyranoid.domain.usecase.broadcast.AddNetworkListener | ||
import com.whyranoid.domain.usecase.broadcast.GetGpsState | ||
import com.whyranoid.domain.usecase.broadcast.GetNetworkState | ||
import com.whyranoid.domain.usecase.broadcast.RemoveGpsListener | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class DialogViewModel( | ||
private val addNetworkListener: AddNetworkListener, | ||
private val removeNetworkListener: AddNetworkListener, | ||
private val getNetworkState: GetNetworkState, | ||
private val addGpsListener: AddGpsListener, | ||
private val removeGpsListener: RemoveGpsListener, | ||
private val getGpsState: GetGpsState, | ||
) : ViewModel() { | ||
init { | ||
addNetworkListener() | ||
addGpsListener() | ||
} | ||
|
||
private val _locationPermissionDialogState = | ||
MutableStateFlow<DialogState>(DialogState.Initialized) | ||
private val _storagePermissionDialogState = | ||
MutableStateFlow<DialogState>(DialogState.Initialized) | ||
|
||
val locationPermissionDialogState get() = _locationPermissionDialogState.asStateFlow() | ||
val storagePermissionDialogState get() = _storagePermissionDialogState.asStateFlow() | ||
|
||
val gpsDialogState = getGpsState().map { | ||
if (it) DialogState.Valid else DialogState.InValid(DialogContentProvider.GPS) | ||
} | ||
val networkDialogState = getNetworkState().map { | ||
if (it) DialogState.Valid else DialogState.InValid(DialogContentProvider.Network) | ||
} | ||
|
||
fun setPermission(permission: String, showDialog: Boolean) { | ||
if (permission == DialogContentProvider.LocationPermission.PERMISSION) { | ||
_locationPermissionDialogState.value = | ||
if (showDialog) DialogState.Valid else DialogState.InValid(DialogContentProvider.LocationPermission) | ||
} else if (permission == DialogContentProvider.StoragePermission.PERMISSION) { | ||
_storagePermissionDialogState.value = | ||
if (showDialog) DialogState.Valid else DialogState.InValid(DialogContentProvider.StoragePermission) | ||
} | ||
} | ||
|
||
override fun onCleared() { | ||
removeGpsListener() | ||
removeNetworkListener() | ||
super.onCleared() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/whyranoid/walkie/wlakiedialog/DialogState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.whyranoid.walkie.wlakiedialog | ||
|
||
import com.whyranoid.walkie.walkiedialog.DialogContentProvider | ||
|
||
sealed class DialogState { | ||
object Initialized : DialogState() | ||
|
||
object Valid : DialogState() | ||
|
||
data class InValid(val dialogContentProvider: DialogContentProvider) : DialogState() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
domain/src/main/java/com/whyranoid/domain/usecase/broadcast/AddGpsListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.whyranoid.domain.usecase.broadcast | ||
|
||
import com.whyranoid.domain.repository.GpsRepository | ||
|
||
class AddGpsListener(private val gpsRepository: GpsRepository) { | ||
operator fun invoke() { | ||
gpsRepository.registerReceiver() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
domain/src/main/java/com/whyranoid/domain/usecase/broadcast/AddNetworkListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.whyranoid.domain.usecase.broadcast | ||
|
||
import com.whyranoid.domain.repository.NetworkRepository | ||
|
||
class AddNetworkListener(private val networkRepository: NetworkRepository) { | ||
operator fun invoke() { | ||
networkRepository.addNetworkConnectionCallback() | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
얜 뭔가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gps, 네트워크가 없을 때 뜨는 다이얼로그에 연결동작으로 상단 상태바 내려와서 바로 설정할 수 있게 해주는데 필요한 권한입니다