This file contains hidden or 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
| fun startStopButton(state: State, context: FormulaContext<State>): ButtonRenderModel { | |
| return if (state.isRunning) { | |
| ButtonRenderModel( | |
| text = "Stop", | |
| onSelected = context.callback { | |
| transition(state.copy(isRunning = false)) | |
| } | |
| ) | |
| } else { | |
| ButtonRenderModel( |
This file contains hidden or 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
| class StopwatchFormula : Formula<Unit, StopwatchFormula.State, StopwatchRenderModel> { | |
| data class State( | |
| val isRunning: Boolean | |
| ) | |
| override fun initialState(input: Unit): State = State( | |
| isRunning = false | |
| ) | |
This file contains hidden or 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
| class StopwatchFormula : Formula<Unit, StopwatchFormula.State, StopwatchRenderModel> { | |
| // We will use this a little later. | |
| object State | |
| override fun initialState(input: Unit): State = State | |
| override fun evaluate( | |
| input: Unit, | |
| state: State, | |
| context: FormulaContext<State> |
This file contains hidden or 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
| data class State( | |
| val isRunning: Boolean | |
| ) |
This file contains hidden or 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
| Observable | |
| .interval(1, TimeUnit.MILLISECONDS) | |
| .observeOn(AndroidSchedulers.mainThread()) |
This file contains hidden or 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
| data class State( | |
| val timePassedInMillis: Long, | |
| val isRunning: Boolean | |
| ) |
This file contains hidden or 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
| fun formatTimePassed(timePassedInMillis: Long): String { | |
| // TODO: actually format it | |
| return "${timePassedInMillis}ms" | |
| } |
This file contains hidden or 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
| class StopwatchActivity : FragmentActivity() { | |
| private val disposables = CompositeDisposable() | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.stopwatch_activity) | |
| val renderView = StopwatchRenderView(findViewById(R.id.activity_content)) | |
| val renderModels: Observable<StopwatchRenderModel> = |
NewerOlder