Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix/351] 보관함 필터 없음 오류 처리 #352

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions app/src/main/res/layout/fragment_diary_archive.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
android:layout_marginEnd="32dp"
android:layout_marginTop="8dp"
android:text="@={viewModel.keyword}"
android:inputType="text"
android:maxLength="8"
android:maxLines="1"
app:layout_constraintEnd_toStartOf="@+id/diary_archive_filter_search_btn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/diary_archive_filter" />
Expand Down