From 3d3a143dbadf46f57ea93f3f1766b998944bbb82 Mon Sep 17 00:00:00 2001 From: Ray Ryan Date: Thu, 8 May 2025 16:20:22 -0700 Subject: [PATCH] Fix tutorial fileTemplates Our templates were out of date, and our `install.sh` script doesn't work any more. Replaced with an IDE-produced zip file that the IDE is willing to import. Replaces `Layout Runner (ViewBinding)` with `Android Screen (ViewBinding)`: ```kotlin package ${PACKAGE_NAME} import com.squareup.workflow1.ui.AndroidScreen import com.squareup.workflow1.ui.ScreenViewFactory import com.squareup.workflow1.ui.ScreenViewRunner import com.squareup.workflow1.ui.ViewEnvironment import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @OptIn(WorkflowUiExperimentalApi::class) data class $Name( // TODO: add properties needed to update $VIEW_BINDING_TYPE ) : AndroidScreen<$Name> { override val viewFactory = ScreenViewFactory.fromViewBinding($VIEW_BINDING_TYPE::inflate, ::${Name}Runner) } @OptIn(WorkflowUiExperimentalApi::class) private class ${Name}Runner( private val viewBinding: $VIEW_BINDING_TYPE ) : ScreenViewRunner<$Name> { override fun showRendering( rendering: $Name, environment: ViewEnvironment ) { TODO("Update viewBinding from rendering") } } ``` --- README-templates.md | 8 +++ fileTemplates/Stateful Workflow.kt | 87 ----------------------------- fileTemplates/Stateless Workflow.kt | 61 -------------------- install-templates.sh | 27 --------- 4 files changed, 8 insertions(+), 175 deletions(-) create mode 100644 README-templates.md delete mode 100644 fileTemplates/Stateful Workflow.kt delete mode 100644 fileTemplates/Stateless Workflow.kt delete mode 100755 install-templates.sh diff --git a/README-templates.md b/README-templates.md new file mode 100644 index 000000000..79f0de221 --- /dev/null +++ b/README-templates.md @@ -0,0 +1,8 @@ +# File Templates + +`workflow-file-templates.zip` can be imported into Android Studio / IntelliJ IDEA to add a few Workflow-specific file templates, via _File > Manage IDE Settings > Import Settings…_. + +To update the templates: + +* edit them in the IDE (_Settings > Editor > File and Code Templates_) +* export them (_File > Manage IDE Settings > Import Settings…_), taking care to clear every checkbox except that for File Templates. diff --git a/fileTemplates/Stateful Workflow.kt b/fileTemplates/Stateful Workflow.kt deleted file mode 100644 index 6f7d54c9f..000000000 --- a/fileTemplates/Stateful Workflow.kt +++ /dev/null @@ -1,87 +0,0 @@ -#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 - -#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") -object $NAME : StatefulWorkflow<$props_type, $state_type, $output_type, $rendering_type>() { - - #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_type, - snapshot: Snapshot? - ): $state_type = TODO("Initialize state") - - override fun render( - renderProps: $props_type, - renderState: $state_type, - context: RenderContext - ): $rendering_type { - TODO("Render") - } - - override fun snapshotState(state: $state_type): Snapshot? = Snapshot.write { - TODO("Save state") - } -} diff --git a/fileTemplates/Stateless Workflow.kt b/fileTemplates/Stateless Workflow.kt deleted file mode 100644 index e103179e0..000000000 --- a/fileTemplates/Stateless Workflow.kt +++ /dev/null @@ -1,61 +0,0 @@ -#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 - -#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") -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 - - #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_type, - context: RenderContext - ): $rendering_type { - TODO("Render") - } -} diff --git a/install-templates.sh b/install-templates.sh deleted file mode 100755 index 3c012c9aa..000000000 --- a/install-templates.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# Installs Workflow file templates for IntelliJ and Android Studio. - - -OS="$(uname -s)" -echo "Installing Workflow file templates on $OS system..." -ideaConfigPath="" -if [[ "$OS" == Linux ]]; then - ideaConfigPath="$HOME/.config" -elif [[ "$OS" == Darwin ]]; then - ideaConfigPath="$HOME/Library/Application Support" -fi -TEMPLATES="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/fileTemplates" -for i in "$ideaConfigPath"/Google/AndroidStudio* \ - "$ideaConfigPath"/JetBrains/IdeaIC* \ - "$ideaConfigPath"/JetBrains/IntelliJIdea* -do - echo $i - if [[ -d "$i" ]]; then - mkdir -p "$i/fileTemplates" - cp -frv "$TEMPLATES"/* "$i/fileTemplates" - fi -done - -echo "Done." -echo "" -echo "Restart IntelliJ and/or AndroidStudio."