Skip to content

Commit 36e2a1e

Browse files
committed
feat: configure the formats inserted by the date tools
Add a Date formats dialog to the Notes settings. The insert date and insert date and time tools each get their own pattern, chosen from common formats such as dd.MM.yy or entered as a custom pattern with a live preview, tappable building blocks, and warnings for the week-based year and day-of-year letters. Unusable patterns are never stored, and the defaults stay unchanged. The toolbar help shows the chosen formats.
1 parent bdf7b5d commit 36e2a1e

28 files changed

Lines changed: 1064 additions & 38 deletions

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ zero-based increasing release counter within the month. See [the release guide](
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Choose the formats that the editor's **Insert date** and **Insert date and time** tools use in
14+
the new **Date formats** settings. Pick a common format such as `dd.MM.yy`, `dd.MM.yyyy`, or
15+
`MM/dd/yyyy` with a live preview, or enter your own pattern with tappable building blocks.
16+
Mistakes like `YY` for the week-based year are pointed out. The default formats are unchanged.
17+
1118
## [26.11.2] - 2026-11-13
1219

1320
### Added

‎app/src/androidTest/kotlin/org/qownnotes/mobile/AppLaunchTest.kt‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import org.qownnotes.mobile.core.DeckBoard
7878
import org.qownnotes.mobile.core.DeckCardDraft
7979
import org.qownnotes.mobile.core.DeckStack
8080
import org.qownnotes.mobile.core.DeckStackTarget
81+
import org.qownnotes.mobile.core.InsertDateFormats
8182
import org.qownnotes.mobile.core.Note
8283
import org.qownnotes.mobile.core.NoteFolderScope
8384
import org.qownnotes.mobile.core.NoteNames
@@ -2702,6 +2703,42 @@ class AppLaunchTest {
27022703
onView(withId(R.id.markdown_editor)).check(matches(hasFocus()))
27032704
}
27042705

2706+
@Test
2707+
fun settingsChooseTheFormatsInsertedByTheDateTools() {
2708+
importAccount("alice", "Existing note", "etag-1", 10)
2709+
listAction("settings")
2710+
composeRule.onNodeWithTag("open-insert-date-formats").performScrollTo().performClick()
2711+
composeRule.onNodeWithTag("insert-date-formats-dialog").assertIsDisplayed()
2712+
composeRule.onNodeWithTag("insert-date-preset-dd.MM.yy").performScrollTo().performClick()
2713+
composeRule.onNodeWithTag("insert-date-preview-pattern").assertTextEquals("dd.MM.yy")
2714+
2715+
composeRule.onNodeWithTag("insert-date-kind-datetime").performClick()
2716+
composeRule.onNodeWithTag("insert-date-custom").performScrollTo().performClick()
2717+
composeRule.onNodeWithTag("insert-date-custom-pattern").performTextReplacement("YYYY {")
2718+
composeRule.onNodeWithTag("insert-date-custom-supporting", useUnmergedTree = true)
2719+
.assertTextEquals("This pattern cannot be used")
2720+
composeRule.onNodeWithTag("insert-date-pitfall-week_based_year").assertExists()
2721+
composeRule.onNodeWithTag("insert-date-custom-pattern")
2722+
.performTextReplacement("'at' HH 'h'")
2723+
composeRule.onNodeWithTag("insert-date-preview-pattern").assertTextEquals("'at' HH 'h'")
2724+
composeRule.onNodeWithTag("close-insert-date-formats").performClick()
2725+
composeRule.onNodeWithTag("close-settings").performClick()
2726+
assertEquals(
2727+
InsertDateFormats(date = "dd.MM.yy", dateTime = "'at' HH 'h'"),
2728+
application.component.settings.insertDateFormats.value
2729+
)
2730+
2731+
composeRule.onNodeWithText("Existing note").performClick()
2732+
composeRule.enterEditMode()
2733+
onView(withId(R.id.markdown_editor)).perform(click(), replaceText(""))
2734+
val today = LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd.MM.yy"))
2735+
composeRule.onNodeWithTag("insert-date").performScrollTo().performClick()
2736+
awaitEditorText(today)
2737+
composeRule.onNodeWithTag("insert-datetime").performScrollTo().performClick()
2738+
awaitEditorText("at ")
2739+
awaitEditorText(" h")
2740+
}
2741+
27052742
@Test
27062743
fun enterRemovesSingleTrailingSpaceAndPreservesMarkdownHardBreaks() {
27072744
importAccount("alice", "Existing note", "etag-1", 10, "text ")

‎app/src/androidTest/kotlin/org/qownnotes/mobile/TestQOwnNotesApplication.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.qownnotes.mobile.core.DeckCardDraft
2323
import org.qownnotes.mobile.core.DeckCardLink
2424
import org.qownnotes.mobile.core.DeckStackTarget
2525
import org.qownnotes.mobile.core.ImageShrinkSettings
26+
import org.qownnotes.mobile.core.InsertDateFormats
2627
import org.qownnotes.mobile.core.Note
2728
import org.qownnotes.mobile.core.NoteArchiveBackend
2829
import org.qownnotes.mobile.core.NoteBackend
@@ -119,6 +120,7 @@ class TestQOwnNotesApplication : QOwnNotesApplication() {
119120
component.settings.setAppearance(AppAppearance())
120121
component.settings.setPhotoResolution(PhotoResolution())
121122
component.settings.setImageShrink(ImageShrinkSettings())
123+
component.settings.setInsertDateFormats(InsertDateFormats())
122124
component.settings.resetDeckLinkOpening()
123125
component.settings.resetAudioLinkOpening()
124126
fakeBackend.reset()

‎app/src/main/kotlin/org/qownnotes/mobile/AppSettings.kt‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.qownnotes.mobile.core.DeckStackTarget
99
import org.qownnotes.mobile.core.ImageOrigin
1010
import org.qownnotes.mobile.core.ImageShrinkSettings
1111
import org.qownnotes.mobile.core.ImageShrinking
12+
import org.qownnotes.mobile.core.InsertDateFormats
1213
import org.qownnotes.mobile.core.NoteCategoryScope
1314
import org.qownnotes.mobile.core.NoteFolderScope
1415
import org.qownnotes.mobile.core.PhotoResolution
@@ -162,6 +163,28 @@ class AppSettings(context: Context, name: String = PREFERENCES) {
162163
mutableRemoveEditedTrailingSpaces.value = enabled
163164
}
164165

166+
private val mutableInsertDateFormats = MutableStateFlow(
167+
InsertDateFormats().let { defaults ->
168+
InsertDateFormats(
169+
date = preferences.getString(INSERT_DATE_FORMAT, null) ?: defaults.date,
170+
dateTime = preferences.getString(INSERT_DATE_TIME_FORMAT, null)
171+
?: defaults.dateTime
172+
)
173+
}
174+
)
175+
176+
/** Patterns of the editor's insert-date and insert-date-and-time actions. */
177+
val insertDateFormats: StateFlow<InsertDateFormats> = mutableInsertDateFormats.asStateFlow()
178+
179+
fun setInsertDateFormats(formats: InsertDateFormats) {
180+
if (formats == mutableInsertDateFormats.value) return
181+
preferences.edit()
182+
.putString(INSERT_DATE_FORMAT, formats.date)
183+
.putString(INSERT_DATE_TIME_FORMAT, formats.dateTime)
184+
.apply()
185+
mutableInsertDateFormats.value = formats
186+
}
187+
165188
private val mutableEditorToolbarHintDismissed =
166189
MutableStateFlow(preferences.getBoolean(EDITOR_TOOLBAR_HINT_DISMISSED, false))
167190

@@ -487,6 +510,8 @@ class AppSettings(context: Context, name: String = PREFERENCES) {
487510
const val SHOW_EDITOR_TOOLBAR_LABELS = "showEditorToolbarLabels"
488511
const val REMOVE_EDITED_TRAILING_SPACES = "removeEditedTrailingSpaces"
489512
const val EDITOR_TOOLBAR_HINT_DISMISSED = "editorToolbarHintDismissed"
513+
const val INSERT_DATE_FORMAT = "insertDateFormat"
514+
const val INSERT_DATE_TIME_FORMAT = "insertDateTimeFormat"
490515
const val HEADER_COLOR = "headerColor"
491516
const val NOTE_BACKGROUND_COLOR = "noteBackgroundColor"
492517
const val HIGHLIGHT_CATEGORIES = "highlightCategories"

‎app/src/main/kotlin/org/qownnotes/mobile/EditorToolbar.kt‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import androidx.compose.ui.graphics.Path
7575
import androidx.compose.ui.graphics.SolidColor
7676
import androidx.compose.ui.graphics.vector.ImageVector
7777
import androidx.compose.ui.graphics.vector.path
78+
import androidx.compose.ui.platform.LocalConfiguration
7879
import androidx.compose.ui.platform.testTag
7980
import androidx.compose.ui.res.stringResource
8081
import androidx.compose.ui.semantics.Role
@@ -85,6 +86,9 @@ import androidx.compose.ui.text.font.FontWeight
8586
import androidx.compose.ui.text.style.TextOverflow
8687
import androidx.compose.ui.unit.dp
8788
import androidx.compose.ui.window.PopupProperties
89+
import java.time.ZonedDateTime
90+
import org.qownnotes.mobile.core.InsertDateFormats
91+
import org.qownnotes.mobile.core.InsertDateKind
8892
import org.qownnotes.mobile.markdown.MAX_HEADING_LEVEL
8993

9094
/** Related editor tools, shown together and separated from the other groups. */
@@ -601,9 +605,12 @@ internal fun EditorToolbarHelpDialog(
601605
cameraAvailable: Boolean,
602606
showLabels: Boolean,
603607
onShowLabelsChange: (Boolean) -> Unit,
608+
insertDateFormats: InsertDateFormats,
604609
onDismiss: () -> Unit
605610
) {
606611
val tools = availableEditorTools(deckAvailable, cameraAvailable)
612+
val now = remember { ZonedDateTime.now() }
613+
val locale = LocalConfiguration.current.locales[0]
607614
AlertDialog(
608615
onDismissRequest = onDismiss,
609616
icon = { Icon(Icons.AutoMirrored.Filled.HelpOutline, contentDescription = null) },
@@ -627,7 +634,21 @@ internal fun EditorToolbarHelpDialog(
627634
tools.groupBy { it.group }.forEach { (group, groupTools) ->
628635
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))
629636
SettingsSectionHeader(stringResource(group.title))
630-
groupTools.forEach { tool -> ToolHelpRow(tool) }
637+
groupTools.forEach { tool ->
638+
val example = when (tool) {
639+
EditorTool.DATE -> InsertDateKind.DATE
640+
EditorTool.DATE_TIME -> InsertDateKind.DATE_TIME
641+
else -> null
642+
}?.let { insertDateFormats.format(it, now, locale) }
643+
ToolHelpRow(
644+
tool,
645+
if (example == null) {
646+
stringResource(tool.help)
647+
} else {
648+
stringResource(tool.help, example)
649+
}
650+
)
651+
}
631652
}
632653
}
633654
},
@@ -641,7 +662,7 @@ internal fun EditorToolbarHelpDialog(
641662
}
642663

643664
@Composable
644-
private fun ToolHelpRow(tool: EditorTool) {
665+
private fun ToolHelpRow(tool: EditorTool, help: String) {
645666
Row(
646667
horizontalArrangement = Arrangement.spacedBy(16.dp),
647668
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp)
@@ -656,7 +677,7 @@ private fun ToolHelpRow(tool: EditorTool) {
656677
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
657678
Text(stringResource(tool.description), style = MaterialTheme.typography.bodyLarge)
658679
Text(
659-
stringResource(tool.help),
680+
help,
660681
style = MaterialTheme.typography.bodySmall,
661682
color = MaterialTheme.colorScheme.onSurfaceVariant
662683
)

0 commit comments

Comments
 (0)