diff --git a/app/src/main/java/com/ftw/hometerview/ui/main/mypage/MyPageFragment.kt b/app/src/main/java/com/ftw/hometerview/ui/main/mypage/MyPageFragment.kt index 50440bc..be659d0 100644 --- a/app/src/main/java/com/ftw/hometerview/ui/main/mypage/MyPageFragment.kt +++ b/app/src/main/java/com/ftw/hometerview/ui/main/mypage/MyPageFragment.kt @@ -26,14 +26,7 @@ import javax.inject.Inject @AndroidEntryPoint class MyPageFragment : Fragment() { - private val updateNicknameLauncher: ActivityResultLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> - if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult - val nickname = - result.data?.getStringExtra(UpdateNicknameActivity.UPDATE_NICKNAME_RESULT_KEY) - if (nickname == null) return@registerForActivityResult - viewModel.showPopup.value = true - } + private lateinit var updateNicknameLauncher: ActivityResultLauncher companion object { fun newInstance() = MyPageFragment() @@ -45,7 +38,6 @@ class MyPageFragment : Fragment() { @Inject lateinit var viewModel: MyPageViewModel - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -64,6 +56,7 @@ class MyPageFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + setLauncher() observeEvent() observeShowBanner() } @@ -136,4 +129,15 @@ class MyPageFragment : Fragment() { private fun updateNicknameActivity(nickname: String) { updateNicknameLauncher.launch(UpdateNicknameActivity.newIntent(requireContext(), nickname)) } + + private fun setLauncher() { + updateNicknameLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult + val nickname = + result.data?.getStringExtra(UpdateNicknameActivity.UPDATE_NICKNAME_RESULT_KEY) + if (nickname == null) return@registerForActivityResult + viewModel.showPopup.value = true + } + } }