-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from step-Mate/home
fix : 권한 처리 플로우 수정
- Loading branch information
Showing
13 changed files
with
390 additions
and
233 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": 3, | ||
"artifactType": { | ||
"type": "APK", | ||
"kind": "Directory" | ||
}, | ||
"applicationId": "com.stepmate.app", | ||
"variantName": "release", | ||
"elements": [ | ||
{ | ||
"type": "SINGLE", | ||
"filters": [], | ||
"attributes": [], | ||
"versionCode": 5, | ||
"versionName": "1.0.0", | ||
"outputFile": "app-release.apk" | ||
} | ||
], | ||
"elementType": "File" | ||
} |
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
45 changes: 3 additions & 42 deletions
45
app/src/main/kotlin/com/stepmate/app/ui/StepMateViewModel.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 |
---|---|---|
@@ -1,61 +1,22 @@ | ||
package com.stepmate.app.ui | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import com.stepmate.app.ui.navigation.permission.PermissionRequester | ||
import com.stepmate.domain.usecase.user.GetBodyDataUseCases | ||
import com.stepmate.home.HealthConnector | ||
import com.stepmate.home.HealthConnector.Companion.healthConnectPermissions | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.flow.update | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
internal class StepMateViewModel @Inject constructor( | ||
@ApplicationContext private val applicationContext: Context, | ||
private val healthConnector: HealthConnector, | ||
private val getBodyDataUseCases: GetBodyDataUseCases, | ||
savedStateHandle: SavedStateHandle, | ||
) : ViewModel() { | ||
|
||
private val _permissionState = MutableStateFlow(false) | ||
val permissionState get() = _permissionState.asStateFlow() | ||
|
||
private val _isBodyDataExist = MutableStateFlow(false) | ||
val isBodyDataExist get() = _isBodyDataExist.asStateFlow() | ||
val isBodyDataExist: Boolean = savedStateHandle["isBodyDataExist"] ?: false | ||
|
||
private val _isNeedReLogin = MutableStateFlow(false) | ||
val isNeedReLogin get() = _isNeedReLogin.asStateFlow() | ||
|
||
suspend fun checkPermission() { | ||
val isNotificationGranted = | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) | ||
PermissionRequester.checkNotification(applicationContext) | ||
else | ||
true | ||
|
||
val isActivityRecognitionGranted = | ||
PermissionRequester.checkActivityRecognition(applicationContext) | ||
|
||
val isExactAlarmGranted = | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) | ||
PermissionRequester.checkExactAlarm(applicationContext) | ||
else | ||
true | ||
|
||
val isHealthConnectGranted = healthConnector.checkPermissions(healthConnectPermissions) | ||
isBodyDataExist() | ||
_permissionState.update { isNotificationGranted && isActivityRecognitionGranted && isExactAlarmGranted && isHealthConnectGranted } | ||
} | ||
|
||
private suspend fun isBodyDataExist() = getBodyDataUseCases().onEach { bodyData -> | ||
_isBodyDataExist.update { bodyData.age != 0 && bodyData.height != 0 && bodyData.weight != 0 } | ||
}.first() | ||
|
||
fun updateIsNeedLogin(bool: Boolean) = _isNeedReLogin.update { bool } | ||
} |
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
Oops, something went wrong.