diff --git a/fileTemplates/Layout Runner (ViewBinding).kt b/fileTemplates/Layout Runner (ViewBinding).kt index 59ec960688..9b0f3af2ce 100644 --- a/fileTemplates/Layout Runner (ViewBinding).kt +++ b/fileTemplates/Layout Runner (ViewBinding).kt @@ -1,6 +1,5 @@ -#set( $LayoutRunnerName = "${NAME}LayoutRunner" ) -#set( $ViewBindingName = "YourViewBinding" ) -#set( $RenderingName = "YourRendering" ) +## Unlike the Workflow Templates, we never generate inner classes for view bindings +## or rendering types. i.e. they are never "optional" package ${PACKAGE_NAME} import com.squareup.workflow1.ui.LayoutRunner @@ -10,20 +9,19 @@ import com.squareup.workflow1.ui.ViewFactory import com.squareup.workflow1.ui.WorkflowUiExperimentalApi #parse("File Header.java") -// TODO Change "YourViewBinding" and "YourRendering" to your actual types. @OptIn(WorkflowUiExperimentalApi::class) -class $LayoutRunnerName( - private val binding: ${ViewBindingName} -) : LayoutRunner<${RenderingName}> { +class $Name( + private val binding: $VIEW_BINDING_TYPE +) : LayoutRunner<$RENDERING_TYPE> { override fun showRendering( - rendering: ${RenderingName}, + rendering: $RENDERING_TYPE, viewEnvironment: ViewEnvironment ) { TODO("Update ViewBinding from rendering") } - companion object : ViewFactory<${RenderingName}> by bind( - ${ViewBindingName}::inflate, ::$LayoutRunnerName + companion object : ViewFactory<$RENDERING_TYPE> by bind( + $VIEW_BINDING_TYPE::inflate, ::$NAME ) } diff --git a/fileTemplates/Stateful Workflow.kt b/fileTemplates/Stateful Workflow.kt index dadddfa188..839431d904 100644 --- a/fileTemplates/Stateful Workflow.kt +++ b/fileTemplates/Stateful Workflow.kt @@ -1,35 +1,87 @@ -#set( $WorkflowName = "${NAME}Workflow" ) -package ${PACKAGE_NAME} +#set ($prefix = $NAME.replace('Workflow', '') ) +## build props string +#if( $PROPS_TYPE_OPTIONAL == '') + #set ($props_type = $prefix + "Props") +#else + #set ($props_type = $PROPS_TYPE_OPTIONAL) +#end +## build state string +#if( $STATE_TYPE_OPTIONAL == '') + #set ($state_type = $prefix + "State") +#else + #set ($state_type = $STATE_TYPE_OPTIONAL) +#end +## build output string +#if( $OUTPUT_TYPE_OPTIONAL == '') + #set ($output_type = $prefix + "Output") +#else + #set ($output_type = $OUTPUT_TYPE_OPTIONAL) +#end +## build rendering string +#if( $RENDERING_TYPE_OPTIONAL == '') + #set ($rendering_type = $prefix + "Rendering") +#else + #set ($rendering_type = $RENDERING_TYPE_OPTIONAL) +#end +package $PACKAGE_NAME import com.squareup.workflow1.Snapshot import com.squareup.workflow1.StatefulWorkflow -import ${PACKAGE_NAME}.${WorkflowName}.Output -import ${PACKAGE_NAME}.${WorkflowName}.Props -import ${PACKAGE_NAME}.${WorkflowName}.Rendering -import ${PACKAGE_NAME}.${WorkflowName}.State + +#if( $PROPS_TYPE_OPTIONAL == '') ## import if we create below +import $PACKAGE_NAME.$NAME.$props_type +#end +#if( $STATE_TYPE_OPTIONAL == '') ## import if we create below +import $PACKAGE_NAME.$NAME.$state_type +#end +#if( $OUTPUT_TYPE_OPTIONAL == '') ## import if we create below +import $PACKAGE_NAME.$NAME.$output_type +#end +#if( $RENDERING_TYPE_OPTIONAL == '') ## import if we create below +import $PACKAGE_NAME.$NAME.$rendering_type +#end #parse("File Header.java") -class ${WorkflowName} : StatefulWorkflow() { +object $NAME : StatefulWorkflow<$props_type, $state_type, $output_type, $rendering_type>() { - data class Props - data class State - data class Output - data class Rendering + #if( $PROPS_TYPE_OPTIONAL == '') ## create if not supplied + data class $props_type( + // TODO add args + ) + #end + + #if( $STATE_TYPE_OPTIONAL == '') ## create if not supplied + data class $state_type( + // TODO add args + ) + #end + + #if( $OUTPUT_TYPE_OPTIONAL == '') ## create if not supplied + data class $output_type( + // TODO add args + ) + #end + + #if( $RENDERING_TYPE_OPTIONAL == '') ## create if not supplied + data class $rendering_type( + // TODO add args + ) + #end override fun initialState( - props: Props, + props: $props_type, snapshot: Snapshot? - ): State = TODO("Initialize state") + ): $state_type = TODO("Initialize state") override fun render( - renderProps: Props, - renderState: State, + props: $props_type, + state: $state_type, context: RenderContext - ): Rendering { + ): $rendering_type { TODO("Render") } - override fun snapshotState(state: State): Snapshot? = Snapshot.write { + override fun snapshotState(state: $state_type): Snapshot? = Snapshot.write { TODO("Save state") } } diff --git a/fileTemplates/Stateless Workflow.kt b/fileTemplates/Stateless Workflow.kt index 2b84dcaf46..8f9427a048 100644 --- a/fileTemplates/Stateless Workflow.kt +++ b/fileTemplates/Stateless Workflow.kt @@ -1,22 +1,61 @@ -#set( $WorkflowName = "${NAME}Workflow" ) -package ${PACKAGE_NAME} +#set ($prefix = $NAME.replace('Workflow', '') ) +## build props string +#if( $PROPS_TYPE_OPTIONAL == '') + #set ($props_type = $prefix + "Props") +#else + #set ($props_type = $PROPS_TYPE_OPTIONAL) +#end +## build output string +#if( $OUTPUT_TYPE_OPTIONAL == '') + #set ($output_type = $prefix + "Output") +#else + #set ($output_type = $OUTPUT_TYPE_OPTIONAL) +#end +## build rendering string +#if( $RENDERING_TYPE_OPTIONAL == '') + #set ($rendering_type = $prefix + "Rendering") +#else + #set ($rendering_type = $RENDERING_TYPE_OPTIONAL) +#end +package $PACKAGE_NAME import com.squareup.workflow1.StatelessWorkflow -import ${PACKAGE_NAME}.${WorkflowName}.Output -import ${PACKAGE_NAME}.${WorkflowName}.Props -import ${PACKAGE_NAME}.${WorkflowName}.Rendering + +#if( $PROPS_TYPE_OPTIONAL == '') ## import if we create below +import $PACKAGE_NAME.$NAME.$props_type +#end +#if( $OUTPUT_TYPE_OPTIONAL == '') ## import if we create below +import $PACKAGE_NAME.$NAME.$output_type +#end +#if( $RENDERING_TYPE_OPTIONAL == '') ## import if we create below +import $PACKAGE_NAME.$NAME.$rendering_type +#end #parse("File Header.java") -class ${WorkflowName} : StatelessWorkflow() { +object $NAME : StatelessWorkflow<$props_type, $output_type, $rendering_type>() { + + #if( $PROPS_TYPE_OPTIONAL == '') ## create if not supplied + data class $props_type( + // TODO add args + ) + #end - data class Props - data class Output - data class Rendering + #if( $OUTPUT_TYPE_OPTIONAL == '') ## create if not supplied + data class $output_type( + // TODO add args + ) + #end + + #if( $RENDERING_TYPE_OPTIONAL == '') ## create if not supplied + data class $rendering_type( + // TODO add args + ) + #end override fun render( - renderProps: Props, + props: $props_type, context: RenderContext - ): Rendering { + ): $rendering_type { TODO("Render") } }