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 : 알림 권한 설정 #193

Merged
merged 21 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f8db57c
Chore : Sdk 업데이트 및 알림 권한 추가
huiwoo-jo Mar 17, 2024
33c06bc
design : 권한 스위치 기본 테두리 색 변경
huiwoo-jo Mar 17, 2024
deb603b
refactor : 온보딩 화면에서의 권한 설정
huiwoo-jo Mar 17, 2024
bf65980
refactor : 권한 요청 확장함수로 분리
huiwoo-jo Mar 17, 2024
1b0632d
refactor : SplashActivity의 BaseActivity 상속 추가
huiwoo-jo Mar 17, 2024
ca712ba
fix : 오류로 인한 확장함수 제거
huiwoo-jo Mar 17, 2024
65d554d
refactor : splash viewModel 수정
huiwoo-jo Mar 17, 2024
1d0da5d
refactor : 스플래시 화면 처음 시작시 권한 요청
huiwoo-jo Mar 17, 2024
94f289b
refactor : 권한 설정 확장함수 제거
huiwoo-jo Mar 17, 2024
efa468c
refactor : 알림 권한 거부 상태에서 알림 -> 세팅 화면으로 이동
huiwoo-jo Mar 20, 2024
573e462
refactor : 미사용 호출 제거 및 자동 정렬
huiwoo-jo Mar 20, 2024
60783d9
Comment : 권한 설정에 따른 주석추가
huiwoo-jo Mar 20, 2024
de9eff3
refactor : 불필요한 인자 호출 제거
huiwoo-jo Mar 20, 2024
34a62c3
refactor : 불필요 변화 재설정
huiwoo-jo Mar 20, 2024
193074b
Merge branch 'develop' into feature/permission-alarm
huiwoo-jo Mar 20, 2024
9591efd
refactor : 스위치 체크 초기화 방식 변경
huiwoo-jo Mar 23, 2024
6d79440
style : 함수 매개변수 줄바꿈
huiwoo-jo Mar 23, 2024
be342d5
Merge branch 'feature/permission-alarm' of https://github.com/TeamDMU…
huiwoo-jo Mar 23, 2024
45a682f
style : 자동 정렬
huiwoo-jo Mar 23, 2024
f740b0f
refactor : requestCode 상수화
huiwoo-jo Mar 23, 2024
1e21f38
refactor : intent 객체화
huiwoo-jo Mar 23, 2024
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
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ plugins {
}

android {
compileSdk 32
compileSdk 33

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

defaultConfig {
applicationId "com.dongyang.android.youdongknowme"
minSdk 24
targetSdk 32
targetSdk 33
versionCode 5
versionName "1.0.3"

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.POST_NOTIFICATIONS"
android:minSdkVersion="33" />

<application
android:name=".standard.MyApplication"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dongyang.android.youdongknowme.ui.view.depart

import android.content.Context
import android.content.Intent
import androidx.recyclerview.widget.LinearLayoutManager
import com.dongyang.android.youdongknowme.R
Expand Down Expand Up @@ -73,4 +74,10 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
}
}
}

companion object {
fun createIntent(context: Context): Intent {
return Intent(context, OnboardingDepartActivity::class.java)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dongyang.android.youdongknowme.ui.view.main

import android.content.Context
import android.content.Intent
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.plusAssign
import androidx.navigation.ui.setupWithNavController
Expand Down Expand Up @@ -31,4 +33,10 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
override fun initDataBinding() {}

override fun initAfterBinding() {}

companion object {
fun createIntent(context: Context): Intent {
return Intent(context, MainActivity::class.java)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.dongyang.android.youdongknowme.ui.view.permission

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.net.Uri
import android.provider.Settings
import androidx.core.content.ContextCompat
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.ActivityOnboardingPermissionBinding
Expand All @@ -18,10 +21,9 @@ class OnboardingPermissionActivity :
override val viewModel: SettingViewModel by viewModel()

override fun initStartView() {
setPermission(false)

viewModel.checkAccessAlarm()
viewModel.getUserDepartment()
setPermissionSwitch(false)

setSpanText(this, binding.tvPermissionTitleMain, startIdx = 0, endIdx = 9)
}
Expand All @@ -30,28 +32,50 @@ class OnboardingPermissionActivity :

override fun initAfterBinding() {
binding.btnPermissionComplete.setOnClickListener {
val intent = Intent(this@OnboardingPermissionActivity, MainActivity::class.java)
val intent = MainActivity.createIntent(this@OnboardingPermissionActivity)
startActivity(intent)
finish()
}

binding.switchPermission.setOnCheckedChangeListener { compoundButton, _ ->
if (compoundButton.isChecked) {
setPermission(true)
binding.switchPermission.compoundDrawableTintList =
ColorStateList.valueOf(ContextCompat.getColor(this, R.color.blue300))
// 권환 확인 전 스위치 초기화
binding.switchPermission.isChecked = false

// 온보딩 알림 스위치를 활성화
if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(
this, Manifest.permission.POST_NOTIFICATIONS
)
) {
// 알림 권한이 허용 상태
setPermissionSwitch(true)
} else {
// 알림 권한이 미허용 상태
val intent =
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:" + this.packageName))
startActivity(intent)
}
} else {
setPermission(false)
binding.switchPermission.compoundDrawableTintList =
ColorStateList.valueOf(ContextCompat.getColor(this, R.color.gray300))
binding.switchPermission.setTextColor(getColor(R.color.gray300))
// 온보딩 알림 스위치 비활성화
setPermissionSwitch(false)
}
}
}

private fun setPermission(boolean: Boolean) {
binding.switchPermission.isChecked = boolean
viewModel.setIsAccessSchoolAlarm(boolean)
viewModel.setIsAccessDepartAlarm(boolean)
private fun setPermissionSwitch(isChecked: Boolean) {
val resources = if (isChecked) {
R.color.blue300
} else {
R.color.gray300
}

binding.switchPermission.compoundDrawableTintList =
ColorStateList.valueOf(ContextCompat.getColor(this, resources))
binding.switchPermission.setTextColor(getColor(resources))
binding.mvSwitchPermission.strokeColor = getColor(resources)

binding.switchPermission.isChecked = isChecked
viewModel.setIsAccessSchoolAlarm(isChecked)
viewModel.setIsAccessDepartAlarm(isChecked)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.dongyang.android.youdongknowme.ui.view.splash

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.ActivitySplashBinding
import com.dongyang.android.youdongknowme.ui.view.depart.DepartActivity
import com.dongyang.android.youdongknowme.standard.base.BaseActivity
import com.dongyang.android.youdongknowme.ui.view.depart.OnboardingDepartActivity
import com.dongyang.android.youdongknowme.ui.view.main.MainActivity
import kotlinx.coroutines.Job
Expand All @@ -17,40 +20,71 @@ import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.viewModel

@SuppressLint("CustomSplashScreen")
class SplashActivity : AppCompatActivity() {
class SplashActivity : BaseActivity<ActivitySplashBinding, SplashViewModel>() {

private var intentJob: Job? = null
private lateinit var binding: ActivitySplashBinding
private val viewModel: SplashViewModel by viewModel()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override val layoutResourceId: Int = R.layout.activity_splash
override val viewModel: SplashViewModel by viewModel()

binding = ActivitySplashBinding.inflate(layoutInflater)
setContentView(binding.root)
private var intentJob: Job? = null

override fun initStartView() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val content: View = findViewById(android.R.id.content)
content.viewTreeObserver.addOnPreDrawListener { false }
}

viewModel.checkFirstLaunch()
}

override fun initDataBinding() = Unit

override fun initAfterBinding() {
intentJob = lifecycleScope.launch {
delay(SPLASH_TIME_MILLIS)

if(viewModel.isFirstLaunch) {
val intent = Intent(this@SplashActivity, OnboardingDepartActivity::class.java)
startActivity(intent)
finish()
if (viewModel.isFirstLaunch.value == true) {
val intent = OnboardingDepartActivity.createIntent(this@SplashActivity)

if (PackageManager.PERMISSION_DENIED == ContextCompat.checkSelfPermission(
this@SplashActivity, Manifest.permission.POST_NOTIFICATIONS
)
) {
// 알림 권한 설정 허용
ActivityCompat.requestPermissions(
this@SplashActivity, arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQUEST_PERMISSION_CODE
)
} else {
// 알림 권한 설정 미허용
startActivity(intent)
finish()
}
} else {
val intent = Intent(this@SplashActivity, MainActivity::class.java)
intent = MainActivity.createIntent(this@SplashActivity)
startActivity(intent)
finish()
}
}
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_PERMISSION_CODE) {
// 권한 설정 결과 처리
intent = if (viewModel.isFirstLaunch.value == true) {
OnboardingDepartActivity.createIntent(this@SplashActivity)
} else {
MainActivity.createIntent(this@SplashActivity)
}
startActivity(intent)
finish()
}
}


override fun onBackPressed() {
intentJob?.cancel()
super.onBackPressed()
Expand All @@ -63,5 +97,6 @@ class SplashActivity : AppCompatActivity() {

companion object {
private const val SPLASH_TIME_MILLIS = 1_500L
private const val REQUEST_PERMISSION_CODE = 100
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.dongyang.android.youdongknowme.ui.view.splash

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.dongyang.android.youdongknowme.data.repository.SplashRepository
import com.dongyang.android.youdongknowme.standard.base.BaseViewModel

class SplashViewModel(private val splashRepository: SplashRepository) : BaseViewModel() {

private var _isFirstLaunch: Boolean = false
val isFirstLaunch: Boolean get() = _isFirstLaunch
private val _isFirstLaunch: MutableLiveData<Boolean> = MutableLiveData(false)
val isFirstLaunch: LiveData<Boolean> get() = _isFirstLaunch

fun checkFirstLaunch() {
if (splashRepository.getIsFirstLaunch()) {
_isFirstLaunch = true
_isFirstLaunch.value = true
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_onboarding_permission.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/onboarding_permission_step"
app:strokeColor="@color/blue300"
app:strokeColor="@color/gray300"
app:strokeWidth="3dp">

<androidx.appcompat.widget.SwitchCompat
Expand Down
Loading