Skip to content

Commit cf3efb0

Browse files
committed
wip: moved binding methods to view factory
1 parent 2ad84bb commit cf3efb0

File tree

29 files changed

+314
-294
lines changed

29 files changed

+314
-294
lines changed

samples/containers/android/src/main/java/com/squareup/sample/container/overviewdetail/OverviewDetailContainer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ class OverviewDetailContainer(view: View) : ScreenViewUpdater<OverviewDetailScre
8484
stub.show(combined, viewEnvironment + (OverviewDetailConfig to Single))
8585
}
8686

87-
companion object : ScreenViewFactory<OverviewDetailScreen> by ScreenViewUpdater.bind(
88-
layoutId = R.layout.overview_detail,
89-
constructor = ::OverviewDetailContainer
87+
companion object : ScreenViewFactory<OverviewDetailScreen> by ScreenViewFactory.ofLayout(R.layout.overview_detail,
88+
{ it: View -> OverviewDetailContainer(it) }
9089
) {
9190
private const val OverviewBackStackKey = "overview"
9291
}

samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemListScreen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Overvie
1212
import com.squareup.sample.container.poetryapp.R
1313
import com.squareup.sample.poetry.model.Poem
1414
import com.squareup.workflow1.ui.AndroidScreen
15+
import com.squareup.workflow1.ui.ScreenViewFactory
1516
import com.squareup.workflow1.ui.ScreenViewUpdater
1617
import com.squareup.workflow1.ui.ViewEnvironment
1718
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
@@ -22,10 +23,9 @@ data class PoemListScreen(
2223
val onPoemSelected: (Int) -> Unit,
2324
val selection: Int = -1
2425
) : AndroidScreen<PoemListScreen> {
25-
override val viewFactory = ScreenViewUpdater.bind(
26-
R.layout.list,
27-
::PoemListLayoutUpdater
28-
)
26+
override val viewFactory = ScreenViewFactory.ofLayout(
27+
R.layout.list
28+
) { it: View -> PoemListLayoutUpdater(it) }
2929
}
3030

3131
@OptIn(WorkflowUiExperimentalApi::class)

samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonLayoutUpdater.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ data class HelloBackButtonScreen(
1515
val onClick: () -> Unit,
1616
val onBackPressed: (() -> Unit)?
1717
) : AndroidScreen<HelloBackButtonScreen> {
18-
override val viewFactory: ScreenViewFactory<HelloBackButtonScreen> = ScreenViewUpdater.bind(
19-
R.layout.hello_back_button_layout, ::HelloBackButtonLayoutUpdater
20-
)
18+
override val viewFactory: ScreenViewFactory<HelloBackButtonScreen> = ScreenViewFactory.ofLayout(
19+
R.layout.hello_back_button_layout
20+
) { it: View -> HelloBackButtonLayoutUpdater(it) }
2121
}
2222

2323
@OptIn(WorkflowUiExperimentalApi::class)

samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaListScreen.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ data class StanzaListScreen(
2828
val onExit: () -> Unit,
2929
val selection: Int = -1
3030
) : AndroidScreen<StanzaListScreen> {
31-
override val viewFactory: ScreenViewFactory<StanzaListScreen> = ScreenViewUpdater.bind(
32-
R.layout.list,
33-
::StanzaListLayoutUpdater
34-
)
31+
override val viewFactory: ScreenViewFactory<StanzaListScreen> = ScreenViewFactory.ofLayout(
32+
R.layout.list
33+
) { it: View -> StanzaListLayoutUpdater(it) }
3534
}
3635

3736
@OptIn(WorkflowUiExperimentalApi::class)

samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaScreen.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ data class StanzaScreen(
3232
) : AndroidScreen<StanzaScreen>, Compatible {
3333
override val compatibilityKey = "$title: $stanzaNumber"
3434

35-
override val viewFactory: ScreenViewFactory<StanzaScreen> = ScreenViewUpdater.bind(
36-
R.layout.stanza_layout,
37-
::StanzaLayoutUpdater
38-
)
35+
override val viewFactory: ScreenViewFactory<StanzaScreen> = ScreenViewFactory.ofLayout(
36+
R.layout.stanza_layout
37+
) { it: View -> StanzaLayoutUpdater(it) }
3938
}
4039

4140
@OptIn(WorkflowUiExperimentalApi::class)
@@ -114,8 +113,7 @@ private class StanzaLayoutUpdater(private val view: View) : ScreenViewUpdater<St
114113
setText(spans, SPANNABLE)
115114
}
116115

117-
companion object : ScreenViewFactory<StanzaScreen> by ScreenViewUpdater.bind(
118-
R.layout.stanza_layout,
119-
::StanzaLayoutUpdater
116+
companion object : ScreenViewFactory<StanzaScreen> by ScreenViewFactory.ofLayout(R.layout.stanza_layout,
117+
{ it: View -> StanzaLayoutUpdater(it) }
120118
)
121119
}

samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/BoardsListLayoutUpdater.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.squareup.sample.dungeon.DungeonAppWorkflow.DisplayBoardsListScreen
1212
import com.squareup.sample.dungeon.board.Board
1313
import com.squareup.workflow1.ui.ScreenViewFactory
1414
import com.squareup.workflow1.ui.ScreenViewUpdater
15-
import com.squareup.workflow1.ui.ScreenViewUpdater.Companion.bind
1615
import com.squareup.workflow1.ui.ViewEnvironment
1716
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1817
import com.squareup.workflow1.ui.WorkflowViewStub
@@ -101,7 +100,8 @@ class BoardsListLayoutUpdater(rootView: View) : ScreenViewUpdater<DisplayBoardsL
101100
)
102101
}
103102

104-
companion object : ScreenViewFactory<DisplayBoardsListScreen> by bind(
105-
R.layout.boards_list_layout, ::BoardsListLayoutUpdater
103+
companion object : ScreenViewFactory<DisplayBoardsListScreen> by ScreenViewFactory.ofLayout(
104+
R.layout.boards_list_layout,
105+
{ it: View -> BoardsListLayoutUpdater(it) }
106106
)
107107
}

samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameLayoutUpdater.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.squareup.sample.dungeon.Direction.UP
1212
import com.squareup.sample.dungeon.GameWorkflow.GameRendering
1313
import com.squareup.workflow1.ui.ScreenViewFactory
1414
import com.squareup.workflow1.ui.ScreenViewUpdater
15-
import com.squareup.workflow1.ui.ScreenViewUpdater.Companion.bind
1615
import com.squareup.workflow1.ui.ViewEnvironment
1716
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1817
import com.squareup.workflow1.ui.WorkflowViewStub
@@ -66,7 +65,8 @@ class GameLayoutUpdater(view: View) : ScreenViewUpdater<GameRendering> {
6665
}
6766
}
6867

69-
companion object : ScreenViewFactory<GameRendering> by bind(
70-
R.layout.game_layout, ::GameLayoutUpdater
68+
companion object : ScreenViewFactory<GameRendering> by ScreenViewFactory.ofLayout(
69+
R.layout.game_layout,
70+
{ it: View -> GameLayoutUpdater(it) }
7171
)
7272
}

samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/LoadingBinding.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import androidx.annotation.StringRes
88
import com.squareup.workflow1.ui.Screen
99
import com.squareup.workflow1.ui.ScreenViewFactory
1010
import com.squareup.workflow1.ui.ScreenViewUpdater
11-
import com.squareup.workflow1.ui.ScreenViewUpdater.Companion.bind
1211
import com.squareup.workflow1.ui.ViewEnvironment
1312
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1413

@@ -23,7 +22,12 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
2322
inline fun <reified RenderingT : Screen> LoadingBinding(
2423
@StringRes loadingLabelRes: Int
2524
): ScreenViewFactory<RenderingT> =
26-
bind(R.layout.loading_layout) { view -> LoadingLayoutUpdater(loadingLabelRes, view) }
25+
ScreenViewFactory.ofLayout(R.layout.loading_layout) { view: View ->
26+
LoadingLayoutUpdater(
27+
loadingLabelRes,
28+
view
29+
)
30+
}
2731

2832
@PublishedApi
2933
internal class LoadingLayoutUpdater<RenderingT : Screen>(

samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineLayoutUpdater.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.transition.TransitionManager
99
import com.squareup.sample.timemachine.shakeable.internal.GlassFrameLayout
1010
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1111
import com.squareup.workflow1.ui.ScreenViewUpdater
12-
import com.squareup.workflow1.ui.ScreenViewUpdater.Companion.bind
1312
import com.squareup.workflow1.ui.ViewEnvironment
1413
import com.squareup.workflow1.ui.ScreenViewFactory
1514
import com.squareup.workflow1.ui.WorkflowViewStub
@@ -87,7 +86,8 @@ class ShakeableTimeMachineLayoutUpdater(
8786

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

90-
companion object : ScreenViewFactory<ShakeableTimeMachineScreen> by bind(
91-
R.layout.shakeable_time_machine_layout, ::ShakeableTimeMachineLayoutUpdater
89+
companion object : ScreenViewFactory<ShakeableTimeMachineScreen> by ScreenViewFactory.ofLayout(
90+
R.layout.shakeable_time_machine_layout,
91+
{ it: View -> ShakeableTimeMachineLayoutUpdater(it) }
9292
)
9393
}

samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloRendering.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.squareup.sample.helloworkflowfragment
22

3+
import android.view.LayoutInflater
4+
import android.view.ViewGroup
35
import com.squareup.sample.helloworkflowfragment.databinding.HelloGoodbyeLayoutBinding
46
import com.squareup.workflow1.ui.AndroidScreen
57
import com.squareup.workflow1.ui.ScreenViewFactory
@@ -12,8 +14,16 @@ data class HelloRendering(
1214
val onClick: () -> Unit
1315
) : AndroidScreen<HelloRendering> {
1416
override val viewFactory: ScreenViewFactory<HelloRendering> =
15-
ScreenViewUpdater.bind(HelloGoodbyeLayoutBinding::inflate) { r, _ ->
16-
helloMessage.text = "${r.message} Fragment"
17-
helloMessage.setOnClickListener { r.onClick() }
17+
ScreenViewFactory.ofViewBinding<BindingT, ScreenT>({ inflater: LayoutInflater, parent: ViewGroup?, attachToParent: Boolean ->
18+
HelloGoodbyeLayoutBinding.inflate(
19+
inflater,
20+
parent,
21+
attachToParent
22+
)
23+
}) { binding ->
24+
ScreenViewUpdater<ScreenT> { rendering, viewEnvironment ->
25+
binding.helloMessage.text = "${rendering.message} Fragment"
26+
binding.helloMessage.setOnClickListener { rendering.onClick() }
27+
}
1828
}
1929
}

0 commit comments

Comments
 (0)