Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ object Dependencies {

object Compose {
const val activity = "androidx.activity:activity-compose:1.3.1"
const val foundation = "androidx.compose.foundation:foundation:1.0.1"
const val material = "androidx.compose.material:material:1.0.1"
const val tooling = "androidx.compose.ui:ui-tooling:1.0.1"
const val ui = "androidx.compose.ui:ui:1.0.1"
const val foundation = "androidx.compose.foundation:foundation:1.1.0-rc01"
const val material = "androidx.compose.material:material:1.1.0-rc01"
const val tooling = "androidx.compose.ui:ui-tooling:1.1.0-rc01"
const val ui = "androidx.compose.ui:ui:1.1.0-rc01"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is the latest version for these libraries, but there's an rc02 for the compiler plugin with Kotlin 1.6.10 support. We'll use the same versions internally very soon.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you file an issue tracking this, and add a comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

const val constraint_layout = "androidx.constraintlayout:constraintlayout:2.1.0"
Expand Down Expand Up @@ -60,15 +60,15 @@ object Dependencies {
const val timber = "com.jakewharton.timber:timber:4.7.1"

object Moshi {
const val adapters = "com.squareup.moshi:moshi-adapters:1.12.0"
const val codeGen = "com.squareup.moshi:moshi-kotlin-codegen:1.12.0"
const val moshi = "com.squareup.moshi:moshi:1.12.0"
const val adapters = "com.squareup.moshi:moshi-adapters:1.13.0"
const val codeGen = "com.squareup.moshi:moshi-kotlin-codegen:1.13.0"
const val moshi = "com.squareup.moshi:moshi:1.13.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support Kotlin 1.6.10.

}

object Kotlin {
const val binaryCompatibilityValidatorPlugin =
"org.jetbrains.kotlinx:binary-compatibility-validator:0.6.0"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"

object Stdlib {
const val common = "org.jetbrains.kotlin:kotlin-stdlib-common"
Expand All @@ -85,11 +85,11 @@ object Dependencies {
const val test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.1"
}

const val reflect = "org.jetbrains.kotlin:kotlin-reflect:1.5.21"
const val reflect = "org.jetbrains.kotlin:kotlin-reflect:1.6.10"

object Serialization {
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-serialization:1.5.20"
const val json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-serialization:1.6.10"
const val json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2"
}

object Test {
Expand All @@ -101,7 +101,7 @@ object Dependencies {
}
}

const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.4.32" // 1.5.0?
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.5.31"

object Jmh {
const val gradlePlugin = "me.champeau.gradle:jmh-gradle-plugin:0.5.3"
Expand Down
2 changes: 1 addition & 1 deletion samples/compose-samples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.0.1"
kotlinCompilerExtensionVersion = "1.1.0-rc02"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ object InlineRenderingWorkflow : StatefulWorkflow<Unit, Int, Nothing, AndroidVie
AnimatedContent(
targetState = counterValue,
transitionSpec = {
(slideInVertically({ it }) + fadeIn() with
slideOutVertically({ -it }) + fadeOut())
(slideInVertically() + fadeIn() with
slideOutVertically() + fadeOut())
.using(SizeTransform(clip = false))
}
) { content(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.squareup.sample.dungeon

import android.content.Context
import kotlinx.coroutines.delay
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime

/**
Expand All @@ -19,4 +19,4 @@ interface DungeonApplication {
@OptIn(ExperimentalTime::class)
suspend fun Context.delayForFakeLoad() =
(applicationContext as? DungeonApplication)?.delayForFakeLoad()
?: delay(Duration.seconds(1).inWholeMilliseconds)
?: delay(1.seconds.inWholeMilliseconds)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.squareup.sample.timemachine.shakeable.ShakeableTimeMachineWorkflow
import com.squareup.sample.timemachine.shakeable.ShakeableTimeMachineWorkflow.PropsFactory
import com.squareup.workflow1.StatelessWorkflow
import com.squareup.workflow1.renderChild
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource

Expand All @@ -25,6 +26,7 @@ class TimeMachineAppWorkflow(
private val timeMachineWorkflow =
ShakeableTimeMachineWorkflow(TimeMachineWorkflow(appWorkflow, clock), context)

@OptIn(WorkflowUiExperimentalApi::class)
override fun render(
renderProps: BoardPath,
context: RenderContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.renderWorkflowIn
import kotlinx.coroutines.flow.StateFlow
import java.io.File
import kotlin.time.ExperimentalTime

class TimeMachineModel(
private val savedState: SavedStateHandle,
private val workflow: TimeMachineAppWorkflow,
private val traceFilesDir: File
) : ViewModel() {
@OptIn(ExperimentalTime::class)
val renderings: StateFlow<Any> by lazy {
val traceFile = traceFilesDir.resolve("workflow-trace-dungeon.json")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.squareup.workflow1.ui.ViewFactory
import com.squareup.workflow1.ui.WorkflowViewStub
import com.squareup.workflow1.ui.backPressedHandler
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime

/**
Expand Down Expand Up @@ -83,7 +84,7 @@ class ShakeableTimeMachineLayoutRunner(
}

private fun Duration.toProgressInt(): Int = this.inWholeMilliseconds.toInt()
private fun Int.toProgressDuration(): Duration = Duration.milliseconds(this)
private fun Int.toProgressDuration(): Duration = this.milliseconds

private fun Duration.toUiString(): String = toString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.squareup.sample.timemachine.RecorderWorkflow.RecorderProps.RecordValu
import com.squareup.sample.timemachine.RecorderWorkflow.Recording
import com.squareup.workflow1.testing.testRender
import org.junit.Test
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime
import kotlin.time.TestTimeSource

Expand All @@ -17,37 +17,37 @@ class RecorderWorkflowTest {
val clock = TestTimeSource()
val workflow = RecorderWorkflow<String>(clock)
val startTime = clock.markNow()
clock += Duration.milliseconds(42)
clock += 42.milliseconds

val newState = workflow.onPropsChanged(
old = RecordValue("foo"),
new = RecordValue("bar"),
state = Recording(
startTime = startTime,
series = TimeSeries(listOf("foo" to Duration.milliseconds(0)))
series = TimeSeries(listOf("foo" to 0.milliseconds))
)
)

assertThat(newState.series.duration).isEqualTo(Duration.milliseconds(42))
assertThat(newState.series.duration).isEqualTo(42.milliseconds)
assertThat(newState.series.values.toList()).isEqualTo(listOf("foo", "bar"))
}

@Test fun `onPropsChanged doesn't record value when not recording`() {
val clock = TestTimeSource()
val workflow = RecorderWorkflow<String>(clock)
val startTime = clock.markNow()
clock += Duration.milliseconds(42)
clock += 42.milliseconds

val newState = workflow.onPropsChanged(
old = RecordValue("foo"),
new = PlaybackAt(Duration.milliseconds(42)),
new = PlaybackAt(42.milliseconds),
state = Recording(
startTime = startTime,
series = TimeSeries(listOf("foo" to Duration.milliseconds(0)))
series = TimeSeries(listOf("foo" to 0.milliseconds))
)
)

assertThat(newState.series.duration).isEqualTo(Duration.milliseconds(0))
assertThat(newState.series.duration).isEqualTo(0.milliseconds)
assertThat(newState.series.values.toList()).isEqualTo(listOf("foo"))
}

Expand All @@ -61,7 +61,7 @@ class RecorderWorkflowTest {
props = RecordValue("bar"),
initialState = Recording(
startTime = startTime,
series = TimeSeries(listOf("foo" to Duration.milliseconds(42)))
series = TimeSeries(listOf("foo" to 42.milliseconds))
)
)
.render { rendering ->
Expand All @@ -76,13 +76,13 @@ class RecorderWorkflowTest {

workflow
.testRender(
props = PlaybackAt(Duration.milliseconds(10)),
props = PlaybackAt(10.milliseconds),
initialState = Recording(
startTime = startTime,
series = TimeSeries(
listOf(
"foo" to Duration.milliseconds(0),
"bar" to Duration.milliseconds(42)
"foo" to 0.milliseconds,
"bar" to 42.milliseconds
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.squareup.workflow1.stateful
import com.squareup.workflow1.testing.launchForTestingFromStartWith
import org.junit.Test
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime
import kotlin.time.TestTimeSource

Expand All @@ -34,7 +35,7 @@ class TimeMachineWorkflowTest {
// Record some renderings.
awaitNextRendering().let { rendering ->
assertThat(rendering.value.state).isEqualTo("initial")
clock += Duration.seconds(1)
clock += 1.seconds
rendering.value.setState("second")
}
awaitNextRendering().let { rendering ->
Expand All @@ -45,14 +46,14 @@ class TimeMachineWorkflowTest {
sendProps(PlayingBackAt(Unit, Duration.ZERO))
awaitNextRendering().let { rendering ->
assertThat(rendering.value.state).isEqualTo("initial")
assertThat(rendering.totalDuration).isEqualTo(Duration.seconds(1))
assertThat(rendering.totalDuration).isEqualTo(1.seconds)
}

clock += Duration.seconds(1)
sendProps(PlayingBackAt(Unit, Duration.seconds(1)))
clock += 1.seconds
sendProps(PlayingBackAt(Unit, 1.seconds))
awaitNextRendering().let { rendering ->
assertThat(rendering.value.state).isEqualTo("second")
assertThat(rendering.totalDuration).isEqualTo(Duration.seconds(1))
assertThat(rendering.totalDuration).isEqualTo(1.seconds)

rendering.value.setState("third")
}
Expand All @@ -61,7 +62,7 @@ class TimeMachineWorkflowTest {
sendProps(Recording(Unit))
awaitNextRendering().let { rendering ->
assertThat(rendering.value.state).isEqualTo("third")
assertThat(rendering.totalDuration).isEqualTo(Duration.seconds(2))
assertThat(rendering.totalDuration).isEqualTo(2.seconds)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Test
import kotlin.test.assertFailsWith
import kotlin.time.Duration
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime

@OptIn(ExperimentalTime::class)
Expand All @@ -16,60 +18,60 @@ class TimeSeriesTest {
}

@Test fun `duration increases after append`() {
series.append("foo", Duration.milliseconds(42))
series.append("foo", 42.milliseconds)
.let {
assertThat(it.duration).isEqualTo(Duration.milliseconds(42))
assertThat(it.duration).isEqualTo(42.milliseconds)
}
}

@Test fun `duration increases after multiple appends`() {
series.append("foo", Duration.milliseconds(2))
.append("bar", Duration.milliseconds(42))
series.append("foo", 2.milliseconds)
.append("bar", 42.milliseconds)
.let {
assertThat(it.duration).isEqualTo(Duration.milliseconds(42))
assertThat(it.duration).isEqualTo(42.milliseconds)
}
}

@Test fun `throws when appending value from the past`() {
val series1 = series.append("foo", Duration.milliseconds(42))
val series1 = series.append("foo", 42.milliseconds)

assertFailsWith<IllegalArgumentException> {
series1.append("bar", Duration.milliseconds(41))
series1.append("bar", 41.milliseconds)
}
}

@Test fun `allows appending value with last timestamp`() {
series.append("foo", Duration.milliseconds(42))
.append("bar", Duration.milliseconds(42))
series.append("foo", 42.milliseconds)
.append("bar", 42.milliseconds)
.let {
assertThat(it.duration).isEqualTo(Duration.milliseconds(42))
assertThat(it.duration).isEqualTo(42.milliseconds)
}
}

@Test fun `findValueNearest with empty list`() {
assertFailsWith<NoSuchElementException> {
series.findValueNearest(Duration.milliseconds(42))
series.findValueNearest(42.milliseconds)
}
}

@Test fun `findValueNearest with single value`() {
series.append("foo", Duration.milliseconds(42))
series.append("foo", 42.milliseconds)
.let {
assertThat(it.findValueNearest(Duration.milliseconds(0))).isEqualTo("foo")
assertThat(it.findValueNearest(Duration.milliseconds(42))).isEqualTo("foo")
assertThat(it.findValueNearest(Duration.days(100))).isEqualTo("foo")
assertThat(it.findValueNearest(0.milliseconds)).isEqualTo("foo")
assertThat(it.findValueNearest(42.milliseconds)).isEqualTo("foo")
assertThat(it.findValueNearest(100.days)).isEqualTo("foo")
}
}

@Test fun `findValueNearest with multiple values`() {
series.append("foo", Duration.milliseconds(41))
.append("bar", Duration.milliseconds(43))
series.append("foo", 41.milliseconds)
.append("bar", 43.milliseconds)
.let {
assertThat(it.findValueNearest(Duration.milliseconds(0))).isEqualTo("foo")
assertThat(it.findValueNearest(Duration.milliseconds(41))).isEqualTo("foo")
assertThat(it.findValueNearest(Duration.milliseconds(42))).isEqualTo("foo")
assertThat(it.findValueNearest(Duration.milliseconds(43))).isEqualTo("bar")
assertThat(it.findValueNearest(Duration.days(100))).isEqualTo("bar")
assertThat(it.findValueNearest(0.milliseconds)).isEqualTo("foo")
assertThat(it.findValueNearest(41.milliseconds)).isEqualTo("foo")
assertThat(it.findValueNearest(42.milliseconds)).isEqualTo("foo")
assertThat(it.findValueNearest(43.milliseconds)).isEqualTo("bar")
assertThat(it.findValueNearest(100.days)).isEqualTo("bar")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TodoWorkflow : TerminalWorkflow,
override fun snapshotState(state: TodoList): Snapshot? = null

private fun onKeystroke(key: KeyStroke) = action {
@Suppress("NON_EXHAUSTIVE_WHEN")
@Suppress("NON_EXHAUSTIVE_WHEN_STATEMENT")
when (key.keyType) {
ArrowUp -> state = state.moveFocusUp()
ArrowDown -> state = state.moveFocusDown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import com.squareup.sample.gameworkflow.RealTakeTurnsWorkflow
import com.squareup.sample.gameworkflow.RunGameWorkflow
import com.squareup.sample.gameworkflow.TakeTurnsWorkflow
import com.squareup.sample.mainworkflow.TicTacToeWorkflow
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
import timber.log.Timber

/**
* Pretend generated code of a pretend DI framework.
*/
@OptIn(WorkflowUiExperimentalApi::class)
class TicTacToeComponent : ViewModel() {
private val countingIdlingResource = CountingIdlingResource("AuthServiceIdling")
val idlingResource: IdlingResource = countingIdlingResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typealias RunGameScreen = AlertContainerScreen<PanelContainerScreen<Any, Any>>
* We define this otherwise redundant typealias to keep composite workflows
* that build on [RunGameWorkflow] decoupled from it, for ease of testing.
*/
@OptIn(WorkflowUiExperimentalApi::class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this is needed, possible b/c of the @WorkflowUiExperimentalApi mistake above? Same question for the other new appearances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler is more strict. It's needed even with the other change.

> Task :samples:tictactoe:common:compileKotlin FAILED
e: /Users/ralf/Development/projects/square/workflow-kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt: (46, 59): This declaration is experimental and its usage must be marked with '@com.squareup.workflow1.ui.WorkflowUiExperimentalApi' or '@OptIn(com.squareup.workflow1.ui.WorkflowUiExperimentalApi::class)'

typealias RunGameWorkflow = Workflow<Unit, RunGameResult, RunGameScreen>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.squareup.workflow1.ui.modal.AlertContainerScreen
* A [Unit] output event is emitted to signal that the workflow has ended, and the host
* activity should be finished.
*/
@OptIn(WorkflowUiExperimentalApi::class)
class TicTacToeWorkflow(
private val authWorkflow: AuthWorkflow,
private val runGameWorkflow: RunGameWorkflow
Expand Down
Loading