Skip to content

Commit

Permalink
[FEAT/#55] check permission dialog and setting
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Sep 21, 2024
1 parent 0e50c29 commit 77db613
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package com.kkkk.presentation.onboarding.splash

import android.Manifest
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.view.View
import androidx.activity.viewModels
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.kkkk.core.base.BaseActivity
Expand All @@ -29,8 +41,15 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
setStatusBarColor()
setNavigationBarColor()
observeStates()
}

viewModel.checkTokenState()
override fun onResume() {
super.onResume()
if (isActivityRecognitionPermissionGranted(this)) {
viewModel.checkTokenState()
} else {
showDialog()
}
}

private fun setStatusBarColor() = setStatusBarColorFromResource(R.color.purple_50)
Expand Down Expand Up @@ -65,6 +84,65 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(R.layout.activity_spl
viewModel.setAndroidId(getDeviceTag())
}

private fun isActivityRecognitionPermissionGranted(context: Context): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACTIVITY_RECOGNITION
) == PackageManager.PERMISSION_GRANTED
} else {
// Android Q 미만 버전에서는 이 권한이 필요하지 않으므로 항상 true 반환
true
}
}

private fun showDialog() {
val dialog = Dialog(this)
dialog.setContentView(R.layout.dialog_single_button)
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.setCanceledOnTouchOutside(false)
dialog.setCancelable(false)
dialog.show()

dialog.findViewById<View>(R.id.btn_onboarding_start_measure).setOnClickListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACTIVITY_RECOGNITION),
200
)
} else {
navigateToSettings()
}
}
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray,
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)

if (requestCode == 200) {
if (permissions.isNotEmpty() && permissions[0] == Manifest.permission.ACTIVITY_RECOGNITION) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
viewModel.checkTokenState()
} else {
navigateToSettings()
}
}
}
}

private fun navigateToSettings() {
Intent().apply {
action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
data = Uri.fromParts("package", packageName, null)
startActivity(this)
}
}

@SuppressLint("HardwareIds")
private fun getDeviceTag(): String =
Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
Expand Down
75 changes: 75 additions & 0 deletions presentation/src/main/res/layout/dialog_single_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_white_fill_16_rect"
app:cardCornerRadius="16dp"
app:cardElevation="4dp">


<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">

<TextView
android:id="@+id/tvTitle"
style="@style/TextAppearance.Stempo.Head3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="앱 권한 설정 필요"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/subTitle"
style="@style/TextAppearance.Stempo.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="스템포 이용을 위해서는 \n접근 권한 허용이 필요해요."
android:textColor="@color/gray_500"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />

<TextView
android:id="@+id/tvContent"
style="@style/TextAppearance.Stempo.Body2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginTop="12dp"
android:gravity="start"
android:text=" - 신체활동 권한\n - 걸음 수 측정 및 기록"
android:textColor="@color/gray_700"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/subTitle" />

<TextView
android:id="@+id/btn_onboarding_start_measure"
style="@style/TextAppearance.Stempo.Head4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:background="@drawable/shape_purple50_fill_12_rect"
android:gravity="center"
android:paddingVertical="15dp"
android:text="@string/ok"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvContent" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string name="ing">측정 중...</string>
<string name="before_page">이전페이지</string>
<string name="next_page">다음페이지</string>
<string name="ok">확인</string>

<string name="menu_rhythm">리듬</string>
<string name="menu_report">기록</string>
Expand Down

0 comments on commit 77db613

Please sign in to comment.