From b8f383e30a901294e2fffe87f67a115c2a7ae526 Mon Sep 17 00:00:00 2001 From: Sangwook123 Date: Wed, 10 Jan 2024 08:49:47 +0900 Subject: [PATCH] =?UTF-8?q?[chore]=20#231=20=EC=BD=94=EB=93=9C=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../winey/presentation/main/MainActivity.kt | 8 +-- .../main/mypage/MyPageFragment.kt | 69 ++++++++++--------- app/src/main/res/values/strings.xml | 3 +- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt index 9947953c..74615f22 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt @@ -44,9 +44,9 @@ class MainActivity : BindingActivity(R.layout.activity_main registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> if (!isGranted) { wineySnackbar( - binding.root, - true, - stringOf(R.string.snackbar_notification_permission_fail) + anchorView = binding.root, + isSuccess = false, + message = stringOf(R.string.snackbar_notification_permission_fail) ) } } @@ -213,7 +213,5 @@ class MainActivity : BindingActivity(R.layout.activity_main private const val KEY_TO_MYPAGE = "navigateMypage" private const val VAL_MY_FEED_SCREEN = "MyFeedFragment" - - private const val CODE_NOTIFICATION_PERMISSION = 1020 } } diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt index fe76ebe6..0665653f 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt @@ -38,7 +38,6 @@ import org.go.sopt.winey.presentation.nickname.NicknameActivity import org.go.sopt.winey.presentation.onboarding.guide.GuideActivity import org.go.sopt.winey.util.amplitude.AmplitudeUtils import org.go.sopt.winey.util.binding.BindingFragment -import org.go.sopt.winey.util.context.stringOf import org.go.sopt.winey.util.fragment.WineyDialogFragment import org.go.sopt.winey.util.fragment.snackBar import org.go.sopt.winey.util.fragment.stringOf @@ -59,7 +58,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ @Inject lateinit var amplitudeUtils: AmplitudeUtils - private var isNotificationAllowed = true + private var isNotificationPermissionAllowed = true override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -88,7 +87,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ } private fun initCheckNotificationPermission() { - isNotificationAllowed = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + isNotificationPermissionAllowed = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { ContextCompat.checkSelfPermission( requireContext(), Manifest.permission.POST_NOTIFICATIONS @@ -124,7 +123,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ private fun initAllowedNotificationButtonClickListener() { binding.ivMypageSwitch.setOnClickListener { - when (isNotificationAllowed) { + when (isNotificationPermissionAllowed) { true -> { val isAllowed = when (binding.ivMypageAgree.currentState) { R.id.start -> false @@ -133,24 +132,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ } when (isAllowed) { true -> { - val dialog = WineyDialogFragment.newInstance( - WineyDialogLabel( - stringOf(R.string.notification_off_dialog_title), - stringOf(R.string.notification_off_dialog_subtitle), - stringOf(R.string.notification_off_dialog_negative_button), - stringOf(R.string.notification_off_dialog_positive_button) - ), - handleNegativeButton = {}, - handlePositiveButton = { - binding.ivMypageAgree.transitionToState(R.id.start, -1) - patchUserInfo() - myPageViewModel.patchAllowedNotification(isAllowed) - } - ) - dialog.show( - parentFragmentManager, - TAG_NOTIFICATION_OFF_DIALOG - ) + showNotificationOffDialog(isAllowed) } false -> { @@ -165,24 +147,45 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ wineySnackbar( binding.root, true, - stringOf(R.string.snackbar_mypage_permission_fail) + stringOf(R.string.snackbar_notification_permission_fail) ) } } } } + private fun showNotificationOffDialog(isAllowed: Boolean) { + val dialog = WineyDialogFragment.newInstance( + WineyDialogLabel( + stringOf(R.string.notification_off_dialog_title), + stringOf(R.string.notification_off_dialog_subtitle), + stringOf(R.string.notification_off_dialog_negative_button), + stringOf(R.string.notification_off_dialog_positive_button) + ), + handleNegativeButton = {}, + handlePositiveButton = { + binding.ivMypageAgree.transitionToState(R.id.start, -1) + patchUserInfo() + myPageViewModel.patchAllowedNotification(isAllowed) + } + ) + dialog.show( + parentFragmentManager, + TAG_NOTIFICATION_OFF_DIALOG + ) + } + private fun initNotificationPermissionChangeButtonClickListener() { binding.llMypageAgreePermissionChange.setOnClickListener { - presentNotificationSetting(requireContext()) + navigateToNotificationSetting(requireContext()) } } - fun presentNotificationSetting(context: Context) { + private fun navigateToNotificationSetting(context: Context) { val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - notificationSettingOreo(context) + setNotificationIntentActionOreo(context) } else { - notificationSettingOreoLess(context) + setNorificationIntentActionOreoLess(context) } try { context.startActivity(intent) @@ -191,7 +194,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ } } - fun notificationSettingOreo(context: Context): Intent { + private fun setNotificationIntentActionOreo(context: Context): Intent { return Intent().also { intent -> intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) @@ -199,7 +202,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ } } - fun notificationSettingOreoLess(context: Context): Intent { + private fun setNorificationIntentActionOreoLess(context: Context): Intent { return Intent().also { intent -> intent.action = "android.settings.APP_NOTIFICATION_SETTINGS" intent.putExtra("app_package", context.packageName) @@ -221,11 +224,11 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ super.onStart() mainViewModel.getUser() initCheckNotificationPermission() - checkIsNotificationAllowed() + changeNotiButtonByPermission() } - private fun checkIsNotificationAllowed() { - if (isNotificationAllowed) { + private fun changeNotiButtonByPermission() { + if (isNotificationPermissionAllowed) { binding.ivMypageAgree.isVisible = true binding.llMypageAgreePermissionChange.isGone = true binding.tvMypageAgreePermission.isGone = true @@ -454,7 +457,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ } private fun updateNotificationAllowSwitchState(data: User) { - if (isNotificationAllowed) { + if (isNotificationPermissionAllowed) { binding.ivMypageAgree.isVisible = true binding.llMypageAgreePermissionChange.isGone = true binding.tvMypageAgreePermission.isGone = true diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d7580431..f088e999 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -223,8 +223,7 @@ 죄송합니다. 다시 시도해주세요. 정상적으로 신고되었습니다 :) 죄송합니다. 신고접수에 실패하였습니다. - "기기 설정을 변경해야 알림을 받을 수 있어요" - "기기 설정을 변경해야 알림을 받을 수 있어요" + 기기 설정을 변경해야 알림을 받을 수 있어요 LV. 평민 ㆍ