Skip to content

Commit

Permalink
๐Ÿ› Fix: ๋ชจ์ž„ ์ผ์ • ํŽธ์ง‘ ๋ชจ๋“œ ์ฐธ์„์ž ์„ ํƒ ํ›„ ์—…๋ฐ์ดํŠธ ์ด์Šˆ ํ™•์ธ
Browse files Browse the repository at this point in the history
- registerForActivityResult ์„ค์ •

Related to: #347
  • Loading branch information
nahy-512 committed Feb 16, 2025
1 parent 869a54f commit 04162a8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.mongmong.namo.presentation.ui.community.moim.diary.MoimDiaryDetailAct
import com.mongmong.namo.presentation.ui.community.moim.schedule.FriendInviteActivity
import com.mongmong.namo.presentation.ui.community.moim.schedule.FriendInviteActivity.Companion.MOIM_INVITE_KEY
import com.mongmong.namo.presentation.ui.community.moim.schedule.MoimScheduleActivity
import com.mongmong.namo.presentation.ui.community.moim.schedule.MoimScheduleActivity.Companion.MOIM_ID_KEY
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -88,7 +89,7 @@ class MoimFragment : BaseFragment<FragmentMoimBinding>(R.layout.fragment_moim),
override fun onItemClick(position: Int) {
// ๋ชจ์ž„ ์ผ์ • ํŽธ์ง‘ ํ™”๋ฉด์œผ๋กœ ์ด๋™
val intent = Intent(context, MoimScheduleActivity::class.java)
.putExtra("moimScheduleId", viewModel.moimPreviewList.value!![position].moimId)
.putExtra(MOIM_ID_KEY, viewModel.moimPreviewList.value!![position].moimId)
getMoimResultData.launch(intent)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.mongmong.namo.R
import com.mongmong.namo.databinding.ActivityFriendInviteBinding
import com.mongmong.namo.domain.model.MoimCreateInfo
import com.mongmong.namo.presentation.config.BaseActivity
import com.mongmong.namo.presentation.enums.SuccessType
import com.mongmong.namo.presentation.ui.MainActivity
import com.mongmong.namo.presentation.ui.common.ConfirmDialog
import com.mongmong.namo.presentation.ui.community.moim.MoimFragment.Companion.MOIM_CREATE_KEY
import com.mongmong.namo.presentation.ui.community.moim.MoimFragment.Companion.MOIM_EDIT_KEY
import com.mongmong.namo.presentation.ui.community.moim.schedule.adapter.FriendInvitePreparatoryRVAdapter
import com.mongmong.namo.presentation.ui.community.moim.schedule.adapter.FriendInviteRVAdapter
Expand Down Expand Up @@ -171,11 +168,17 @@ class FriendInviteActivity : BaseActivity<ActivityFriendInviteBinding>(R.layout.
// API ํ˜ธ์ถœ ์„ฑ๊ณต ์—ฌ๋ถ€
viewModel.isSuccess.observe(this) { isSuccess ->
if (isSuccess) {
// ํŽธ์ง‘์—ฌ๋ถ€ ์ „๋‹ฌ (์—…๋ฐ์ดํŠธ)
val intent = Intent(this, MainActivity::class.java).apply {
putExtra(MOIM_EDIT_KEY, isSuccess) // ํŽธ์ง‘ ์—ฌ๋ถ€
// ์ƒ์„ฑ ๋ฐ ํŽธ์ง‘ ๋ชจ๋“œ์—์„œ์˜ ํ™”๋ฉด ์ง„์ž… ๊ฒฝ๋กœ ๊ตฌ๋ถ„
val mainIntent = Intent(this, MainActivity::class.java).apply {
putExtra(MOIM_EDIT_KEY, isSuccess)
}
val scheduleIntent = Intent(this, MoimScheduleActivity::class.java).apply {
putExtra(MOIM_EDIT_KEY, isSuccess)
}
val intents = arrayOf(mainIntent, scheduleIntent)
intents.forEach {
setResult(Activity.RESULT_OK, it)
}
setResult(Activity.RESULT_OK, intent)
finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.

private val viewModel : MoimScheduleViewModel by viewModels()

private lateinit var getInviteResultData: ActivityResultLauncher<Intent>

override fun setup() {
binding.viewModel = viewModel

Expand All @@ -73,6 +75,7 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.
setResultLocation()
initClickListeners()
initObserve()
initInviteResultData()
}

override fun onResume() {
Expand All @@ -91,7 +94,8 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.
}

private fun initViews() {
viewModel.setMoimSchedule(intent.getLongExtra("moimScheduleId", 0L))
viewModel.moimScheduleId = intent.getLongExtra(MOIM_ID_KEY, 0L)
viewModel.setMoimSchedule()

val slideAnimation = AnimationUtils.loadAnimation(this, R.anim.slide_in_up)
binding.moimScheduleContainerLayout.startAnimation(slideAnimation)
Expand All @@ -116,13 +120,12 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.

// ์นœ๊ตฌ ์ดˆ๋Œ€ ๋ฒ„ํŠผ ํด๋ฆญ
binding.moimScheduleAddParticipantTv.setOnClickListener {
// ์นœ๊ตฌ ์ถ”๊ฐ€ํ•˜๊ธฐ ํ™”๋ฉด์œผ๋กœ ์ด๋™
startActivity(
Intent(this, FriendInviteActivity::class.java).apply {
putExtra(MOIM_INVITE_KEY, viewModel.moimSchedule.value!!.moimId)
if (viewModel.getParticipantUserIdList().isNotEmpty()) putExtra(MOIM_PARTICIPANT_ID_KEY, viewModel.getParticipantUserIdList().toLongArray())
}
)
// ์นœ๊ตฌ ์ดˆ๋Œ€ ํ™”๋ฉด์œผ๋กœ ์ด๋™
val intent = Intent(this, FriendInviteActivity::class.java).apply {
putExtra(MOIM_INVITE_KEY, viewModel.moimSchedule.value!!.moimId)
if (viewModel.getParticipantUserIdList().isNotEmpty()) putExtra(MOIM_PARTICIPANT_ID_KEY, viewModel.getParticipantUserIdList().toLongArray())
}
getInviteResultData.launch(intent)
}

// ๊ฒŒ์ŠคํŠธ ์ดˆ๋Œ€ ๋ฒ„ํŠผ ํด๋ฆญ (ํŽธ์ง‘ ๋ชจ๋“œ)
Expand Down Expand Up @@ -186,6 +189,18 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.
}
}

private fun initInviteResultData() {
getInviteResultData = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult

// ๋ณ€๊ฒฝ์‚ฌํ•ญ ํ™•์ธ
val isEdited = result.data?.getBooleanExtra(MOIM_EDIT_KEY, false)
if (isEdited == true) viewModel.getMoimScheduleDetailInfo() // ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์žˆ๋‹ค๋ฉด ์—…๋ฐ์ดํŠธ
}
}

/** ๋ชจ์ž„ ์ผ์ • ์ถ”๊ฐ€ */
private fun insertSchedule() {
viewModel.postMoimSchedule()
Expand Down Expand Up @@ -472,10 +487,16 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.
override fun onClickYesButton(id: Int) {
when (id) {
0 -> deleteSchedule() // ์ผ์ • ์‚ญ์ œ ์ง„ํ–‰
1 -> startActivity(
Intent(this, FriendInviteActivity::class.java)
.putExtra(MOIM_INVITE_KEY, viewModel.moimSchedule.value!!.moimId)
) // ์นœ๊ตฌ ์ดˆ๋Œ€ ํ™”๋ฉด์œผ๋กœ ์ด๋™
1 -> { // ์นœ๊ตฌ ์ดˆ๋Œ€ ํ™”๋ฉด์œผ๋กœ ์ด๋™
val intent = Intent(this, FriendInviteActivity::class.java).apply {
putExtra(MOIM_INVITE_KEY, viewModel.moimSchedule.value!!.moimId)
}
getInviteResultData.launch(intent)
}
}
}

companion object {
const val MOIM_ID_KEY = "moimId"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MoimScheduleViewModel @Inject constructor(
private val repository: ScheduleRepository,
private val uploadImageToS3UseCase: UploadImageToS3UseCase
) : ViewModel() {
var moimScheduleId: Long = -1

private val _moimSchedule = MutableLiveData<MoimScheduleDetail>()
val moimSchedule: LiveData<MoimScheduleDetail> = _moimSchedule

Expand All @@ -50,7 +52,7 @@ class MoimScheduleViewModel @Inject constructor(
var successState: LiveData<SuccessState> = _successState

/** ๋ชจ์ž„ ์ผ์ • ์ƒ์„ธ ์กฐํšŒ */
private fun getMoimSchedule(moimScheduleId: Long) {
fun getMoimScheduleDetailInfo() {
viewModelScope.launch {
_moimSchedule.value = repository.getMoimScheduleDetail(moimScheduleId)
getGuestInvitationLink()
Expand Down Expand Up @@ -140,12 +142,12 @@ class MoimScheduleViewModel @Inject constructor(
}

// ๋ชจ์ž„ ์ผ์ • ๊ธฐ๋ณธ ์ •๋ณด ์„ธํŒ…
fun setMoimSchedule(moimScheduleId: Long) {
fun setMoimSchedule() {
if (moimScheduleId == 0L) { // ๋ชจ์ž„ ์ผ์ • ์ƒ์„ฑ
_moimSchedule.value = MoimScheduleDetail()
return
}
getMoimSchedule(moimScheduleId) // ๋ชจ์ž„ ์ผ์ • ํŽธ์ง‘
getMoimScheduleDetailInfo() // ๋ชจ์ž„ ์ผ์ • ํŽธ์ง‘
}

fun updateImage(uri: Uri?) {
Expand Down

0 comments on commit 04162a8

Please sign in to comment.