Skip to content

Commit

Permalink
Merge pull request #131 from meongCare/feature/supplement
Browse files Browse the repository at this point in the history
fix: 영양제 관련 에러 해결
  • Loading branch information
nueijeel authored Jan 24, 2024
2 parents 7d81ba8 + 43254e7 commit 399fe7d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class SupplementInfoFragment : Fragment() {
Glide.with(this@SupplementInfoFragment)
.load(it.imageUrl)
.into(imageViewSupplementInfo)
textViewSupplementInfoName.text = it.name
}

textViewSupplementInfoBrandName.text = it.brand
textViewSupplementInfoName.text = it.name
textViewSupplementInfoCycleCount.text = it.intakeCycle.toString()
textViewSupplementInfoTimeListCount.text = "${it.intakeInfos.size}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,37 @@ class SupplementRoutineEditFragment : Fragment() {

supplementViewModel.run {
getSupplementDogs()
supplementIdListAllCheck.observe(viewLifecycleOwner) {
Log.d("루틴 변경", it.toString())
Log.d("루틴 변경2", supplementIdList.value.toString())
supplementIdList.observe(viewLifecycleOwner) {
Log.d("영양제 리스트", supplementIdList.value.toString())
fragmentSupplementRoutineEditBinding.run {
imageViewSupplementRoutineEditDeleteAllCheck.isSelected = it.isNotEmpty() && it.size == supplementDogList.value!!.size
}
}
supplementDogList.observe(viewLifecycleOwner) {
Log.d("영양제 리스트 확인", it.toString())
fragmentSupplementRoutineEditBinding.run {
val temp =
supplementViewModel.supplementDogList.value!!.map { it.supplementsId }.toMutableList()
Log.d("영양제 리스트 확인2", temp.toString())
imageViewSupplementRoutineEditDeleteAllCheck.run {
setOnClickListener {
it.isSelected = !it.isSelected
Log.d("영양제 리스트1", it.isSelected.toString())
if (it.isSelected) {
supplementViewModel.supplementIdList.value = temp
Log.d("영양제 리스트2", supplementViewModel.supplementIdList.value.toString())
} else {
supplementViewModel.supplementIdList.value = mutableListOf()
Log.d("영양제 리스트3", supplementViewModel.supplementIdList.value.toString())
}
}
}
recyclerViewSupplementRoutineEdit.run {
adapter = SupplementRoutineEditRecyclerViewAdapter()
layoutManager = LinearLayoutManager(context)
}
}
}
supplementDogList.observe(viewLifecycleOwner) {
fragmentSupplementRoutineEditBinding.recyclerViewSupplementRoutineEdit.run {
adapter = SupplementRoutineEditRecyclerViewAdapter()
layoutManager = LinearLayoutManager(context)
}
}
supplementDeleteCode.observe(viewLifecycleOwner) {
if (it == 200) {
showSuccessSnackbar()
Expand All @@ -73,16 +88,21 @@ class SupplementRoutineEditFragment : Fragment() {
fragmentSupplementRoutineEditBinding.run {
toolbarSupplementRoutineEdit.setNavigationOnClickListener { navController.popBackStack() }

imageViewSupplementRoutineEditDeleteAllCheck.setOnClickListener { view ->
val isAllSelected = !view.isSelected
view.isSelected = isAllSelected
val temp =
supplementViewModel.supplementDogList.value!!.map { it.supplementsId }
.toMutableList()
supplementViewModel.setAllItemsChecked(
imageViewSupplementRoutineEditDeleteAllCheck.isSelected,
temp,
)
val temp =
supplementViewModel.supplementDogList.value!!.map { it.supplementsId }.toMutableList()
Log.d("영양제 리스트 확인2", temp.toString())
imageViewSupplementRoutineEditDeleteAllCheck.run {
setOnClickListener {
it.isSelected = !it.isSelected
Log.d("영양제 리스트1", it.isSelected.toString())
if (it.isSelected) {
supplementViewModel.supplementIdList.value = temp
Log.d("영양제 리스트2", supplementViewModel.supplementIdList.value.toString())
} else {
supplementViewModel.supplementIdList.value = mutableListOf()
Log.d("영양제 리스트3", supplementViewModel.supplementIdList.value.toString())
}
}
}

buttonSupplementRoutineEditCancel.setOnClickListener {
Expand Down Expand Up @@ -170,17 +190,20 @@ class SupplementRoutineEditFragment : Fragment() {
val supplementsId =
supplementViewModel.supplementDogList.value!![position].supplementsId

holder.itemSupplementRoutineEditCheckImg.isSelected =
supplementViewModel.supplementIdList.value!!.contains(supplementsId)

holder.itemSupplementRoutineEditCheckImg.setOnClickListener {
supplementViewModel.updateSupplementIds(mutableListOf(supplementsId))
supplementViewModel.supplementIdList.observe(viewLifecycleOwner) {
holder.itemSupplementRoutineEditCheckImg.isSelected =
!holder.itemSupplementRoutineEditCheckImg.isSelected
supplementViewModel.supplementIdList.value!!.contains(supplementsId)
}

if (supplementViewModel.supplementIdListAllCheck.value!!) {
fragmentSupplementRoutineEditBinding.imageViewSupplementRoutineEditDeleteAllCheck.isSelected =
false
holder.itemSupplementRoutineEditCheckImg.setOnClickListener {
it.isSelected = !it.isSelected
val temp2 = supplementViewModel.supplementIdList.value!!
if (temp2.contains(supplementsId)) {
temp2.remove(supplementsId)
supplementViewModel.supplementIdList.value = temp2
} else {
temp2.add(supplementsId)
supplementViewModel.supplementIdList.value = temp2
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class SupplementViewModel
var supplementSize = MutableLiveData<Double>()
var supplementPercentage = MutableLiveData<Double>()
var supplementIdList = MutableLiveData<MutableList<Int>>()
var supplementIdListAllCheck = MutableLiveData<Boolean>()
var supplementDogList = MutableLiveData<MutableList<SupplementDog>>()
var supplementDetail = MutableLiveData<DetailSupplement>()
var supplementAddImg = MutableLiveData<Uri?>()
Expand All @@ -66,7 +65,6 @@ class SupplementViewModel
supplementCheckCount.value = 0.0
supplementSize.value = 0.0
supplementPercentage.value = 0.0
supplementIdListAllCheck.value = false
supplementAddImg.value = null
getDogName()
}
Expand Down Expand Up @@ -291,32 +289,6 @@ class SupplementViewModel
}
}

fun updateSupplementIds(supplementsRoutineIdList: MutableList<Int>) {
viewModelScope.launch {
if (supplementsRoutineIdList.isNotEmpty()) {
if (supplementIdList.value!!.containsAll(supplementsRoutineIdList)) {
supplementIdList.value!!.removeAll(supplementsRoutineIdList)
} else {
supplementIdList.value!!.addAll(supplementsRoutineIdList)
}
}
}
}

fun setAllItemsChecked(
isChecked: Boolean,
supplementsRoutineIdList: MutableList<Int>,
) {
if (isChecked) {
supplementIdList.value!!.clear()
supplementIdList.value = supplementsRoutineIdList
} else {
supplementIdList.value!!.clear()
}

supplementIdListAllCheck.value = isChecked
}

fun getDogName() {
viewModelScope.launch {
dogName.value = DogPreferences(GlobalApplication.applicationContext()).dogName.first()
Expand Down

0 comments on commit 399fe7d

Please sign in to comment.