diff --git a/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryArchiveFragment.kt b/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryArchiveFragment.kt index a272eda8..9e0db647 100644 --- a/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryArchiveFragment.kt +++ b/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryArchiveFragment.kt @@ -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 @@ -25,32 +27,44 @@ import java.util.ArrayList class DiaryArchiveFragment: BaseFragment(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, @@ -122,18 +136,4 @@ class DiaryArchiveFragment: BaseFragment(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 - } } - - diff --git a/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryViewModel.kt b/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryViewModel.kt index 8fae6819..3c87b3d8 100644 --- a/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryViewModel.kt +++ b/app/src/main/java/com/mongmong/namo/presentation/ui/home/diary/DiaryViewModel.kt @@ -40,7 +40,7 @@ class DiaryViewModel @Inject constructor( /** 일기 리스트 조회 **/ fun getDiaryPaging(): Flow> { - 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() } @@ -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) { diff --git a/app/src/main/res/layout/fragment_diary_archive.xml b/app/src/main/res/layout/fragment_diary_archive.xml index b3209ed1..ff642f07 100644 --- a/app/src/main/res/layout/fragment_diary_archive.xml +++ b/app/src/main/res/layout/fragment_diary_archive.xml @@ -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" />