diff --git a/app/build.gradle b/app/build.gradle index 45671f18..e81c7552 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ plugins { } android { - compileSdk 32 + compileSdk 33 Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) @@ -14,7 +14,7 @@ android { defaultConfig { applicationId "com.dongyang.android.youdongknowme" minSdk 24 - targetSdk 32 + targetSdk 33 versionCode 5 versionName "1.0.3" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e8dd9271..9e44f80d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" /> + () { override fun initDataBinding() {} override fun initAfterBinding() {} + + companion object { + fun createIntent(context: Context): Intent { + return Intent(context, MainActivity::class.java) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/permission/OnboardingPermissionActivity.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/permission/OnboardingPermissionActivity.kt index 5363d67a..6d6af0a3 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/permission/OnboardingPermissionActivity.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/permission/OnboardingPermissionActivity.kt @@ -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 @@ -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) } @@ -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) } } \ No newline at end of file diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashActivity.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashActivity.kt index f1bb17e1..5bd26d49 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashActivity.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashActivity.kt @@ -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 @@ -17,40 +20,71 @@ import kotlinx.coroutines.launch import org.koin.androidx.viewmodel.ext.android.viewModel @SuppressLint("CustomSplashScreen") -class SplashActivity : AppCompatActivity() { +class SplashActivity : BaseActivity() { - 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, + 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() @@ -63,5 +97,6 @@ class SplashActivity : AppCompatActivity() { companion object { private const val SPLASH_TIME_MILLIS = 1_500L + private const val REQUEST_PERMISSION_CODE = 100 } } \ No newline at end of file diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashViewModel.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashViewModel.kt index 87eb9e41..66464bc8 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashViewModel.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/splash/SplashViewModel.kt @@ -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 = MutableLiveData(false) + val isFirstLaunch: LiveData get() = _isFirstLaunch fun checkFirstLaunch() { if (splashRepository.getIsFirstLaunch()) { - _isFirstLaunch = true + _isFirstLaunch.value = true } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_onboarding_permission.xml b/app/src/main/res/layout/activity_onboarding_permission.xml index 78334ecd..d7e70a5a 100644 --- a/app/src/main/res/layout/activity_onboarding_permission.xml +++ b/app/src/main/res/layout/activity_onboarding_permission.xml @@ -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">