Skip to content

Instantly share code, notes, and snippets.

Avatar

Ray Ryan rjrjr

View GitHub Profile
View Compose Worker
package com.squareup.sample.compose.hellocomposebinding
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.Rendering
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.HG
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.HG.Goodbye
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.HG.Hello
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.State
import com.squareup.sample.compose.hellocomposeworkflow.HelloWorkflow
import com.squareup.workflow1.Snapshot
import com.squareup.workflow1.StatefulWorkflow
View TextController.kt
package com.squareup.workflow.pos.text
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.TextView
import com.squareup.util.coroutines.launchWhenAttached
import com.squareup.workflow1.ExperimentalWorkflowApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
View ActivityAsWorkflowProps.kt
@OptIn(WorkflowUiExperimentalApi::class)
class HelloWorkflowActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// This ViewModel will survive configuration changes. It's instantiated
// by the first call to viewModels(), and that original instance is returned by
// succeeding calls.
val model: HelloViewModel by viewModels()
@rjrjr
rjrjr / Gatekeeper.kt
Last active Aug 5, 2021
Gatekeeper workflow pattern
View Gatekeeper.kt
/**
* In our production code, this typealias is more interesting,
* something like AlertContainerScreen<PanelContainerScreen<R>>
*/
typealias MetaRootRendering<R>: AlertContainerScreen<R>
data class ActivityAndRoot<R> (
val activity: Activity,
val root: R
)
@rjrjr
rjrjr / java-sealed-class
Last active Mar 20, 2022
Poor Man's Sealed Classes (visitor pattern)
View java-sealed-class
/**
* For Java developers all excited by and jealous of Kotlin's sealed classes.
* Do this when you wish you could put parameters on an enum.
*/
public class PoorMan {
interface Event {
<T> T dispatch(EventHandler<T> handler);
}
interface EventHandler<T> {
View NewViewPresenter.java
package mortar;
import android.view.View;
import mortar.bundler.BundleService;
public class NewViewPresenter<V extends View> extends NewPresenter<V> {
@Override protected final MortarScope extractScope(V view) {
return MortarScope.getScope(view.getContext());
}
}
View NewPresenter.java
package mortar;
public abstract class NewPresenter<V> {
private V view = null;
private Scoped registration = new Scoped() {
@Override public void onEnterScope(MortarScope scope) {
NewPresenter.this.onEnterScope(scope);
}