Skip to content

Commit

Permalink
✨ Feat: 보관함 필터 없음 오류 처리
Browse files Browse the repository at this point in the history
Related to: #351
  • Loading branch information
edv-Shin committed Jan 20, 2025
1 parent b72e4be commit 704f2f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mongmong.namo.presentation.ui.home.diary

import android.content.Intent
import android.text.InputType
import android.util.Log
import android.widget.Toast
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.paging.LoadState
Expand All @@ -25,32 +27,44 @@ import java.util.ArrayList
class DiaryArchiveFragment: BaseFragment<FragmentDiaryArchiveBinding>(R.layout.fragment_diary_archive) {
private val viewModel: DiaryViewModel by viewModels()

override fun setup() {
binding.viewModel = viewModel
initClickListener()
}

override fun onResume() {
super.onResume()
getDiaries() // 화면이 다시 보일 때 관찰 시작
}

private fun initClickListener() {
binding.diaryArchiveFilter.setOnClickListener {
DiaryFilterDialog(viewModel.filter.value).apply {
setOnFilterSelectedListener(object : DiaryFilterDialog.OnFilterSelectedListener {
override fun onFilterSelected(filter: FilterType) {
viewModel.setFilter(filter)
if (filter == FilterType.NONE) handleNullFilter()
}
})
}.show(parentFragmentManager, "FilterDialog")
}

binding.diaryArchiveFilterSearchBtn.setOnClickListener {
getDiaries()
if (viewModel.filter.value == FilterType.NONE) {
// 필터가 NONE일 경우 토스트 메시지 표시
Toast.makeText(requireContext(), "필터를 선택해 주세요.", Toast.LENGTH_SHORT).show()
} else {
getDiaries()
}
}
}

override fun setup() {
binding.viewModel = viewModel
initClickListener()
}

override fun onResume() {
super.onResume()
getDiaries() // 화면이 다시 보일 때 관찰 시작
fun handleNullFilter() {
viewModel.clearKeyword()
getDiaries()
}


private fun getDiaries() {
val adapter = DiaryRVAdapter(
detailClickListener = ::onDetailClickListener,
Expand Down Expand Up @@ -122,18 +136,4 @@ class DiaryArchiveFragment: BaseFragment<FragmentDiaryArchiveBinding>(R.layout.f
private fun onParticipantClickListener(participantsCount: Int, participantNames: String) {
DiaryParticipantDialog(participantsCount, participantNames).show(parentFragmentManager, "ParticipantDialog")
}


// yyyy.MM 타입을 밀리초로 변경
private fun convertYearMonthToMillis(
yearMonthStr: String,
pattern: String = "yyyy.MM"
): Long = DateTimeFormat.forPattern(pattern).parseDateTime(yearMonthStr).toDate().time

companion object {
const val IS_MOIM = 1
const val IS_NOT_MOIM = 0
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DiaryViewModel @Inject constructor(

/** 일기 리스트 조회 **/
fun getDiaryPaging(): Flow<PagingData<Diary>> {
Log.d("getDiaryPaging", "filterType: ${_filter.value} keyword: ${keyword.value}")
Log.d("getDiaryPaging", "filterType: ${_filter.value?.request} keyword: ${keyword.value}")
return repository.getDiaryArchivePagingSource(filter.value?.request, keyword.value)
.cachedIn(viewModelScope)
.map { it.insertHeaderLogic() }
Expand Down Expand Up @@ -68,6 +68,8 @@ class DiaryViewModel @Inject constructor(
return SimpleDateFormat("yyyy.MM.dd").format(this * 1000)
}

fun clearKeyword() { keyword.value = "" }

fun setIsListEmpty(isEmpty: Boolean) { _isListEmpty.value = isEmpty }

fun setEmptyView(messageResId: Int, imageResId: Int) {
Expand Down

0 comments on commit 704f2f8

Please sign in to comment.