Skip to content

Commit

Permalink
✨ RunningStart 뷰 모델 구현 (현재 러너 카운트 받아오기)
Browse files Browse the repository at this point in the history
Co-authored-by: yonghanJu <[email protected]>
  • Loading branch information
bngsh and yonghanJu committed Nov 17, 2022
1 parent 5b1e687 commit 5811202
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.whyranoid.presentation.runningstart

import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.whyranoid.presentation.R
import com.whyranoid.presentation.base.BaseFragment
import com.whyranoid.presentation.databinding.FragmentRunningStartBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
internal class RunningStartFragment :
BaseFragment<FragmentRunningStartBinding>(R.layout.fragment_running_start) {

private val viewModel by viewModels<RunningStartViewModel>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel

lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.runnerCount.collect { runnerCount ->
binding.tvRunnerCountNumber.text = runnerCount.toString()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.whyranoid.presentation.runningstart

import androidx.lifecycle.ViewModel
import com.whyranoid.domain.usecase.GetRunnerCountUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class RunningStartViewModel @Inject constructor(
getRunnerCountUseCase: GetRunnerCountUseCase
) : ViewModel() {

val runnerCount = getRunnerCountUseCase()
}

0 comments on commit 5811202

Please sign in to comment.