Skip to content

Commit 984358a

Browse files
699: Refactor Poetry Workflows into Common; Add Performance Poetry App
1 parent 4860a4e commit 984358a

File tree

11 files changed

+107
-6
lines changed

11 files changed

+107
-6
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
plugins {
2+
id("com.android.application")
3+
kotlin("android")
4+
}
5+
6+
apply(from = rootProject.file(".buildscript/android-sample-app.gradle"))
7+
apply(from = rootProject.file(".buildscript/android-ui-tests.gradle"))
8+
9+
android {
10+
defaultConfig {
11+
applicationId = "com.squareup.benchmarks.performance.poetry"
12+
}
13+
}
14+
15+
dependencies {
16+
debugImplementation(libs.squareup.leakcanary.android)
17+
18+
implementation(project(":samples:containers:android"))
19+
implementation(project(":samples:containers:poetry"))
20+
implementation(project(":workflow-ui:core-android"))
21+
22+
implementation(libs.androidx.activity.ktx)
23+
implementation(libs.androidx.recyclerview)
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.squareup.benchmarks.performance.poetry">
5+
6+
<application
7+
android:allowBackup="false"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme"
10+
tools:ignore="AllowBackup,GoogleAppIndexingWarning,MissingApplicationIcon">
11+
<activity
12+
android:name=".PerformancePoetryActivity"
13+
android:exported="true">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.squareup.benchmarks.performance.poetry
2+
3+
import android.os.Bundle
4+
import androidx.activity.viewModels
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.lifecycle.SavedStateHandle
7+
import androidx.lifecycle.ViewModel
8+
import androidx.lifecycle.viewModelScope
9+
import com.squareup.sample.container.SampleContainers
10+
import com.squareup.sample.poetry.PoemsBrowserWorkflow
11+
import com.squareup.sample.poetry.model.Poem
12+
import com.squareup.workflow1.ui.WorkflowLayout
13+
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
14+
import com.squareup.workflow1.ui.backstack.BackStackContainer
15+
import com.squareup.workflow1.ui.plus
16+
import com.squareup.workflow1.ui.renderWorkflowIn
17+
import kotlinx.coroutines.flow.StateFlow
18+
import timber.log.Timber
19+
20+
@OptIn(WorkflowUiExperimentalApi::class)
21+
private val viewRegistry = SampleContainers + BackStackContainer
22+
23+
public class PerformancePoetryActivity : AppCompatActivity() {
24+
@OptIn(WorkflowUiExperimentalApi::class)
25+
override fun onCreate(savedInstanceState: Bundle?) {
26+
super.onCreate(savedInstanceState)
27+
28+
val model: PoetryModel by viewModels()
29+
setContentView(
30+
WorkflowLayout(this).apply { start(lifecycle, model.renderings, viewRegistry) }
31+
)
32+
}
33+
34+
public companion object {
35+
init {
36+
Timber.plant(Timber.DebugTree())
37+
}
38+
}
39+
}
40+
41+
public class PoetryModel(savedState: SavedStateHandle) : ViewModel() {
42+
@OptIn(WorkflowUiExperimentalApi::class)
43+
public val renderings: StateFlow<Any> by lazy {
44+
renderWorkflowIn(
45+
workflow = PoemsBrowserWorkflow,
46+
scope = viewModelScope,
47+
prop = Poem.allPoems,
48+
savedStateHandle = savedState
49+
)
50+
}
51+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Performance Poetry</string>
3+
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.lifecycle.SavedStateHandle
77
import androidx.lifecycle.ViewModel
88
import androidx.lifecycle.viewModelScope
99
import com.squareup.sample.container.SampleContainers
10+
import com.squareup.sample.poetry.PoemsBrowserWorkflow
1011
import com.squareup.sample.poetry.model.Poem
1112
import com.squareup.workflow1.ui.WorkflowLayout
1213
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<resources>
22
<string name="app_name">Poetry</string>
3-
<string name="poems">Poems</string>
43
</resources>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.squareup.sample.poetryapp
1+
package com.squareup.sample.poetry
22

33
import android.view.LayoutInflater
44
import android.view.View
@@ -9,7 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
99
import androidx.recyclerview.widget.RecyclerView
1010
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig
1111
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Overview
12-
import com.squareup.sample.container.poetryapp.R
12+
import com.squareup.sample.container.poetry.R
1313
import com.squareup.sample.poetry.model.Poem
1414
import com.squareup.workflow1.ui.AndroidViewRendering
1515
import com.squareup.workflow1.ui.LayoutRunner
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.squareup.sample.poetryapp
1+
package com.squareup.sample.poetry
22

33
import com.squareup.sample.poetry.model.Poem
44
import com.squareup.workflow1.StatelessWorkflow
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package com.squareup.sample.poetryapp
1+
package com.squareup.sample.poetry
22

33
import com.squareup.sample.container.overviewdetail.OverviewDetailScreen
4-
import com.squareup.sample.poetry.PoemWorkflow
54
import com.squareup.sample.poetry.model.Poem
65
import com.squareup.workflow1.Snapshot
76
import com.squareup.workflow1.StatefulWorkflow

samples/containers/poetry/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<string name="up">Up</string>
33
<string name="previous">…previous</string>
44
<string name="next">next…</string>
5+
<string name="poems">Poems</string>
56
</resources>

0 commit comments

Comments
 (0)