Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
fix(theme): opaque, readable dialogs in every skin, enforced by lint
Durganshu4aed0824abab
diff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.ktindex 3ebe55b..dcd4dd3 100644--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt@@ -772,7 +772,7 @@ fun ChatScreen(Icons.Default.Stop,contentDescription = stringResource(R.string.chat_stop_recording),modifier = Modifier.size(20.dp),- tint = Color.White+ tint = MaterialTheme.colorScheme.onError)}}diff --git a/app/src/main/java/com/gotcha/ui/InboxScreen.kt b/app/src/main/java/com/gotcha/ui/InboxScreen.ktindex 3b47f5c..b79ca14 100644--- a/app/src/main/java/com/gotcha/ui/InboxScreen.kt+++ b/app/src/main/java/com/gotcha/ui/InboxScreen.kt@@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.shape.CircleShapeimport androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.material3.AlertDialogimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport androidx.compose.material3.Text@@ -29,6 +28,8 @@ import androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dpimport com.gotcha.Rimport com.gotcha.notifications.InboxEntry+import com.gotcha.ui.theme.SkinAlertDialog+import com.gotcha.ui.theme.fade/*** The in-app notification inbox (issue #100): everything Gotcha has notified@@ -81,7 +82,7 @@ fun InboxScreen(}if (confirmClear) {- AlertDialog(+ SkinAlertDialog(onDismissRequest = { confirmClear = false },title = { Text(stringResource(R.string.inbox_clear_notification_history)) },text = {@@ -111,7 +112,7 @@ private fun InboxRow(entry: InboxEntry, onClick: () -> Unit) {val scheme = MaterialTheme.colorSchemeSurface(shape = RoundedCornerShape(16.dp),- color = scheme.surfaceVariant.copy(alpha = 0.5f),+ color = scheme.surfaceVariant.fade(0.5f),modifier = Modifier.fillMaxWidth().clickable(onClick = onClick)diff --git a/app/src/main/java/com/gotcha/ui/LocalNotificationsSection.kt b/app/src/main/java/com/gotcha/ui/LocalNotificationsSection.ktindex 19bd38b..ab6aad7 100644--- a/app/src/main/java/com/gotcha/ui/LocalNotificationsSection.kt+++ b/app/src/main/java/com/gotcha/ui/LocalNotificationsSection.kt@@ -13,7 +13,6 @@ import androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.sizeimport androidx.compose.material.icons.Iconsimport androidx.compose.material.icons.filled.Check-import androidx.compose.material3.AlertDialogimport androidx.compose.material3.FilterChipimport androidx.compose.material3.FilterChipDefaultsimport androidx.compose.material3.Icon@@ -36,6 +35,7 @@ import com.gotcha.data.Settingsimport com.gotcha.notifications.LocalNotificationSchedulerimport com.gotcha.notifications.LocalNotificationStoreimport com.gotcha.notifications.inQuietHours+import com.gotcha.ui.theme.SkinAlertDialogimport java.time.LocalTimeimport java.time.format.DateTimeFormatterimport java.time.format.FormatStyle@@ -204,7 +204,7 @@ internal fun LocalNotificationsSection(}if (confirmClear) {- AlertDialog(+ SkinAlertDialog(onDismissRequest = { confirmClear = false },title = { Text(stringResource(R.string.local_notifications_clear_notification_history)) },text = {diff --git a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt b/app/src/main/java/com/gotcha/ui/SettingsCommon.ktindex c1d5577..a4263c3 100644--- a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt+++ b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt@@ -75,6 +75,7 @@ import com.gotcha.auth.ReferralClipboardHelperimport com.gotcha.auth.SamosaTierimport com.gotcha.auth.SamosaUserimport com.gotcha.i18n.StringLookup+import com.gotcha.ui.theme.fadeimport kotlinx.coroutines.delayimport kotlinx.coroutines.flow.dropimport kotlinx.coroutines.launch@@ -537,7 +538,7 @@ fun ReferAndEarnCard(if (referredByCode != null) {Surface(shape = RoundedCornerShape(8.dp),- color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.5f),+ color = MaterialTheme.colorScheme.secondaryContainer.fade(0.5f),modifier = Modifier.fillMaxWidth()) {Row(diff --git a/app/src/main/java/com/gotcha/ui/SkillsScreen.kt b/app/src/main/java/com/gotcha/ui/SkillsScreen.ktindex 736bdc4..6fc06d7 100644--- a/app/src/main/java/com/gotcha/ui/SkillsScreen.kt+++ b/app/src/main/java/com/gotcha/ui/SkillsScreen.kt@@ -17,7 +17,6 @@ import androidx.compose.material3.IconButtonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.OutlinedButtonimport androidx.compose.material3.OutlinedTextField-import androidx.compose.material3.Surfaceimport androidx.compose.material3.Switchimport androidx.compose.material3.Textimport androidx.compose.material3.TextButton@@ -42,6 +41,7 @@ import com.gotcha.agent.skills.SkillRegistryimport com.gotcha.data.Settingsimport com.gotcha.i18n.stringLookupimport com.gotcha.ui.theme.SkinAlertDialog+import com.gotcha.ui.theme.SkinDialogimport kotlinx.coroutines.launch/**@@ -185,58 +185,59 @@ fun SkillsScreen(modifier = Modifier.fillMaxWidth()) { Text(stringResource(R.string.skills_paste_json)) }if (pasteOpen) {- androidx.compose.ui.window.Dialog(onDismissRequest = {- pasteOpen = false- communitySkillPasteJson = ""- }) {- Surface(shape = MaterialTheme.shapes.medium) {- Column(- modifier = Modifier.padding(16.dp),- verticalArrangement = Arrangement.spacedBy(8.dp)+ SkinDialog(+ onDismissRequest = {+ pasteOpen = false+ communitySkillPasteJson = ""+ },+ shape = MaterialTheme.shapes.medium+ ) {+ Column(+ modifier = Modifier.padding(16.dp),+ verticalArrangement = Arrangement.spacedBy(8.dp)+ ) {+ Text(+ stringResource(R.string.skills_paste_community_skill_json),+ style = MaterialTheme.typography.titleMedium+ )+ OutlinedTextField(+ value = communitySkillPasteJson,+ onValueChange = { communitySkillPasteJson = it },+ label = { Text(stringResource(R.string.skills_skill_json)) },+ modifier = Modifier.fillMaxWidth().height(220.dp),+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)+ )+ Row(+ horizontalArrangement = Arrangement.End,+ modifier = Modifier.fillMaxWidth()) {- Text(- stringResource(R.string.skills_paste_community_skill_json),- style = MaterialTheme.typography.titleMedium- )- OutlinedTextField(- value = communitySkillPasteJson,- onValueChange = { communitySkillPasteJson = it },- label = { Text(stringResource(R.string.skills_skill_json)) },- modifier = Modifier.fillMaxWidth().height(220.dp),- keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)- )- Row(- horizontalArrangement = Arrangement.End,- modifier = Modifier.fillMaxWidth()- ) {- TextButton(onClick = {- pasteOpen = false- communitySkillPasteJson = ""- }) { Text(stringResource(R.string.skills_cancel)) }- TextButton(onClick = {- val src = communitySkillPasteJson.trim()- if (src.isEmpty()) {- overlay.show(localContext.getString(R.string.skills_paste_json_first))- return@TextButton+ TextButton(onClick = {+ pasteOpen = false+ communitySkillPasteJson = ""+ }) { Text(stringResource(R.string.skills_cancel)) }+ TextButton(onClick = {+ val src = communitySkillPasteJson.trim()+ if (src.isEmpty()) {+ overlay.show(localContext.getString(R.string.skills_paste_json_first))+ return@TextButton+ }+ communityImportBusy = true+ pasteOpen = false+ overlay.show(localContext.getString(R.string.skills_importing_skill), sticky = true)+ scope.launch {+ val result = runCatching {+ SkillRegistry.importCommunity(src)}- communityImportBusy = true- pasteOpen = false- overlay.show(localContext.getString(R.string.skills_importing_skill), sticky = true)- scope.launch {- val result = runCatching {- SkillRegistry.importCommunity(src)- }- communityImportBusy = false- communitySkillPasteJson = ""- result.onSuccess { skill ->- communitySkillRefreshTick++- overlay.show(localContext.getString(R.string.skills_imported, skill.id))- }.onFailure { e ->- overlay.show(formatImportError(e, localContext.stringLookup()))- }+ communityImportBusy = false+ communitySkillPasteJson = ""+ result.onSuccess { skill ->+ communitySkillRefreshTick+++ overlay.show(localContext.getString(R.string.skills_imported, skill.id))+ }.onFailure { e ->+ overlay.show(formatImportError(e, localContext.stringLookup()))}- }) { Text(stringResource(R.string.skills_import)) }- }+ }+ }) { Text(stringResource(R.string.skills_import)) }}}}diff --git a/app/src/main/java/com/gotcha/ui/theme/Color.kt b/app/src/main/java/com/gotcha/ui/theme/Color.ktindex 5e435e0..5ae73d3 100644--- a/app/src/main/java/com/gotcha/ui/theme/Color.kt+++ b/app/src/main/java/com/gotcha/ui/theme/Color.kt@@ -82,6 +82,9 @@ val OrchidOutline = Color(0xFFB878BE)val OrchidOnCoral = Color(0xFF45061F)val OrchidCoralContainer = Color(0xFF6E1443)+/** Dialogs and menus: deep enough that coral and the dim ink both clear 4.5:1. */+val OrchidPopup = Color(0xFF4A1052)+// ---- Nocturne: the icon's facets at wallpaper scale, behind dark glass ----val NocturneGround = Color(0xFF0A050E)val NocturnePanel = Color(0x8F1A1020)@@ -102,9 +105,12 @@ val NocturneOnMagentaContainer = Color(0xFFF7D9F2)// Glass is for chrome you look past; a sheet you are reading from needs a// ground of its own, or the screen behind it reads straight through the text.//-// Material 3 routes all of those through the surfaceContainer* roles, so-// setting them opaque here fixes the drawer, dialogs and menus in one move,-// while `surface` and `surfaceVariant` stay translucent for the in-page chrome.+// The drawer and sheets read the surfaceContainer* roles, so setting them+// opaque here covers those, while `surface` and `surfaceVariant` stay+// translucent for the in-page chrome. Dialogs and menus do NOT: Material 3+// 1.2 paints AlertDialog and DropdownMenu from `surface` (plus a rose tonal+// tint), which is why SkinAlertDialog and SkinDropdownMenu exist. The+// `gotcha` detekt rule set enforces both.val AuraContainerLowest = Color(0xFF050506)val AuraContainerLow = Color(0xFF0A0A0B)diff --git a/app/src/main/java/com/gotcha/ui/theme/Dialog.kt b/app/src/main/java/com/gotcha/ui/theme/Dialog.ktindex 846cafc..c05cc51 100644--- a/app/src/main/java/com/gotcha/ui/theme/Dialog.kt+++ b/app/src/main/java/com/gotcha/ui/theme/Dialog.kt@@ -1,9 +1,13 @@package com.gotcha.ui.themeimport androidx.compose.material3.AlertDialog+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Surfaceimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.Shape+import androidx.compose.ui.window.Dialog/*** Dialogs, in the skin.@@ -44,3 +48,23 @@ fun SkinAlertDialog(containerColor = containerColor)}++/**+ * A free-form dialog, in the skin: [Dialog] with its content already on an+ * opaque [Skin.menuContainer] panel.+ *+ * For dialogs [SkinAlertDialog]'s title/text/buttons layout does not fit. A bare+ * `Dialog { Surface { … } }` falls into the same trap as the Material alert+ * dialog: `Surface` defaults to the translucent `surface` role, so the screen+ * underneath reads through it on every glass skin.+ */+@Composable+fun SkinDialog(+ onDismissRequest: () -> Unit,+ shape: Shape = MaterialTheme.shapes.extraLarge,+ content: @Composable () -> Unit+) {+ Dialog(onDismissRequest = onDismissRequest) {+ Surface(shape = shape, color = LocalSkin.current.menuContainer, content = content)+ }+}diff --git a/app/src/main/java/com/gotcha/ui/theme/Skin.kt b/app/src/main/java/com/gotcha/ui/theme/Skin.ktindex af2f49e..d832b9f 100644--- a/app/src/main/java/com/gotcha/ui/theme/Skin.kt+++ b/app/src/main/java/com/gotcha/ui/theme/Skin.kt@@ -47,6 +47,9 @@ enum class Backdrop {* @param grain film-grain opacity over the ground, 0f–1f.* @param scrim a veil of [ground] over the wallpaper, 0f–1f, so body text is* never fighting whatever the wallpaper is doing underneath it.+ * @param popup what dialogs and menus paint, when the derived default (see+ * [menuContainer]) leaves the accent or the dim ink below 4.5:1 on it.+ * SkinContrastTest says when a skin needs one.*/data class Skin(val id: String,@@ -60,7 +63,8 @@ data class Skin(val frost: Dp = 0.dp,val grain: Float = 0f,val scrim: Float = 0f,- val corner: Dp = 20.dp+ val corner: Dp = 20.dp,+ val popup: Color? = null) {/*** Radius for the small stuff — inline images, the reasoning block, status@@ -97,9 +101,12 @@ data class Skin(** Named for menus because they were the first to need it; see* [com.gotcha.ui.theme.SkinAlertDialog] for the other caller.+ *+ * A skin can override it with [popup]: on Orchid the composited panel is a+ * light lilac that coral buttons all but vanish into.*/val menuContainer: Color- get() = scheme.surface.over(ground)+ get() = popup ?: scheme.surface.over(ground)/*** The same skin with the glass taken out: panels composited down onto their@@ -133,6 +140,17 @@ private fun ColorScheme.flattenOnto(ground: Color): ColorScheme = copy(secondaryContainer = secondaryContainer.over(ground))+/**+ * This colour at [fraction] of its own opacity.+ *+ * `copy(alpha = 0.5f)` *replaces* the alpha rather than scaling it. On Deep+ * Space's opaque roles the two are the same, which is how it slips through+ * review; on a glass skin `surfaceVariant` is already ~19% white, and replacing+ * that with 50% paints a pale grey slab that the dim ink beside it vanishes+ * into. Fade a scheme role with this, never with `copy(alpha = …)`.+ */+fun Color.fade(fraction: Float): Color = copy(alpha = alpha * fraction)+private fun Color.over(background: Color): Color {if (alpha >= 1f) return thisreturn Color(@@ -284,7 +302,9 @@ object Skins {frost = 20.dp,grain = 0.06f,scrim = 0.05f,- corner = 22.dp+ corner = 22.dp,+ // The derived panel grey leaves the rose at 4.3:1; one step darker clears it.+ popup = AuraContainerHigh)/** The icon's white field as an interface. The one skin that survives sun. */@@ -328,7 +348,10 @@ object Skins {grain = 0.12f,// The Arc read is a generous radius; it is half of why that look reads// as soft even though the colour is shouting.- corner = 26.dp+ corner = 26.dp,+ // Coral on the derived lilac panel measured 1.7:1 on a phone. Dialogs sit+ // on the ramp's violet, deepened until coral clears 5:1.+ popup = OrchidPopup)/** The launcher icon's low-poly geometry, blown up to wallpaper scale. */diff --git a/app/src/test/java/com/gotcha/ui/theme/SkinContrastTest.kt b/app/src/test/java/com/gotcha/ui/theme/SkinContrastTest.ktnew file mode 100644index 0000000..510d1f9--- /dev/null+++ b/app/src/test/java/com/gotcha/ui/theme/SkinContrastTest.kt@@ -0,0 +1,71 @@+package com.gotcha.ui.theme++import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.luminance+import org.junit.Assert.assertTrue+import org.junit.Test++/**+ * Text on dialogs and menus has to be readable in every skin.+ *+ * Popups are where this is testable: they sit on [Skin.menuContainer], one+ * opaque colour, so the contrast is exactly what the user sees. In-page chrome+ * sits on a wallpaper and isn't covered here.+ *+ * 4.5:1 is WCAG AA for body text — dialog titles, bodies and the TextButtons+ * along the bottom are all ordinary-sized text. Orchid's coral buttons once+ * came out at 1.7:1 on a lilac dialog, which nothing but a phone noticed.+ */+class SkinContrastTest {++ private val allMaterials = Skins.all + Skins.all.map { it.opaque() }++ @Test+ fun `dialog text is readable on the dialog in every skin`() {+ allMaterials.forEach { skin ->+ val popup = skin.menuContainer+ assertReadable(skin, "onSurface on the dialog", skin.scheme.onSurface, popup)+ assertReadable(skin, "onSurfaceVariant on the dialog", skin.scheme.onSurfaceVariant, popup)+ }+ }++ @Test+ fun `dialog buttons are readable on the dialog in every skin`() {+ allMaterials.forEach { skin ->+ assertReadable(skin, "primary (TextButton) on the dialog", skin.scheme.primary, skin.menuContainer)+ assertReadable(skin, "error on the dialog", skin.scheme.error, skin.menuContainer)+ }+ }++ @Test+ fun `content on an error fill is readable in every skin`() {+ allMaterials.forEach { skin ->+ assertReadable(skin, "onError on error", skin.scheme.onError, skin.scheme.error)+ }+ }++ @Test+ fun `the dialog is opaque in every skin`() {+ allMaterials.forEach { skin ->+ assertTrue("${skin.id}: dialogs must not be see-through", skin.menuContainer.alpha == 1f)+ }+ }++ private fun assertReadable(skin: Skin, what: String, fg: Color, bg: Color) {+ val ratio = contrast(fg, bg)+ assertTrue(+ "${skin.id}${if (skin.isGlass) "" else " (solid)"}: $what is %.2f:1, needs $MIN_TEXT:1".format(ratio),+ ratio >= MIN_TEXT+ )+ }++ private fun contrast(a: Color, b: Color): Float {+ val la = a.luminance()+ val lb = b.luminance()+ return (maxOf(la, lb) + 0.05f) / (minOf(la, lb) + 0.05f)+ }++ private companion object {+ const val MIN_TEXT = 4.5f+ }+}diff --git a/detekt-rules/detekt.yml b/detekt-rules/detekt.ymlindex 79b7f8d..7202704 100644--- a/detekt-rules/detekt.yml+++ b/detekt-rules/detekt.yml@@ -67,6 +67,12 @@ gotcha:# GotchaLog.kt is the one sanctioned place raw Log.d/Log.v appears (behind# BuildConfig.DEBUG). Everything else must route through the facade.excludes: ["**/GotchaLog.kt"]+ UnskinnedPopup:+ active: true+ # The theme package is where the Skin* wrappers call the Material originals.+ excludes: ["**/ui/theme/**"]+ GlassRoleAlphaOverride:+ active: trueformatting:MaximumLineLength:diff --git a/detekt-rules/src/main/kotlin/com/gotcha/detekt/GotchaRules.kt b/detekt-rules/src/main/kotlin/com/gotcha/detekt/GotchaRules.ktindex 33e9e41..4cd7ee8 100644--- a/detekt-rules/src/main/kotlin/com/gotcha/detekt/GotchaRules.kt+++ b/detekt-rules/src/main/kotlin/com/gotcha/detekt/GotchaRules.kt@@ -11,6 +11,7 @@ import io.gitlab.arturbosch.detekt.api.RuleSetProviderimport io.gitlab.arturbosch.detekt.api.Severityimport org.jetbrains.kotlin.psi.KtCallExpressionimport org.jetbrains.kotlin.psi.KtDotQualifiedExpression+import org.jetbrains.kotlin.psi.KtNameReferenceExpression/*** Blocks raw `android.util.Log.d` / `Log.v` calls. Those ship into release builds@@ -46,12 +47,95 @@ class NoRawDebugLog(config: Config) : Rule(config) {}}+/**+ * Blocks the raw popups — `AlertDialog`, `DropdownMenu`, `ExposedDropdownMenu`,+ * and the free-form `Dialog` / `BasicAlertDialog` / `Popup` — outside the theme+ * package. Material 3 1.2 paints the first three from the `surface` role, and a+ * bare `Surface` inside the others defaults to it too. Every glass skin (Aura,+ * Vellum, Orchid, Nocturne) leaves that role translucent, so the screen+ * underneath reads straight through the popup. `SkinAlertDialog`,+ * `SkinDropdownMenu`, `SkinExposedDropdownMenu` and `SkinDialog` hand them an+ * opaque container instead.+ *+ * Every screen was moved to the wrappers once; new screens kept reaching for+ * the Material originals, and nothing looks wrong on the default skin.+ */+class UnskinnedPopup(config: Config) : Rule(config) {+ override val issue = Issue(+ id = "UnskinnedPopup",+ severity = Severity.Defect,+ description = "Material 3 dialogs and menus are see-through on glass skins. " ++ "Use SkinAlertDialog / SkinDialog / SkinDropdownMenu / SkinExposedDropdownMenu from com.gotcha.ui.theme.",+ debt = Debt.FIVE_MINS+ )++ override fun visitCallExpression(expression: KtCallExpression) {+ super.visitCallExpression(expression)+ val name = expression.calleeExpression?.text ?: return+ val wrapper = SKINNED[name] ?: return+ report(CodeSmell(issue, Entity.from(expression), "Use $wrapper instead of $name."))+ }++ private companion object {+ /** Each raw popup, and the skin-aware wrapper that replaces it. */+ val SKINNED = mapOf(+ "AlertDialog" to "SkinAlertDialog",+ "DropdownMenu" to "SkinDropdownMenu",+ "ExposedDropdownMenu" to "SkinExposedDropdownMenu",+ "Dialog" to "SkinDialog",+ "BasicAlertDialog" to "SkinDialog",+ "Popup" to "SkinDialog or SkinDropdownMenu"+ )+ }+}++/**+ * Blocks `copy(alpha = …)` on the colour-scheme roles that glass skins leave+ * translucent. `copy` replaces the alpha instead of scaling it: harmless on+ * Deep Space's opaque roles, but on Aura it turns a 19% white panel into a 50%+ * one — a pale slab the dim ink beside it disappears into. Use+ * `com.gotcha.ui.theme.fade`, which multiplies.+ */+class GlassRoleAlphaOverride(config: Config) : Rule(config) {+ override val issue = Issue(+ id = "GlassRoleAlphaOverride",+ severity = Severity.Defect,+ description = "copy(alpha = …) replaces a glass skin's translucency instead of scaling it. " ++ "Use .fade(fraction) from com.gotcha.ui.theme.",+ debt = Debt.FIVE_MINS+ )++ override fun visitCallExpression(expression: KtCallExpression) {+ super.visitCallExpression(expression)+ if (expression.calleeExpression?.text != "copy") return+ val args = expression.valueArguments+ val setsAlpha = args.any { it.getArgumentName()?.asName?.asString() == "alpha" } ||+ args.firstOrNull()?.let { !it.isNamed() } == true+ if (!setsAlpha) return+ val qualified = expression.parent as? KtDotQualifiedExpression ?: return+ if (qualified.selectorExpression != expression) return+ val receiver = qualified.receiverExpression+ val role = when (receiver) {+ is KtDotQualifiedExpression -> receiver.selectorExpression?.text+ is KtNameReferenceExpression -> receiver.getReferencedName()+ else -> null+ }+ if (role !in GLASS_ROLES) return+ report(CodeSmell(issue, Entity.from(qualified), "Use $role.fade(…) instead of $role.copy(alpha = …)."))+ }++ private companion object {+ /** The roles Skin.kt leaves translucent; see flattenOnto there. */+ val GLASS_ROLES = setOf("background", "surface", "surfaceVariant", "secondaryContainer")+ }+}+/** Registers the repo's custom detekt rules. */class GotchaRuleSetProvider : RuleSetProvider {override val ruleSetId: String = "gotcha"override fun instance(config: Config): RuleSet = RuleSet(ruleSetId,- listOf(NoRawDebugLog(config))+ listOf(NoRawDebugLog(config), UnskinnedPopup(config), GlassRoleAlphaOverride(config)))}diff --git a/detekt-rules/src/test/kotlin/com/gotcha/detekt/SkinRulesTest.kt b/detekt-rules/src/test/kotlin/com/gotcha/detekt/SkinRulesTest.ktnew file mode 100644index 0000000..1e70207--- /dev/null+++ b/detekt-rules/src/test/kotlin/com/gotcha/detekt/SkinRulesTest.kt@@ -0,0 +1,85 @@+package com.gotcha.detekt++import io.gitlab.arturbosch.detekt.test.TestConfig+import io.gitlab.arturbosch.detekt.test.lint+import org.junit.Assert.assertEquals+import org.junit.Test++class UnskinnedPopupTest {++ private val rule = UnskinnedPopup(TestConfig())++ @Test+ fun `reports raw AlertDialog`() {+ val code = """+ fun f() { AlertDialog(onDismissRequest = {}, confirmButton = {}) }+ """.trimIndent()+ assertEquals(1, rule.lint(code).size)+ }++ @Test+ fun `reports raw DropdownMenu and ExposedDropdownMenu`() {+ val code = """+ fun f() {+ DropdownMenu(expanded = true, onDismissRequest = {}) {}+ ExposedDropdownMenu(expanded = true, onDismissRequest = {}) {}+ }+ """.trimIndent()+ assertEquals(2, rule.lint(code).size)+ }++ @Test+ fun `reports bare and qualified Dialog, BasicAlertDialog and Popup`() {+ val code = """+ fun f() {+ Dialog(onDismissRequest = {}) { Surface {} }+ androidx.compose.ui.window.Dialog(onDismissRequest = {}) { Surface {} }+ BasicAlertDialog(onDismissRequest = {}) {}+ Popup {}+ }+ """.trimIndent()+ assertEquals(4, rule.lint(code).size)+ }++ @Test+ fun `does not report the skin wrappers or the menu box`() {+ val code = """+ fun f() {+ SkinAlertDialog(onDismissRequest = {}, confirmButton = {})+ SkinDropdownMenu(expanded = true, onDismissRequest = {}) {}+ SkinDialog(onDismissRequest = {}) {}+ ExposedDropdownMenuBox(expanded = true, onExpandedChange = {}) {}+ }+ """.trimIndent()+ assertEquals(0, rule.lint(code).size)+ }+}++class GlassRoleAlphaOverrideTest {++ private val rule = GlassRoleAlphaOverride(TestConfig())++ @Test+ fun `reports copy alpha on a glass role`() {+ val code = """+ fun f(scheme: ColorScheme) {+ val a = scheme.surfaceVariant.copy(alpha = 0.5f)+ val b = MaterialTheme.colorScheme.secondaryContainer.copy(0.5f)+ val c = surface.copy(alpha = 0.2f)+ }+ """.trimIndent()+ assertEquals(3, rule.lint(code).size)+ }++ @Test+ fun `does not report opaque roles, fade, or non-alpha copies`() {+ val code = """+ fun f(scheme: ColorScheme) {+ val a = scheme.primary.copy(alpha = 0.18f)+ val b = scheme.surfaceVariant.fade(0.5f)+ val c = scheme.copy(surface = Color.Black)+ }+ """.trimIndent()+ assertEquals(0, rule.lint(code).size)+ }+}