From aff3c6fdf33266925c922cddd20a65d4ef931a05 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Wed, 11 Oct 2023 20:05:42 +0900 Subject: [PATCH] =?UTF-8?q?[CHORE]=20#25=20:=20NoticeViewModel=20EventFlow?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20handleEvent=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wap/wapp/feature/notice/NoticeFragment.kt | 15 +++++++++++---- .../wap/wapp/feature/notice/NoticeViewModel.kt | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeFragment.kt b/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeFragment.kt index 13bbf52c..e512d25e 100644 --- a/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeFragment.kt +++ b/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeFragment.kt @@ -7,19 +7,26 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import com.android.mediproject.core.ui.base.BaseFragment +import com.wap.wapp.core.base.util.repeatOnStarted import com.wap.wapp.feature.notice.databinding.FragmentNoticeBinding import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class NoticeFragment : - BaseFragment(FragmentNoticeBinding::inflate) { + BaseFragment(FragmentNoticeBinding::inflate) { override val fragmentViewModel: NoticeViewModel by viewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - binding.apply{ - viewModel = fragmentViewModel.apply{ - + binding.apply { + viewModel = fragmentViewModel.apply { + repeatOnStarted { eventFlow.collect { handleEvent(it) } } } } } + + private fun handleEvent(event : NoticeViewModel.NoticeEvent){ + when(event){ + else -> {} + } + } } diff --git a/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeViewModel.kt b/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeViewModel.kt index 60d90ea8..43c36e04 100644 --- a/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeViewModel.kt +++ b/feature/notice/src/main/java/com/wap/wapp/feature/notice/NoticeViewModel.kt @@ -1,9 +1,23 @@ package com.wap.wapp.feature.notice import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class NoticeViewModel @Inject constructor() : ViewModel() { + private val _eventFlow = MutableSharedFlow() + val eventFlow = _eventFlow.asSharedFlow() + + private fun event(event: NoticeEvent) = viewModelScope.launch { + _eventFlow.emit(event) + } + + sealed class NoticeEvent { + + } }