Skip to content

Commit

Permalink
Rename Kotlin's ViewBinding to ViewFactory.
Browse files Browse the repository at this point in the history
Closes #988.
  • Loading branch information
zach-klippenstein committed Mar 6, 2020
1 parent 41c0ae4 commit 15ab30a
Show file tree
Hide file tree
Showing 53 changed files with 157 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.squareup.sample.container

import com.squareup.workflow.ui.BuilderBinding
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewRegistry
import com.squareup.workflow.ui.backPressedHandler
import com.squareup.workflow.ui.bindShowRendering
Expand All @@ -40,7 +40,7 @@ data class BackButtonScreen<W : Any>(
val override: Boolean = false,
val onBackPressed: (() -> Unit)? = null
) {
companion object Binding : ViewBinding<BackButtonScreen<*>>
companion object Binding : ViewFactory<BackButtonScreen<*>>
by BuilderBinding(
type = BackButtonScreen::class,
viewConstructor = { initialRendering, initialHints, contextForNewView, container ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.squareup.sample.container.masterdetail.MasterDetailConfig.Detail
import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master
import com.squareup.sample.container.masterdetail.MasterDetailConfig.Single
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.WorkflowViewStub
import com.squareup.workflow.ui.backstack.BackStackScreen
Expand Down Expand Up @@ -95,7 +95,7 @@ class MasterDetailContainer(view: View) : LayoutRunner<MasterDetailScreen> {
stub.update(combined, viewEnvironment + (MasterDetailConfig to Single))
}

companion object : ViewBinding<MasterDetailScreen> by LayoutRunner.Binding(
companion object : ViewFactory<MasterDetailScreen> by LayoutRunner.Binding(
type = MasterDetailScreen::class,
layoutId = R.layout.master_detail,
runnerConstructor = ::MasterDetailContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import com.squareup.sample.container.R
import com.squareup.workflow.ui.BuilderBinding
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.bindShowRendering
import com.squareup.workflow.ui.modal.ModalViewContainer

Expand Down Expand Up @@ -71,7 +71,7 @@ class PanelContainer @JvmOverloads constructor(
}
}

companion object : ViewBinding<PanelContainerScreen<*, *>> by BuilderBinding(
companion object : ViewFactory<PanelContainerScreen<*, *>> by BuilderBinding(
type = PanelContainerScreen::class,
viewConstructor = { initialRendering, initialHints, contextForNewView, _ ->
PanelContainer(contextForNewView).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.view.View
import android.view.ViewGroup
import com.squareup.sample.container.R
import com.squareup.workflow.ui.BuilderBinding
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.WorkflowViewStub
import com.squareup.workflow.ui.bindShowRendering

Expand Down Expand Up @@ -104,7 +104,7 @@ class ScrimContainer @JvmOverloads constructor(
}
}

companion object : ViewBinding<ScrimContainerScreen<*>> by BuilderBinding(
companion object : ViewFactory<ScrimContainerScreen<*>> by BuilderBinding(
type = ScrimContainerScreen::class,
viewConstructor = { initialRendering, initialViewEnvironment, contextForNewView, _ ->
val stub = WorkflowViewStub(contextForNewView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master
import com.squareup.sample.container.poetryapp.R
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment

class PoemListLayoutRunner(view: View) : LayoutRunner<PoemListRendering> {
Expand Down Expand Up @@ -94,7 +94,7 @@ class PoemListLayoutRunner(view: View) : LayoutRunner<PoemListRendering> {
}
}

companion object : ViewBinding<PoemListRendering>
companion object : ViewFactory<PoemListRendering>
by bind(
R.layout.list,
::PoemListLayoutRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.squareup.sample.hellobackbutton.R.id
import com.squareup.sample.hellobackbutton.R.layout
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.backPressedHandler

Expand All @@ -38,7 +38,7 @@ class HelloBackButtonLayoutRunner(view: View) : LayoutRunner<Rendering> {
messageView.backPressedHandler = rendering.onBackPressed
}

companion object : ViewBinding<Rendering> by bind(
companion object : ViewFactory<Rendering> by bind(
layout.hello_back_button_layout, ::HelloBackButtonLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.squareup.sample.container.masterdetail.MasterDetailConfig
import com.squareup.sample.container.masterdetail.MasterDetailConfig.Detail
import com.squareup.sample.container.poetry.R
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.backPressedHandler
import com.squareup.workflow.ui.backstack.BackStackConfig
Expand Down Expand Up @@ -106,7 +106,7 @@ class StanzaLayoutRunner(private val view: View) : LayoutRunner<StanzaRendering>
setText(spans, SPANNABLE)
}

companion object : ViewBinding<StanzaRendering> by LayoutRunner.bind(
companion object : ViewFactory<StanzaRendering> by LayoutRunner.bind(
R.layout.stanza_layout,
::StanzaLayoutRunner
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master
import com.squareup.sample.container.poetry.R
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.backPressedHandler
import com.squareup.workflow.ui.backstack.BackStackConfig
Expand Down Expand Up @@ -100,7 +100,7 @@ class StanzaListLayoutRunner(view: View) : LayoutRunner<StanzaListRendering> {
}
}

companion object : ViewBinding<StanzaListRendering>
companion object : ViewFactory<StanzaListRendering>
by bind(
R.layout.list,
::StanzaListLayoutRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import android.view.View
import androidx.core.content.ContextCompat
import com.squareup.sample.dungeon.board.Board
import com.squareup.workflow.ui.BuilderBinding
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.bindShowRendering
import kotlin.math.abs
import kotlin.math.min
Expand Down Expand Up @@ -97,7 +97,7 @@ class BoardView(context: Context) : View(context) {
}
}

companion object : ViewBinding<Board> by BuilderBinding(
companion object : ViewFactory<Board> by BuilderBinding(
type = Board::class,
viewConstructor = { initialRendering, initialHints, contextForNewView, _ ->
BoardView(contextForNewView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.squareup.sample.dungeon.DungeonAppWorkflow.DisplayBoardsListScreen
import com.squareup.sample.dungeon.board.Board
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.WorkflowViewStub

Expand Down Expand Up @@ -101,7 +101,7 @@ class BoardsListLayoutRunner(rootView: View) : LayoutRunner<DisplayBoardsListScr
)
}

companion object : ViewBinding<DisplayBoardsListScreen> by bind(
companion object : ViewFactory<DisplayBoardsListScreen> by bind(
R.layout.boards_list_layout, ::BoardsListLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.squareup.sample.dungeon.Direction.UP
import com.squareup.sample.dungeon.GameWorkflow.GameRendering
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.WorkflowViewStub

Expand Down Expand Up @@ -77,7 +77,7 @@ class GameLayoutRunner(view: View) : LayoutRunner<GameRendering> {
}
}

companion object : ViewBinding<GameRendering> by bind(
companion object : ViewFactory<GameRendering> by bind(
R.layout.game_layout, ::GameLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import android.widget.TextView
import androidx.annotation.StringRes
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment

/**
* Factory function for [ViewBinding]s that show a full-screen loading indicator with some text
* Factory function for [ViewFactory]s that show a full-screen loading indicator with some text
* underneath.
*
* The binding is parameterized on two things: the type of the rendering that this binding is
Expand All @@ -33,7 +33,7 @@ import com.squareup.workflow.ui.ViewEnvironment
@Suppress("FunctionName")
inline fun <reified RenderingT : Any> LoadingBinding(
@StringRes loadingLabelRes: Int
): ViewBinding<RenderingT> =
): ViewFactory<RenderingT> =
bind(R.layout.loading_layout) { view -> LoadingLayoutRunner<RenderingT>(loadingLabelRes, view) }

@PublishedApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.transition.TransitionManager
import com.squareup.sample.timemachine.shakeable.internal.GlassFrameLayout
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.WorkflowViewStub
import com.squareup.workflow.ui.backPressedHandler
Expand Down Expand Up @@ -102,7 +102,7 @@ class ShakeableTimeMachineLayoutRunner(

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

companion object : ViewBinding<ShakeableTimeMachineRendering> by bind(
companion object : ViewFactory<ShakeableTimeMachineRendering> by bind(
R.layout.shakeable_time_machine_layout, ::ShakeableTimeMachineLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.view.View
import android.widget.TextView
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment

class HelloFragmentLayoutRunner(view: View) : LayoutRunner<HelloWorkflow.Rendering> {
Expand All @@ -35,7 +35,7 @@ class HelloFragmentLayoutRunner(view: View) : LayoutRunner<HelloWorkflow.Renderi
messageView.setOnClickListener { rendering.onClick() }
}

companion object : ViewBinding<HelloWorkflow.Rendering> by bind(
companion object : ViewFactory<HelloWorkflow.Rendering> by bind(
R.layout.hello_goodbye_layout, ::HelloFragmentLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import android.view.View
import android.widget.TextView
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment

class HelloLayoutRunner(view: View) : LayoutRunner<HelloWorkflow.Rendering> {
Expand All @@ -33,7 +33,7 @@ class HelloLayoutRunner(view: View) : LayoutRunner<HelloWorkflow.Rendering> {
messageView.setOnClickListener { rendering.onClick() }
}

companion object : ViewBinding<HelloWorkflow.Rendering> by bind(
companion object : ViewFactory<HelloWorkflow.Rendering> by bind(
R.layout.hello_goodbye_layout, ::HelloLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.squareup.sample.recyclerview

import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.modal.ModalContainer
import com.squareup.workflow.ui.modal.ModalViewContainer

/**
* A simple [ModalContainer] [ViewBinding] that knows how to render [AppWorkflow.Rendering]s.
* A simple [ModalContainer] [ViewFactory] that knows how to render [AppWorkflow.Rendering]s.
*/
object AddRowContainer : ViewBinding<AppWorkflow.Rendering> by ModalViewContainer.binding()
object AddRowContainer : ViewFactory<AppWorkflow.Rendering> by ModalViewContainer.binding()
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.squareup.sample.recyclerview.editablelistworkflow.ListDiffMode.Asynch
import com.squareup.sample.recyclerview.editablelistworkflow.ListDiffMode.Synchronous
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.WorkflowViewStub

Expand Down Expand Up @@ -52,7 +52,7 @@ class BaseScreenLayoutRunner(view: View) : LayoutRunner<BaseScreen> {
addRowButton.setOnClickListener { rendering.onAddRowTapped() }
}

companion object : ViewBinding<BaseScreen> by bind(
companion object : ViewFactory<BaseScreen> by bind(
R.layout.base_screen_layout, ::BaseScreenLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.Button
import android.widget.LinearLayout
import com.squareup.sample.recyclerview.AppWorkflow.ChooseRowTypeScreen
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.bindShowRendering
import kotlin.reflect.KClass

/**
* Shows a list of buttons for selecting a new row type to add.
*/
object ChooseRowTypeViewBinding : ViewBinding<ChooseRowTypeScreen> {
object ChooseRowTypeViewFactory : ViewFactory<ChooseRowTypeScreen> {
override val type: KClass<ChooseRowTypeScreen> get() = ChooseRowTypeScreen::class

override fun buildView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import timber.log.Timber.DebugTree
private val viewRegistry = ViewRegistry(
AddRowContainer,
BaseScreenLayoutRunner,
ChooseRowTypeViewBinding,
ChooseRowTypeViewFactory,
EditableListLayoutRunner
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.squareup.sample.recyclerview.R.id
import com.squareup.sample.recyclerview.editablelistworkflow.EditableListWorkflow.Rendering
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment

class EditableListLayoutRunner(view: View) : LayoutRunner<Rendering> {
Expand All @@ -46,7 +46,7 @@ class EditableListLayoutRunner(view: View) : LayoutRunner<Rendering> {
adapter.updateRendering(rendering, viewEnvironment[ListDiffMode])
}

companion object : ViewBinding<Rendering> by bind(
companion object : ViewFactory<Rendering> by bind(
R.layout.recyclerview_layout, ::EditableListLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package com.squareup.sample.authworkflow

import com.squareup.workflow.ui.ViewRegistry

val AuthViewBindings = ViewRegistry(
val AuthViewFactories = ViewRegistry(
AuthorizingLayoutRunner,
LoginLayoutRunner,
SecondFactorLayoutRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.widget.TextView
import com.squareup.sample.tictactoe.R
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment

internal class AuthorizingLayoutRunner(view: View) : LayoutRunner<AuthorizingScreen> {
Expand All @@ -33,7 +33,7 @@ internal class AuthorizingLayoutRunner(view: View) : LayoutRunner<AuthorizingScr
messageView.text = rendering.message
}

companion object : ViewBinding<AuthorizingScreen> by bind(
companion object : ViewFactory<AuthorizingScreen> by bind(
R.layout.authorizing_layout, ::AuthorizingLayoutRunner
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.widget.TextView
import com.squareup.sample.tictactoe.R
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
import com.squareup.workflow.ui.ViewBinding
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.backPressedHandler

Expand All @@ -45,7 +45,7 @@ internal class LoginLayoutRunner(val view: View) : LayoutRunner<LoginScreen> {
view.backPressedHandler = { rendering.onCancel() }
}

companion object : ViewBinding<LoginScreen> by bind(
companion object : ViewFactory<LoginScreen> by bind(
R.layout.login_layout, ::LoginLayoutRunner
)
}
Loading

0 comments on commit 15ab30a

Please sign in to comment.