-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ RunningStart 뷰 모델 구현 (현재 러너 카운트 받아오기)
Co-authored-by: yonghanJu <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
presentation/src/main/java/com/whyranoid/presentation/runningstart/RunningStartFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
presentation/src/main/java/com/whyranoid/presentation/runningstart/RunningStartViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |