Skip to content

Commit

Permalink
[CHORE] #25 : NoticeViewModel EventFlow 추가 및 handleEvent 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Oct 11, 2023
1 parent 3fcf971 commit aff3c6f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,NoticeViewModel>(FragmentNoticeBinding::inflate) {
BaseFragment<FragmentNoticeBinding, NoticeViewModel>(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 -> {}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<NoticeEvent>()
val eventFlow = _eventFlow.asSharedFlow()

private fun event(event: NoticeEvent) = viewModelScope.launch {
_eventFlow.emit(event)
}

sealed class NoticeEvent {

}
}

0 comments on commit aff3c6f

Please sign in to comment.