From f2b093dbe6ca06d6cc4614934e48b680ba9d0e97 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Mon, 6 May 2024 13:32:19 +0200 Subject: [PATCH] Take screenshots of the about view and dynamic color themed main view --- app/build.gradle | 1 + .../java/dev/rocli/android/webdav/ScreenshotTest.kt | 13 +++++++++++++ .../dev/rocli/android/webdav/WebDavApplication.kt | 8 +------- .../rocli/android/webdav/activities/MainActivity.kt | 4 ++++ .../rocli/android/webdav/fragments/AboutFragment.kt | 12 +++++++++++- app/src/main/res/layout/fragment_about.xml | 1 + 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d01f37b..ccca983 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,6 +41,7 @@ android { buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\"" buildConfigField "String", "GIT_BRANCH", "\"${getGitBranch()}\"" buildConfigField "java.util.concurrent.atomic.AtomicBoolean", "TEST", "new java.util.concurrent.atomic.AtomicBoolean(false)" + buildConfigField "java.util.concurrent.atomic.AtomicBoolean", "DYNAMIC_COLORS", "new java.util.concurrent.atomic.AtomicBoolean(true)" kapt { arguments { diff --git a/app/src/androidTest/java/dev/rocli/android/webdav/ScreenshotTest.kt b/app/src/androidTest/java/dev/rocli/android/webdav/ScreenshotTest.kt index 8e5304f..7c2409b 100644 --- a/app/src/androidTest/java/dev/rocli/android/webdav/ScreenshotTest.kt +++ b/app/src/androidTest/java/dev/rocli/android/webdav/ScreenshotTest.kt @@ -4,6 +4,7 @@ import androidx.test.core.app.ActivityScenario import androidx.test.core.app.takeScreenshot import androidx.test.core.graphics.writeToTestStorage import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.Espresso.openContextualActionModeOverflowMenu import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.longClick import androidx.test.espresso.action.ViewActions.pressBack @@ -77,6 +78,11 @@ class ScreenshotTest { onView(withId(R.id.rvAccounts)) .check(matches(hasDescendant(withText("Nextcloud")))) + takeScreenshot().writeToTestStorage("screenshot6") + + BuildConfig.DYNAMIC_COLORS.set(false) + scenario.recreate() + takeScreenshot().writeToTestStorage("screenshot1") onView(withId(R.id.rvAccounts)).perform( @@ -91,6 +97,13 @@ class ScreenshotTest { onView(isRoot()).perform(pressBack()) + openContextualActionModeOverflowMenu() + onView(withText(R.string.action_about)).perform(click()) + + takeScreenshot().writeToTestStorage("screenshot5") + + onView(isRoot()).perform(pressBack()) + onView(withId(R.id.rvAccounts)).perform( RecyclerViewActions.actionOnItem( hasDescendant(withText("Nextcloud")), diff --git a/app/src/main/java/dev/rocli/android/webdav/WebDavApplication.kt b/app/src/main/java/dev/rocli/android/webdav/WebDavApplication.kt index a34df32..bfa3652 100644 --- a/app/src/main/java/dev/rocli/android/webdav/WebDavApplication.kt +++ b/app/src/main/java/dev/rocli/android/webdav/WebDavApplication.kt @@ -1,13 +1,7 @@ package dev.rocli.android.webdav import android.app.Application -import com.google.android.material.color.DynamicColors import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp -class WebDavApplication : Application() { - override fun onCreate() { - super.onCreate() - DynamicColors.applyToActivitiesIfAvailable(this) - } -} +class WebDavApplication : Application() diff --git a/app/src/main/java/dev/rocli/android/webdav/activities/MainActivity.kt b/app/src/main/java/dev/rocli/android/webdav/activities/MainActivity.kt index 672ee63..c64a158 100644 --- a/app/src/main/java/dev/rocli/android/webdav/activities/MainActivity.kt +++ b/app/src/main/java/dev/rocli/android/webdav/activities/MainActivity.kt @@ -14,6 +14,7 @@ import androidx.navigation.NavController import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.findNavController import androidx.navigation.ui.NavigationUI.setupActionBarWithNavController +import com.google.android.material.color.DynamicColors import com.google.android.material.color.MaterialColors import dagger.hilt.android.AndroidEntryPoint import dev.rocli.android.webdav.BuildConfig @@ -29,6 +30,9 @@ class MainActivity : AppCompatActivity() { private lateinit var statusGuardHack: ActionModeStatusGuardHack override fun onCreate(savedInstanceState: Bundle?) { + if (BuildConfig.DYNAMIC_COLORS.get()) { + DynamicColors.applyToActivityIfAvailable(this) + } super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) diff --git a/app/src/main/java/dev/rocli/android/webdav/fragments/AboutFragment.kt b/app/src/main/java/dev/rocli/android/webdav/fragments/AboutFragment.kt index cfd6ce5..08bf086 100644 --- a/app/src/main/java/dev/rocli/android/webdav/fragments/AboutFragment.kt +++ b/app/src/main/java/dev/rocli/android/webdav/fragments/AboutFragment.kt @@ -6,7 +6,11 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle -import android.view.* +import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.View +import android.view.ViewGroup import android.widget.Toast import androidx.annotation.StringRes import androidx.databinding.DataBindingUtil @@ -35,6 +39,12 @@ class AboutFragment : LibsSupportFragment() { super.onViewCreated(view, savedInstanceState) setHasOptionsMenu(true) + // Override the app name during instrumented tests so that + // we don't see "(Debug)" in the automatically generated screenshots. + if (BuildConfig.TEST.get()) { + binding.textAppName.text = getString(R.string.app_name_release) + } + binding.appVersion.text = getCurrentAppVersion() binding.btnLicense.setOnClickListener { LicenseDialog.create().show(parentFragmentManager, null) diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index 5204ddd..8a4a313 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -51,6 +51,7 @@ Licenced under GPLv3 tools:ignore="ContentDescription" />