Skip to content

Commit

Permalink
#6 mypage_fragment/설정 화면 : 2 닉네임 변경
Browse files Browse the repository at this point in the history
 - 완료 팝업 런처 선언 시점 변경
  • Loading branch information
likppi10 committed Aug 22, 2022
1 parent 636ca85 commit 9f9068b
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class MyPageFragment : Fragment() {

private val updateNicknameLauncher: ActivityResultLauncher<Intent> =
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<Intent>

companion object {
fun newInstance() = MyPageFragment()
Expand All @@ -45,7 +38,6 @@ class MyPageFragment : Fragment() {
@Inject
lateinit var viewModel: MyPageViewModel


override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -64,6 +56,7 @@ class MyPageFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setLauncher()
observeEvent()
observeShowBanner()
}
Expand Down Expand Up @@ -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
}
}
}

0 comments on commit 9f9068b

Please sign in to comment.