Skip to content

Commit

Permalink
πŸ› Fix: λͺ¨μž„ 생성 ν›„ 친ꡬ μ΄ˆλŒ€ νŒμ—… ν‘œμ‹œ μ•ˆ 되던 였λ₯˜ μˆ˜μ •
Browse files Browse the repository at this point in the history
Related to: #347
  • Loading branch information
nahy-512 committed Feb 16, 2025
1 parent 19ddc29 commit 9088ca9
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class ScheduleRepositoryImpl @Inject constructor(
}
}

override suspend fun addMoimSchedule(moimSchedule: MoimScheduleDetail): Boolean {
return remoteScheduleDataSource.addMoimSchedule(moimSchedule.toDTO()).code == SUCCESS_CODE
override suspend fun addMoimSchedule(moimSchedule: MoimScheduleDetail): Long {
return remoteScheduleDataSource.addMoimSchedule(moimSchedule.toDTO()).result
}

override suspend fun editMoimSchedule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ data class Moim(
)
}
}
}
}

data class MoimCreateInfo(
val moimId: Long = 0L,
val title: String = ""
): Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface ScheduleRepository {

suspend fun addMoimSchedule(
moimSchedule: MoimScheduleDetail
): Boolean
): Long

suspend fun editMoimSchedule(
moimSchedule: MoimScheduleDetail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import android.app.Activity
import android.content.Intent
import android.util.Log
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.mongmong.namo.R
import com.mongmong.namo.databinding.FragmentMoimBinding
import com.mongmong.namo.domain.model.Moim
import com.mongmong.namo.domain.model.MoimCreateInfo
import com.mongmong.namo.presentation.config.BaseFragment
import com.mongmong.namo.presentation.ui.common.ConfirmDialog
import com.mongmong.namo.presentation.ui.common.ConfirmDialog.ConfirmDialogInterface
import com.mongmong.namo.presentation.ui.community.moim.diary.MoimDiaryDetailActivity
import com.mongmong.namo.presentation.ui.community.moim.adapter.MoimRVAdapter
import com.mongmong.namo.presentation.ui.community.moim.diary.MoimDiaryDetailActivity
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 dagger.hilt.android.AndroidEntryPoint

Expand All @@ -30,17 +31,20 @@ class MoimFragment : BaseFragment<FragmentMoimBinding>(R.layout.fragment_moim),
private val getResultText = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
Log.d("MoimFragment", "ActivityResult received")
if (result.resultCode == Activity.RESULT_OK) {
Log.d("MoimFragment", "Result OK")
val isEdited = result.data?.getBooleanExtra(MOIM_EDIT_KEY, false)
if (isEdited == true) viewModel.getMoim() // λ³€κ²½ 사항이 μžˆλ‹€λ©΄ μ—…λ°μ΄νŠΈ

val createdMoimTitle = result.data?.getStringExtra(MOIM_CREATE_KEY)
Log.d("MoimFragment", "isEdited: $isEdited, createdMoimTitle: $createdMoimTitle")
if (createdMoimTitle != null) showCustomDialog(getString(R.string.dialog_moim_friend_invite_title, createdMoimTitle), R.string.dialog_moim_friend_invite_content, R.string.continuously, 0)
} else {
Log.d("MoimFragment", "Result not OK: ${result.resultCode}")
if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult

// 변경사항 확인
val isEdited = result.data?.getBooleanExtra(MOIM_EDIT_KEY, false)
if (isEdited == true) viewModel.getMoim() // λ³€κ²½ 사항이 μžˆλ‹€λ©΄ μ—…λ°μ΄νŠΈ

// 생성 λͺ¨λ“œμΈμ§€ 확인
try {
val createdMoimInfo = result.data?.getSerializableExtra(MOIM_CREATE_KEY) as MoimCreateInfo
Log.d("MoimFragment", "createdMoimInfo: $createdMoimInfo")
viewModel.createdMoimId = createdMoimInfo.moimId
showFriendInviteDialog(createdMoimInfo) // 친ꡬ μ΄ˆλŒ€ λ‹€μ΄μ–Όλ‘œκ·Έ λ„μš°κΈ°
} catch (e: Exception) {
Log.e("MoimFragment", "Error processing MoimCreateInfo: ${e.message}")
}
}

Expand All @@ -55,9 +59,9 @@ class MoimFragment : BaseFragment<FragmentMoimBinding>(R.layout.fragment_moim),
// + λ²„νŠΌ
binding.moimCreateFloatingBtn.setOnClickListener {
// λͺ¨μž„ 일정 생성 ν™”λ©΄μœΌλ‘œ 이동
requireActivity().startActivity(Intent(context, MoimScheduleActivity::class.java)
val intent = Intent(context, MoimScheduleActivity::class.java)
.putExtra("moim", Moim())
)
getResultText.launch(intent)
}
}

Expand All @@ -83,9 +87,14 @@ class MoimFragment : BaseFragment<FragmentMoimBinding>(R.layout.fragment_moim),
})
}

private fun showCustomDialog(title: String, content: Int, buttonText: Int, id: Int) {
Log.d("MoimFragment", "showCustomDialog()")
val dialog = ConfirmDialog(this, title, getString(content), getString(buttonText), id)
private fun showFriendInviteDialog(createdMoimInfo: MoimCreateInfo) {
val dialog = ConfirmDialog(
this,
getString(R.string.dialog_moim_friend_invite_title, createdMoimInfo.title),
getString(R.string.dialog_moim_friend_invite_content),
getString(R.string.continuously),
DIALOG_MOIM_CREATE_ID
)
dialog.isCancelable = false
activity?.let { dialog.show(it.supportFragmentManager, "ConfirmDialog") }
}
Expand All @@ -101,11 +110,15 @@ class MoimFragment : BaseFragment<FragmentMoimBinding>(R.layout.fragment_moim),

override fun onClickYesButton(id: Int) {
// 친ꡬ μ΄ˆλŒ€ ν™”λ©΄μœΌλ‘œ 이동
startActivity(Intent(requireActivity(), FriendInviteActivity::class.java))
val intent = Intent(requireActivity(), FriendInviteActivity::class.java)
.putExtra(MOIM_INVITE_KEY, viewModel.createdMoimId)
getResultText.launch(intent)
}

companion object {
const val MOIM_EDIT_KEY = "moim_edit_key"
const val MOIM_CREATE_KEY = "moim_create_key"

private const val DIALOG_MOIM_CREATE_ID = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class MoimViewModel @Inject constructor(
private val _moimPreviewList = MutableLiveData<List<MoimPreview>>(emptyList())
val moimPreviewList: LiveData<List<MoimPreview>> = _moimPreviewList

var createdMoimId: Long = -1

init {
getMoim()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.mongmong.namo.presentation.ui.community.moim.schedule

import android.app.Activity
import android.content.Intent
import android.text.Html
import android.util.Log
import android.view.View
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
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -164,6 +171,11 @@ 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) // νŽΈμ§‘ μ—¬λΆ€
}
setResult(Activity.RESULT_OK, intent)
finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.kakao.vectormap.label.LabelOptions
import com.mongmong.namo.presentation.ui.MainActivity.Companion.ORIGIN_ACTIVITY_INTENT_KEY
import com.mongmong.namo.R
import com.mongmong.namo.databinding.ActivityMoimScheduleBinding
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
Expand Down Expand Up @@ -224,7 +225,10 @@ class MoimScheduleActivity : BaseActivity<ActivityMoimScheduleBinding>(R.layout.
// νŽΈμ§‘μ—¬λΆ€ 전달 (μ—…λ°μ΄νŠΈ)
val intent = Intent(this, MainActivity::class.java).apply {
putExtra(MOIM_EDIT_KEY, successState.isSuccess) // νŽΈμ§‘ μ—¬λΆ€
if (successState.type == SuccessType.ADD) putExtra(MOIM_CREATE_KEY, viewModel.moimSchedule.value?.title) // 친ꡬ μ΄ˆλŒ€ νŒμ—… ν‘œμ‹œμš©
if (successState.type == SuccessType.ADD) putExtra(MOIM_CREATE_KEY, MoimCreateInfo(
moimId = viewModel.createdMoimId,
title = viewModel.moimSchedule.value?.title.toString()
)) // 친ꡬ μ΄ˆλŒ€ νŒμ—… ν‘œμ‹œμš©
}
setResult(Activity.RESULT_OK, intent)
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class MoimScheduleViewModel @Inject constructor(
var participantIdsToAdd = ArrayList<Long>(arrayListOf()) // μŠ€μΌ€μ€„μ— μΆ”κ°€ν•  μœ μ € ID(userId)
var participantIdsToRemove = ArrayList<Long>(arrayListOf()) // μŠ€μΌ€μ€„μ—μ„œ μ‚­μ œν•  μ°Έκ°€μž ID(participantId)

var createdMoimId: Long = -1

// API 호좜 성곡 μ—¬λΆ€
private val _successState = MutableLiveData<SuccessState>()
var successState: LiveData<SuccessState> = _successState
Expand All @@ -60,10 +62,11 @@ class MoimScheduleViewModel @Inject constructor(
fun postMoimSchedule() {
viewModelScope.launch {
uploadImageToServer(_moimSchedule.value?.coverImg)
createdMoimId = repository.addMoimSchedule(_moimSchedule.value!!)

_successState.value = SuccessState(
SuccessType.ADD,
repository.addMoimSchedule(_moimSchedule.value!!)
createdMoimId >= 0
)
}
}
Expand Down

0 comments on commit 9088ca9

Please sign in to comment.