class StopwatchUtil { private val _state = MutableStateFlow(StopwatchState.STOP) val state = _state.asStateFlow() private val _time = MutableStateFlow(0) val time = _time.asStateFlow() private val coroutineScope = CoroutineScope(Dispatchers.IO) private var job: Job? = null val formattedTimeString = time.map { val hour = time.value / 3600 val minute = (time.value % 3600) / 60 val second = time.value % 60 "%02d:%02d:%02d".format(hour, minute, second) }.stateIn(coroutineScope, SharingStarted.Lazily, "00:00:00") fun start() {...} fun pause() {...} ... } StopwatchUtil.kt
Version Android Desktop 1.0.0 1.0.0 1.0.1 Local Storage 1.0.1 Local Storage 1.0.2 Social Login 1.0.2 Social Login 1.0.3 Analytics 1.0.3 Analytics Permission Error!
Version @Composable fun SettingsScreen(modifier: Modifier = Modifier) { var value by remember { mutableStateOf(0f) } var checked by remember { mutableStateOf(false) } Column(...) { ... VersionText(version = getVersionName()) } } @Composable fun SettingsScreen(modifier: Modifier = Modifier) { var value by remember { mutableStateOf(0f) } var checked by remember { mutableStateOf(false) } Column(...) { ... VersionText(version = "1.0.0") } }
ViewModel class AppViewModel(private val stopwatchUtil: StopwatchUtil = StopwatchUtil()) : ViewModel() { { val stopwatchState = stopwatchUtil.state val formattedTimeString = stopwatchUtil.formattedTimeString fun start() = stopwatchUtil.start() fun pause() = stopwatchUtil.pause() fun resume() = stopwatchUtil.resume() fun reset() = stopwatchUtil.reset() fun destroy() = stopwatchUtil.destroy() }
class AppViewModel(private val stopwatchUtil: StopwatchUtil = StopwatchUtil()) : ViewModel() { { val stopwatchState = stopwatchUtil.state val formattedTimeString = stopwatchUtil.formattedTimeString fun start() = stopwatchUtil.start() fun pause() = stopwatchUtil.pause() fun resume() = stopwatchUtil.resume() fun reset() = stopwatchUtil.reset() fun destroy() = stopwatchUtil.destroy() } ViewModel ViewModel ?
ViewModel class AppViewModel(private val stopwatchUtil: StopwatchUtil = StopwatchUtil()) : ViewModel() { val stopwatchState = stopwatchUtil.state val formattedTimeString = stopwatchUtil.formattedTimeString fun start() = stopwatchUtil.start() fun pause() = stopwatchUtil.pause() fun resume() = stopwatchUtil.resume() fun reset() = stopwatchUtil.reset() fun destroy() = stopwatchUtil.destroy() } ViewModel Android Common class AppViewModel(private val stopwatchUtil: StopwatchUtil = StopwatchUtil()) : ViewModel() { { val stopwatchState = stopwatchUtil.state val formattedTimeString = stopwatchUtil.formattedTimeString fun start() = stopwatchUtil.start() fun pause() = stopwatchUtil.pause() fun resume() = stopwatchUtil.resume() fun reset() = stopwatchUtil.reset() fun destroy() = stopwatchUtil.destroy() }
ViewModel class AppViewModel(private val stopwatchUtil: StopwatchUtil = StopwatchUtil()) : BaseViewModel() { val stopwatchState = stopwatchUtil.state val formattedTimeString = stopwatchUtil.formattedTimeString fun start() = stopwatchUtil.start() // 혹은 suspend로 구현 후 viewModelScope 사용 fun pause() = stopwatchUtil.pause() fun resume() = stopwatchUtil.resume() fun reset() = stopwatchUtil.reset() override fun destroy() { super.destroy() stopwatchUtil.destroy() } }