boostcampwm-2022 / android06-mogle

🔮 모글(mogle) - 지도에 쓰는 다이어리, 기록, 일기
32 stars 4 forks source link

글로브 안에 모먼트 추가하기 UI 구현 #89

Closed Choe-Ji-Hwan closed 1 year ago

Choe-Ji-Hwan commented 1 year ago

🚀 Issue #67

👨‍🔧 개요

📝 작업 내용

📢 특이 사항

아래와 같이 스냅샷을 찍어서 list의 변화가 있다는 것을 주는 것이 어색하긴합니다만, 기능적으로는 잘 돌아가서 일단 먼저 이렇게 구현한 다음 리팩토링 할 예정입니다. [snapshot](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#snapshot())() Returns a new ItemSnapshotList representing the currently presented items 라는 의미로, 현재 보여지는 items 들 만 가져와서, 아마도 메모리 누수는 그렇게 많이 일어나지 않을거라 생각합니다. 해석을 잘못했다면 알려주세요 😸

    private fun selectMoment(moment: MomentModel) {
        val data = momentPagingAdapter.snapshot().items.toMutableList()
        val changeData = data.map { snapShotMoment ->
            if (moment.id == snapShotMoment.id) {
                snapShotMoment.copy(isSelected = snapShotMoment.isSelected.not())
            } else {
                snapShotMoment
            }
        }.toList()
        lifecycleScope.launch {
            viewModel.moments.collectLatest {
                momentPagingAdapter.submitData(PagingData.from(changeData))
            }
        }
    }