Skip to content

Commit

Permalink
Merge pull request #193 from TeamDMU/feature/permission-alarm
Browse files Browse the repository at this point in the history
Feat : 알림 권한 설정
  • Loading branch information
huiwoo-jo authored Mar 25, 2024
2 parents e162536 + 1e21f38 commit 6c29fc8
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 37 deletions.
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

0 comments on commit 6c29fc8

Please sign in to comment.