A fully functional Android app built entirely with Kotlin and Jetpack Compose
Fix selecting authors
mlykotom1a36ae50effb
diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.ktindex 159506bc8..92fe3c325 100644--- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt+++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt@@ -48,7 +48,7 @@ class BaselineProfileGenerator {// Scroll the feed critical user journeyforYouWaitForContent()- forYouSelectAuthors()+ forYouSelectAuthors(true)forYouScrollFeedDownUp()// Navigate to saved screendiff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.ktindex 3c33e3f13..b945aa188 100644--- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt+++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt@@ -18,11 +18,9 @@ package com.google.samples.apps.nowinandroid.foryouimport androidx.benchmark.macro.MacrobenchmarkScopeimport androidx.test.uiautomator.By-import androidx.test.uiautomator.Direction.RIGHTimport androidx.test.uiautomator.Untilimport androidx.test.uiautomator.untilHasChildrenimport com.google.samples.apps.nowinandroid.flingElementDownUp-import kotlin.random.Random.Default.nextIntfun MacrobenchmarkScope.forYouWaitForContent() {// Wait until content is loaded by checking if authors are loaded@@ -33,21 +31,40 @@ fun MacrobenchmarkScope.forYouWaitForContent() {obj.wait(untilHasChildren(), 30_000)}-fun MacrobenchmarkScope.forYouSelectAuthors() {+/**+ * Selects some authors, which will show the feed content for them.+ * [recheckAuthorsIfChecked] Authors may be already checked from the previous iteration.+ */+fun MacrobenchmarkScope.forYouSelectAuthors(recheckAuthorsIfChecked: Boolean = false) {val authors = device.findObject(By.res("forYou:authors"))- // set gesture margin from sides not to trigger system gesture navigation+ // Set gesture margin from sides not to trigger system gesture navigationval horizontalMargin = 10 * authors.visibleBounds.width() / 100authors.setGestureMargins(horizontalMargin, 0, horizontalMargin, 0)- // select some random authors to show some feed content- repeat(3) {- // picks randomly from visible authors- val randomChild = nextInt(0, authors.childCount)- val author = authors.children[randomChild]- author.click()- device.waitForIdle()- authors.fling(RIGHT)+ // Select some authors to show some feed content+ repeat(3) { index ->+ val author = authors.children[index % authors.childCount]++ when {+ // Author wasn't checked, so just do that+ !author.isChecked -> {+ author.click()+ device.waitForIdle()+ }++ // The author was checked already and we want to recheck it, so just do it twice+ recheckAuthorsIfChecked -> {+ repeat(2) {+ author.click()+ device.waitForIdle()+ }+ }++ else -> {+ // The author is checked, but we don't recheck it+ }+ }}}