From 203d0a510d0957574f20677f162828f2cc7fb54c Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 02:53:45 +0530 Subject: [PATCH 1/2] fix: close the gap above the Categories & rules footer The 12dp spacer that separates rule sections was also drawn after the last one, where it stacked with SettingsFooter's own 6dp top gap. It is now drawn between sections only; the note sits 55px under the last section instead of 87px on the 420dpi emulator. --- .../messages/ui/InboxSettingsScreen.kt | 10 +++-- .../messages/ui/InboxRulesFooterGapTest.kt | 44 +++++++++++++++++++ scripts | 2 +- 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 app/src/test/java/com/anindra/messages/ui/InboxRulesFooterGapTest.kt diff --git a/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt b/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt index a642c4ec..5e07a9c0 100644 --- a/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt @@ -446,14 +446,18 @@ internal fun InboxCategoryRulesScreen( Spacer(Modifier.height(SettingsLayout.GROUP_GAP)) // Nothing is drawn until the table has been read once: an empty // "no rules yet" under every tab was mistaken for rules going missing. - val byCategory = remember(rules) { rules?.let { InboxCategoryRules.group(it) } } - byCategory?.forEach { (category, inTab) -> + val sections = remember(rules) { + rules?.let { InboxCategoryRules.group(it).entries.toList() } + } + sections?.forEachIndexed { index, (category, inTab) -> RuleSection( category = category, rules = inTab, onDelete = { vm.deleteCategoryRule(it) } ) - Spacer(Modifier.height(12.dp)) + // Only between sections: a spacer after the last one stacked + // with the footer's own gap and left a band above the note. + if (index != sections.lastIndex) Spacer(Modifier.height(12.dp)) } SettingsFooter(stringResource(R.string.settings_inbox_rules_footer)) } diff --git a/app/src/test/java/com/anindra/messages/ui/InboxRulesFooterGapTest.kt b/app/src/test/java/com/anindra/messages/ui/InboxRulesFooterGapTest.kt new file mode 100644 index 00000000..19ae9a7f --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/InboxRulesFooterGapTest.kt @@ -0,0 +1,44 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +/** + * The Categories & rules footer used to sit under an unconditional 12dp spacer + * that was meant to separate sections; after the last section it stacked with + * the footer's own 6dp gap and left a band above the note. The spacer is now + * conditional, which is invisible to a compiler and easy to reintroduce. + */ +class InboxRulesFooterGapTest { + + private val screen: String by lazy { + val root = generateSequence(File("").absoluteFile) { it.parentFile } + .firstOrNull { File(it, "gradle/libs.versions.toml").isFile } + ?: error("repo root not found") + File(root, "app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt").readText() + } + + @Test + fun theSectionSpacerIsSkippedAfterTheLastSection() { + assertTrue( + "the rules screen no longer indexes its sections", + Regex("""sections\?\.forEachIndexed \{ index, \(category, inTab\) ->""") + .containsMatchIn(screen) + ) + assertTrue( + "the spacer after a rule section is unconditional again", + Regex("""if \(index != sections\.lastIndex\) Spacer\(Modifier\.height\(12\.dp\)\)""") + .containsMatchIn(screen) + ) + } + + @Test + fun theFooterStillFollowsTheSections() { + assertTrue( + "the rules footer is missing", + Regex("""if \(index != sections\.lastIndex\)[\s\S]{0,120}SettingsFooter\(stringResource\(R\.string\.settings_inbox_rules_footer\)\)""") + .containsMatchIn(screen) + ) + } +} diff --git a/scripts b/scripts index 8fa0729c..fe4cd766 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 8fa0729c98ae86f82346c99036c01db6bb51169b +Subproject commit fe4cd76658ad2a47e94374fc30155c6a17a3671b From fc3c6b356dd9899f4d936c9d852027f10ae524ee Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 15:51:04 +0530 Subject: [PATCH 2/2] test: anchor the rules first-read check on the null guard The footer fix wraps the grouped rules in `.entries.toList()` so each section knows its index; noSectionIsDrawnBeforeTheRulesArrive pinned the exact expression and went red. The check now matches the guarded `rules?.let { InboxCategoryRules.group(it)` and still refuses an unguarded `group(rules)`. --- .../java/com/anindra/messages/ui/RulesFirstReadTest.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt b/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt index f7b027e1..483d09d6 100644 --- a/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt @@ -44,13 +44,16 @@ class RulesFirstReadTest { @Test fun noSectionIsDrawnBeforeTheRulesArrive() { + // Anchored on the null-guarded grouping, not on the exact shape the + // sections are later turned into (the footer fix wraps it in + // `.entries.toList()`); renaming that should not fail this test. assertTrue( "the sections are drawn from a possibly-null answer", - screen.contains("rules?.let { InboxCategoryRules.group(it) }") + Regex("""rules\?\.let \{\s*InboxCategoryRules\.group\(it\)""").containsMatchIn(screen) ) assertFalse( "the sections fall back to an empty grouping before the read", - screen.contains("InboxCategoryRules.group(rules)") + Regex("""InboxCategoryRules\.group\(rules\)""").containsMatchIn(screen) ) } }