Skip to content

Commit

Permalink
[chore] #231 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook123 committed Jan 9, 2024
1 parent 7667f64 commit b8f383e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class MainActivity : BindingActivity<ActivityMainBinding>(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)
)
}
}
Expand Down Expand Up @@ -213,7 +213,5 @@ class MainActivity : BindingActivity<ActivityMainBinding>(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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,7 +58,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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)
Expand Down Expand Up @@ -88,7 +87,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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
Expand Down Expand Up @@ -124,7 +123,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_

private fun initAllowedNotificationButtonClickListener() {
binding.ivMypageSwitch.setOnClickListener {
when (isNotificationAllowed) {
when (isNotificationPermissionAllowed) {
true -> {
val isAllowed = when (binding.ivMypageAgree.currentState) {
R.id.start -> false
Expand All @@ -133,24 +132,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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 -> {
Expand All @@ -165,24 +147,45 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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)
Expand All @@ -191,15 +194,15 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
}

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)
Expand All @@ -221,11 +224,11 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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
Expand Down Expand Up @@ -454,7 +457,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}

private fun updateNotificationAllowSwitchState(data: User) {
if (isNotificationAllowed) {
if (isNotificationPermissionAllowed) {
binding.ivMypageAgree.isVisible = true
binding.llMypageAgreePermissionChange.isGone = true
binding.tvMypageAgreePermission.isGone = true
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@
<string name="snackbar_delete_fail">죄송합니다. 다시 시도해주세요.</string>
<string name="snackbar_report_success">정상적으로 신고되었습니다 :)</string>
<string name="snackbar_report_fail">죄송합니다. 신고접수에 실패하였습니다.</string>
<string name="snackbar_notification_permission_fail">"기기 설정을 변경해야 알림을 받을 수 있어요"</string>
<string name="snackbar_mypage_permission_fail">"기기 설정을 변경해야 알림을 받을 수 있어요"</string>
<string name="snackbar_notification_permission_fail">기기 설정을 변경해야 알림을 받을 수 있어요</string>

<!-- comment -->
<string name="comment_level_1">LV. 평민 ㆍ </string>
Expand Down

0 comments on commit b8f383e

Please sign in to comment.