Skip to content

Commit

Permalink
[ADD/#22] 뒤로가기 버튼 분기처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed May 26, 2024
1 parent 1d99498 commit c4d4c5b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kr.genti.presentation.main.create

import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -22,6 +23,7 @@ class PoseFragment() : BaseFragment<FragmentPoseBinding>(R.layout.fragment_pose)

initView()
initNextBtnListener()
initBackPressedListener()
}

private fun initView() {
Expand All @@ -34,4 +36,15 @@ class PoseFragment() : BaseFragment<FragmentPoseBinding>(R.layout.fragment_pose)
viewModel.modCurrentPercent(34)
}
}

private fun initBackPressedListener() {
val onBackPressedCallback =
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
viewModel.modCurrentPercent(-33)
}
}
requireActivity().onBackPressedDispatcher.addCallback(requireActivity(), onBackPressedCallback)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.BulletSpan
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import coil.load
import dagger.hilt.android.AndroidEntryPoint
import kr.genti.core.base.BaseFragment
Expand All @@ -35,6 +37,7 @@ class SelfieFragment() : BaseFragment<FragmentSelfieBinding>(R.layout.fragment_s

initView()
initNextBtnListener()
initBackPressedListener()
initAddImageBtnListener()
setGalleryImage()
setBulletPointList()
Expand All @@ -53,6 +56,20 @@ class SelfieFragment() : BaseFragment<FragmentSelfieBinding>(R.layout.fragment_s
}
}

private fun initBackPressedListener() {
val onBackPressedCallback =
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
viewModel.modCurrentPercent(-34)
}
}
requireActivity().onBackPressedDispatcher.addCallback(
requireActivity(),
onBackPressedCallback,
)
}

private fun initAddImageBtnListener() {
with(binding) {
btnSelfieAdd.setOnSingleClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.View
import dagger.hilt.android.AndroidEntryPoint
import kr.genti.core.base.BaseFragment
import kr.genti.core.extension.initOnBackPressedListener
import kr.genti.presentation.R
import kr.genti.presentation.databinding.FragmentFeedBinding

Expand All @@ -14,5 +15,7 @@ class FeedFragment() : BaseFragment<FragmentFeedBinding>(R.layout.fragment_feed)
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

initOnBackPressedListener(binding.root)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.View
import dagger.hilt.android.AndroidEntryPoint
import kr.genti.core.base.BaseFragment
import kr.genti.core.extension.initOnBackPressedListener
import kr.genti.presentation.R
import kr.genti.presentation.databinding.FragmentProfileBinding

Expand All @@ -14,5 +15,7 @@ class ProfileFragment() : BaseFragment<FragmentProfileBinding>(R.layout.fragment
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

initOnBackPressedListener(binding.root)
}
}

0 comments on commit c4d4c5b

Please sign in to comment.