From 0e4334cff4450ff47d4ef73387a973e15f2b1a73 Mon Sep 17 00:00:00 2001 From: easyhz Date: Fri, 30 Aug 2024 13:09:47 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=95=8C=EB=A6=BC=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99=20(#185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../my_page/screen/MyPageMenuViewModel.kt | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt index c2389e72..591fd159 100644 --- a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt +++ b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt @@ -57,7 +57,8 @@ class MyPageMenuViewModel @Inject constructor( } private fun handleNotificationMenu() { - reduce { copy(isCheckedNotification = !currentState.isCheckedNotification) } + navigateNotificationSetting() +// reduce { copy(isCheckedNotification = !currentState.isCheckedNotification) } } private fun handleNoticeMenu() { @@ -113,4 +114,35 @@ class MyPageMenuViewModel @Inject constructor( private fun showSnackBar(stringId: Int) { postSideEffect { MenuSideEffect.ShowSnackBar(stringId) } } + + private fun navigateNotificationSetting() { + val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + notificationSettingOreo(context) + } else { + notificationSettingOreoLess(context) + } + try { + context.startActivity(intent) + }catch (e: ActivityNotFoundException) { + e.printStackTrace() + } + } + + @RequiresApi(Build.VERSION_CODES.O) + private fun notificationSettingOreo(context: Context): Intent { + return Intent().also { intent -> + intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS + intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + } + } + + private fun notificationSettingOreoLess(context: Context): Intent { + return Intent().also { intent -> + intent.action = "android.settings.APP_NOTIFICATION_SETTINGS" + intent.putExtra("app_package", context.packageName) + intent.putExtra("app_uid", context.applicationInfo?.uid) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + } + } } \ No newline at end of file