Skip to content

Commit

Permalink
Merge pull request #87 from Cat-JiYoung/develop
Browse files Browse the repository at this point in the history
[FIX] 대대적인 로직 수정
  • Loading branch information
amourxyoung authored Jul 22, 2023
2 parents e9a6660 + 63b09cd commit 583f125
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DetailRetroActivity :

binding.tvDetailRetroTitle.text = intent.getStringExtra("Title")

val projectId = intent.getIntExtra("projectId", 1)
val projectId = intent.getIntExtra("homeProjectId", 1)
viewModel.getDetailRetro(projectId)

viewModel.detailRetroList.observe(this) { contents ->
Expand Down Expand Up @@ -121,6 +121,7 @@ class DetailRetroActivity :

binding.ibDetailRetroClose.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
intent.putExtra("homeProjectId", 0)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
import androidx.fragment.app.setFragmentResultListener
import com.google.android.material.tabs.TabLayout
import com.puzzling.puzzlingaos.R
import com.puzzling.puzzlingaos.base.BaseFragment
Expand Down Expand Up @@ -118,16 +117,10 @@ class HomeFragment :

private fun handleSelectedProject() {
viewModel.isProjectNameSelected.observe(viewLifecycleOwner) {
Log.d("home", "isProjectSelected: ${viewModel.isProjectNameSelected.value}")
Log.d("home", "isProjectSelected: $it")
val projectName = viewModel.selectedProjectName.value
binding.tvHomeProjectName.text = projectName.toString()
Log.d("home", "tvHomeProjectName: ${binding.tvHomeProjectName.text}")

setFragmentResultListener("projectIdKey") { key, bundle ->
val projectId = bundle.getString("projectId")
Log.d("home", "Received projectId: $projectId")
// Now you can use the projectId value as needed
}
}
// setFragmentResultListener("projectIdKey") { key, bundle ->
// val projectId = bundle.getInt("projectId").toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.puzzling.puzzlingaos.domain.entity.Project
import com.puzzling.puzzlingaos.domain.repository.MyBoardRepository
import com.puzzling.puzzlingaos.domain.repository.ProjectRepository
import com.puzzling.puzzlingaos.util.UserInfo
import com.puzzling.puzzlingaos.util.UserInfo.GET_PROJECT_ID
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand Down Expand Up @@ -48,11 +47,11 @@ class HomeViewModel @Inject constructor(
val isProjectNameSelected: LiveData<Boolean>
get() = _isProjectNameSelected

private val _selectedProjectName = MutableLiveData("찌릿")
private val _selectedProjectName = MutableLiveData("우유")
val selectedProjectName: LiveData<String>
get() = _selectedProjectName

private val _selectedProjectId = MutableLiveData<Int>(GET_PROJECT_ID)
private val _selectedProjectId = MutableLiveData<Int>()
val selectedProjectId: LiveData<Int>
get() = _selectedProjectId

Expand All @@ -67,8 +66,6 @@ class HomeViewModel @Inject constructor(
private val _retroWeek = MutableLiveData<ResponseProjectRetroWeekDto.ProjectCycle?>()
val retroWeek: LiveData<ResponseProjectRetroWeekDto.ProjectCycle?> get() = _retroWeek

// val firstProjectId = MutableLiveData<Int>()

init {
_reviewCycleList.value = listOf("", "", "")
_reviewCycleText.value = _reviewCycleList.value?.joinToString(separator = ",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.viewModels
import androidx.fragment.app.activityViewModels
import com.puzzling.puzzlingaos.R
import com.puzzling.puzzlingaos.base.BaseFragment
import com.puzzling.puzzlingaos.databinding.FragmentPersonalDashboardBinding
import com.puzzling.puzzlingaos.presentation.detailRetrospect.DetailRetroActivity
import com.puzzling.puzzlingaos.presentation.home.HomeViewModel
import com.puzzling.puzzlingaos.presentation.home.personal.puzzleboard.OnePuzzleBoardActivity
import com.puzzling.puzzlingaos.presentation.home.personal.puzzleboard.ThreePuzzleBoardActivity
import com.puzzling.puzzlingaos.presentation.home.personal.puzzleboard.TwoPuzzleBoardActivity
Expand All @@ -20,8 +21,9 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class PersonalDashboardFragment :
BaseFragment<FragmentPersonalDashboardBinding>(R.layout.fragment_personal_dashboard) {
private val viewModel by viewModels<PersonalDashboardViewModel>()
private val teamViewModel by viewModels<TeamDashBoardViewModel>()
private val viewModel by activityViewModels<PersonalDashboardViewModel>()
private val teamViewModel by activityViewModels<TeamDashBoardViewModel>()
private val homeViewModel by activityViewModels<HomeViewModel>()

private var _actionPlanAdapter: ActionPlanListAdapter? = null
private val actionPlanAdapter
Expand All @@ -35,8 +37,33 @@ class PersonalDashboardFragment :
clickMyPuzzleBoardBtn()
clickPuzzlePiece()
setBottomBtnBackgroundColor()
observeProjectId()
homeViewModel.selectedProjectId.observe(this) {
viewModel.getMyPuzzleData(it)
viewModel.getMyPuzzleBoard(it)
}
setVisibleAdapter()
}

private fun observeProjectId() {
viewModel.firstProjectId.observe(this) {
Log.d("personal", "firstProjectId:: $it")
viewModel.getMyPuzzleData(it)
viewModel.getMyPuzzleBoard(it)
viewModel.getActionPlan(it)
viewModel.getPreviousTemplate(it)
}
}

// private fun intentToWriteActivity() {
// val intent = Intent(requireActivity(), WriteRetrospectiveActivity::class.java)
// viewModel.firstProjectId.observe(this) {
// Log.d("개인", "$it")
// intent.putExtra("homeProjectId", it)
//// startActivity(intent)
// }
// }

private fun putExtraProjectId() {
activity?.let {
val intent = Intent(context, TeamRetroActivity::class.java)
Expand All @@ -56,11 +83,15 @@ class PersonalDashboardFragment :

private fun clickBottomBtn() {
binding.clPersonalBottomBtn.setOnClickListener {
teamViewModel.myNickname.observe(this) {
val intent = Intent(context, WriteRetrospectiveActivity::class.java)
intent.putExtra("Title", teamViewModel.myNickname.value)
viewModel.firstProjectId.observe(this) {
val intent = Intent(activity, WriteRetrospectiveActivity::class.java)
intent.putExtra("homeProjectId", it)
Log.d("homeProjectId", "$it")
startActivity(intent)
}
// val intent = Intent(context, WriteRetrospectiveActivity::class.java)
// intent.putExtra("Title", teamViewModel.myNickname.value)
// startActivity(intent)
}
}

Expand Down Expand Up @@ -124,21 +155,33 @@ class PersonalDashboardFragment :
}

private fun setBottomBtnBackgroundColor() {
viewModel.isSuccess.observe(this) {
if (viewModel.isReviewDay.value == true) {
Log.d("personal", "회고 진행해야함")
binding.tvPersonalBottomTitle.text = "회고 작성하기"
viewModel.isReviewDay.observe(this) {
if (it == true) { // 회고하는날
if (viewModel.hasTodayReview.value == true) {
binding.tvPersonalBottomTitle.text = "회고 작성하기"
binding.clPersonalBottomBtn.setBackgroundResource(R.drawable.rect_gray400_fill_16)
binding.clPersonalBottomBtn.isClickable = false
binding.clPersonalBottomBtn.isClickable = true
} else {
binding.tvPersonalBottomTitle.text = "회고 작성하기"
binding.clPersonalBottomBtn.setBackgroundResource(R.drawable.rect_blue400_fill_radius_16)
binding.clPersonalBottomBtn.isClickable = true
}
} else {
binding.tvPersonalBottomTitle.text = "회고 작성일이 아니에요"
binding.clPersonalBottomBtn.setBackgroundResource(R.drawable.rect_gray400_fill_16)
binding.clPersonalBottomBtn.isClickable = false
binding.clPersonalBottomBtn.isClickable = true
}
}
}

private fun setVisibleAdapter() {
viewModel.actionPlanList.observe(this) {
if (it != null && it.isEmpty()) {
binding.clActionplanNone.visibility = View.VISIBLE
binding.rcvPersonalView.visibility = View.INVISIBLE
} else {
binding.rcvPersonalView.visibility = View.VISIBLE
binding.clActionplanNone.visibility = View.INVISIBLE
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class PersonalDashboardViewModel @Inject constructor(
val previousReviewType: LiveData<Int>
get() = _previousReviewType

private val _isSuccess = MutableLiveData(false)
val isSuccess: LiveData<Boolean> get() = _isSuccess
private val _isSuccess = MutableLiveData<Boolean?>(null)
val isSuccess: LiveData<Boolean?> get() = _isSuccess

val firstProjectId = MutableLiveData<Int>()

Expand All @@ -66,18 +66,17 @@ class PersonalDashboardViewModel @Inject constructor(

)

init {
getMyPuzzleData()
getMyPuzzleData()
getActionPlan()
getMyPuzzleBoard()
getPreviousTemplate()
}
// init {
// getMyPuzzleData()
// getMyPuzzleData()
// getActionPlan()
// getMyPuzzleBoard()
// getPreviousTemplate()
// }

private fun getMyPuzzleData() = viewModelScope.launch {
repository.getUserPuzzle(UserInfo.MEMBER_ID, firstProjectId.value!!, UserInfo.TODAY)
fun getMyPuzzleData(projectId: Int) = viewModelScope.launch {
repository.getUserPuzzle(UserInfo.MEMBER_ID, projectId, UserInfo.TODAY)
.onSuccess { response ->
_isSuccess.value = true
Log.d("personal", "getMyPuzzleData() success:: $response")
_myNickname.value = response.data.myPuzzle.nickname
_myPuzzleCount.value = response.data.myPuzzle.puzzleCount
Expand All @@ -94,8 +93,8 @@ class PersonalDashboardViewModel @Inject constructor(
}
}

private fun getMyPuzzleBoard() = viewModelScope.launch {
repository.getUserPuzzleBoard(UserInfo.MEMBER_ID, firstProjectId.value!!, UserInfo.TODAY)
fun getMyPuzzleBoard(projectId: Int) = viewModelScope.launch {
repository.getUserPuzzleBoard(UserInfo.MEMBER_ID, projectId, UserInfo.TODAY)
.onSuccess { response ->
_myPuzzleBoardList.value = response
Log.d("personal", "getMyPuzzleBoard() success:: $response")
Expand Down Expand Up @@ -123,28 +122,32 @@ class PersonalDashboardViewModel @Inject constructor(
return substring(startIndex)
}

private fun getActionPlan() = viewModelScope.launch {
repository.getActionPlan(UserInfo.MEMBER_ID, firstProjectId.value!!).onSuccess { response ->
_isSuccess.value = true
Log.d("personal", "getActionPlan() success:: $response")
val truncatedList = truncateActionPlanList(response)
_actionPlanList.value = truncatedList
Log.d("actionPlan", "actionPlanList.value:: ${_actionPlanList.value}")
_actionPlanList.value?.forEach { actionPlan ->
actionPlan.actionPlanDate = actionPlan.actionPlanDate?.let {
convertActionPlanDate(
it,
)
fun getActionPlan(projectId: Int) = viewModelScope.launch {
repository.getActionPlan(UserInfo.MEMBER_ID, projectId)
.onSuccess { response ->
_isSuccess.value = true
Log.d("personal", "getActionPlan() success:: $response")
val truncatedList = truncateActionPlanList(response)
_actionPlanList.value = truncatedList
Log.d("actionPlan", "actionPlanList.value:: ${_actionPlanList.value}")
_actionPlanList.value?.forEach { actionPlan ->
actionPlan.actionPlanDate = actionPlan.actionPlanDate?.let {
convertActionPlanDate(
it,
)
}
}
}.onFailure {
Log.d("personal", "getActionPlan() Fail:: $it")
}
}.onFailure {
Log.d("personal", "getActionPlan() Fail:: $it")
}
}

private fun getPreviousTemplate() {
fun getPreviousTemplate(projectId: Int) {
viewModelScope.launch {
writeReviewRepository.getPreviousTemplate(UserInfo.MEMBER_ID, firstProjectId.value!!)
writeReviewRepository.getPreviousTemplate(
UserInfo.MEMBER_ID,
projectId,
)
.onSuccess { response ->
_previousReviewType.value = response.data.previousTemplateId
Log.d("write", "getPreviousTemplate() success:: ${_previousReviewType.value}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ class TeamDashBoardViewModel @Inject constructor(

val firstProjectId = MutableLiveData<Int>()


init {
getTeamPuzzleData()
getTeamPuzzleBoard()
getTeamRanking()
}

private fun getTeamPuzzleData() = viewModelScope.launch {
repository.getTeamPuzzle(firstProjectId.value!!, UserInfo.TODAY)
// init {
// getTeamPuzzleData()
// getTeamPuzzleBoard()
// getTeamRanking()
// }

fun getTeamPuzzleData(projectId: Int) = viewModelScope.launch {
repository.getTeamPuzzle(projectId, UserInfo.TODAY)
.onSuccess { response ->
_isSuccess.value = true
Log.d("team", "getTeamPuzzleData() success:: $response")
Expand All @@ -89,8 +88,8 @@ class TeamDashBoardViewModel @Inject constructor(
}
}

private fun getTeamPuzzleBoard() = viewModelScope.launch {
repository.getTeamPuzzleBoard(firstProjectId.value!!, UserInfo.TODAY)
fun getTeamPuzzleBoard(projectId: Int) = viewModelScope.launch {
repository.getTeamPuzzleBoard(projectId, UserInfo.TODAY)
.onSuccess { response ->
_teamPuzzleBoardList.value = response
Log.d("team", "getTeamPuzzleBoard() success:: $response")
Expand All @@ -111,8 +110,8 @@ class TeamDashBoardViewModel @Inject constructor(
}
}

private fun getTeamRanking() = viewModelScope.launch {
repository.getTeamRanking(firstProjectId.value!!).onSuccess { response ->
fun getTeamRanking(projectId: Int) = viewModelScope.launch {
repository.getTeamRanking(projectId).onSuccess { response ->
_teamRankingList.value = response
val teamRanks: List<TeamRanking> =
_teamRankingList.value!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.viewModels
import androidx.fragment.app.activityViewModels
import com.puzzling.puzzlingaos.R
import com.puzzling.puzzlingaos.base.BaseFragment
import com.puzzling.puzzlingaos.databinding.FragmentTeamDashboardBinding
Expand All @@ -18,14 +18,29 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class TeamDashboardFragment :
BaseFragment<FragmentTeamDashboardBinding>(R.layout.fragment_team_dashboard) {
private val viewModel by viewModels<TeamDashBoardViewModel>()
private val homeViewModel by viewModels<HomeViewModel>()
private val viewModel by activityViewModels<TeamDashBoardViewModel>()
private val homeViewModel by activityViewModels<HomeViewModel>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
clickTeamPuzzleBoardBtn()
clickPuzzlePiece()
observeProjectId()
homeViewModel.selectedProjectId.observe(this) {
viewModel.getTeamPuzzleData(it)
viewModel.getTeamPuzzleBoard(it)
viewModel.getTeamRanking(it)
}
}

private fun observeProjectId() {
viewModel.firstProjectId.observe(this) {
Log.d("team", "firstProjectId:: $it")
viewModel.getTeamPuzzleData(it)
viewModel.getTeamPuzzleBoard(it)
viewModel.getTeamRanking(it)
}
}

private fun clickPuzzlePiece() {
Expand All @@ -50,7 +65,7 @@ class TeamDashboardFragment :
layout.setOnClickListener {
activity?.let {
val intent = Intent(context, TeamRetroActivity::class.java)
intent.putExtra("Team", viewModel.myNickname.value)
intent.putExtra("Title", viewModel.myNickname.value)
startActivity(intent)
}
}
Expand Down
Loading

0 comments on commit 583f125

Please sign in to comment.