Skip to content

Commit 94bf8af

Browse files
committed
Created ParcelableTextController.
1 parent bb98bdb commit 94bf8af

File tree

4 files changed

+94
-22
lines changed

4 files changed

+94
-22
lines changed

workflow-ui/core-android/api/core-android.api

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ public final class com/squareup/workflow1/ui/NamedViewFactory : com/squareup/wor
8585
public fun getType ()Lkotlin/reflect/KClass;
8686
}
8787

88+
public final class com/squareup/workflow1/ui/ParcelableTextController : android/os/Parcelable, com/squareup/workflow1/ui/TextController {
89+
public static final field CREATOR Lcom/squareup/workflow1/ui/ParcelableTextController$CREATOR;
90+
public synthetic fun <init> (Landroid/os/Parcel;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
91+
public fun <init> (Ljava/lang/String;)V
92+
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
93+
public fun describeContents ()I
94+
public fun getOnTextChanged ()Lkotlinx/coroutines/flow/Flow;
95+
public fun getTextValue ()Ljava/lang/String;
96+
public fun setTextValue (Ljava/lang/String;)V
97+
public fun writeToParcel (Landroid/os/Parcel;I)V
98+
}
99+
100+
public final class com/squareup/workflow1/ui/ParcelableTextController$CREATOR : android/os/Parcelable$Creator {
101+
public fun createFromParcel (Landroid/os/Parcel;)Lcom/squareup/workflow1/ui/ParcelableTextController;
102+
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
103+
public fun newArray (I)[Lcom/squareup/workflow1/ui/ParcelableTextController;
104+
public synthetic fun newArray (I)[Ljava/lang/Object;
105+
}
106+
88107
public final class com/squareup/workflow1/ui/PickledTreesnapshot : android/os/Parcelable {
89108
public static final field CREATOR Lcom/squareup/workflow1/ui/PickledTreesnapshot$CREATOR;
90109
public fun <init> (Lcom/squareup/workflow1/TreeSnapshot;)V
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.squareup.workflow1.ui
2+
3+
import android.os.Parcel
4+
import android.os.Parcelable
5+
import android.os.Parcelable.Creator
6+
7+
/**
8+
* [Parcelable] implementation of [TextController].
9+
*/
10+
@WorkflowUiExperimentalApi
11+
public class ParcelableTextController private constructor(
12+
controllerImplementation: TextController
13+
) : TextController by controllerImplementation, Parcelable {
14+
15+
public constructor(initialValue: String = "") : this(TextController(initialValue))
16+
17+
private constructor(parcel: Parcel) : this(parcel.readString() ?: "")
18+
19+
override fun writeToParcel(
20+
out: Parcel,
21+
flags: Int
22+
) {
23+
out.writeString(textValue)
24+
}
25+
26+
override fun describeContents(): Int = 0
27+
28+
public companion object CREATOR : Creator<ParcelableTextController> {
29+
30+
override fun createFromParcel(source: Parcel): ParcelableTextController =
31+
ParcelableTextController(source)
32+
33+
override fun newArray(size: Int): Array<ParcelableTextController?> = arrayOfNulls(size)
34+
}
35+
}

workflow-ui/core-common/api/core-common.api

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ public final class com/squareup/workflow1/ui/Named : com/squareup/workflow1/ui/C
2626
public fun toString ()Ljava/lang/String;
2727
}
2828

29-
public final class com/squareup/workflow1/ui/TextController {
30-
public fun <init> ()V
31-
public fun <init> (Ljava/lang/String;)V
32-
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
33-
public final fun getOnTextChanged ()Lkotlinx/coroutines/flow/Flow;
34-
public final fun getTextValue ()Ljava/lang/String;
35-
public final fun setTextValue (Ljava/lang/String;)V
29+
public abstract interface class com/squareup/workflow1/ui/TextController {
30+
public abstract fun getOnTextChanged ()Lkotlinx/coroutines/flow/Flow;
31+
public abstract fun getTextValue ()Ljava/lang/String;
32+
public abstract fun setTextValue (Ljava/lang/String;)V
33+
}
34+
35+
public final class com/squareup/workflow1/ui/TextControllerKt {
36+
public static final fun TextController (Ljava/lang/String;)Lcom/squareup/workflow1/ui/TextController;
37+
public static synthetic fun TextController$default (Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/TextController;
3638
}
3739

3840
public abstract interface annotation class com/squareup/workflow1/ui/WorkflowUiExperimentalApi : java/lang/annotation/Annotation {

workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/TextController.kt

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,35 @@ import kotlinx.coroutines.flow.drop
3333
* worker.
3434
*/
3535
@WorkflowUiExperimentalApi
36-
public class TextController(initialValue: String = "") {
36+
public interface TextController {
37+
38+
/**
39+
* A [Flow] that emits the text value whenever it changes -- and only when it changes, the current value
40+
* is not provided at subscription time. Workflows can safely observe changes by
41+
* converting this value to a worker. (When using multiple instances, remember to provide unique
42+
* key values to each `asWorker` call.)
43+
*
44+
* If you can do processing that doesn't require running a `WorkflowAction` or triggering a render
45+
* pass, it can be done in regular Flow operators before converting to a worker.
46+
*/
47+
public val onTextChanged: Flow<String>
48+
49+
/**
50+
* The current text value.
51+
*/
52+
public var textValue: String
53+
}
54+
55+
@WorkflowUiExperimentalApi
56+
public fun TextController(initialValue: String = ""): TextController {
57+
return TextControllerImpl(initialValue)
58+
}
59+
60+
/**
61+
* Default implementation of [TextController].
62+
*/
63+
@WorkflowUiExperimentalApi
64+
private class TextControllerImpl(initialValue: String) : TextController {
3765

3866
/**
3967
* This flow is not exposed as a StateFlow intentionally. Doing so would encourage observing it from
@@ -49,21 +77,9 @@ public class TextController(initialValue: String = "") {
4977
*/
5078
private val _textValue: MutableStateFlow<String> = MutableStateFlow(initialValue)
5179

52-
/**
53-
* A [Flow] that emits the text value whenever it changes -- and only when it changes, the current value
54-
* is not provided at subscription time. Workflows can safely observe changes by
55-
* converting this value to a worker. (When using multiple instances, remember to provide unique
56-
* key values to each `asWorker` call.)
57-
*
58-
* If you can do processing that doesn't require running a `WorkflowAction` or triggering a render
59-
* pass, it can be done in regular Flow operators before converting to a worker.
60-
*/
61-
public val onTextChanged: Flow<String> = _textValue.drop(1)
80+
override val onTextChanged: Flow<String> = _textValue.drop(1)
6281

63-
/**
64-
* The current text value.
65-
*/
66-
public var textValue: String
82+
override var textValue: String
6783
get() = _textValue.value
6884
set(value) {
6985
_textValue.value = value

0 commit comments

Comments
 (0)