Skip to content

Commit c8e5b63

Browse files
committed
feat: insert local date and time in notes
1 parent 47504d5 commit c8e5b63

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111

1212
- Search text can be turned into a new note named after the query in the selected category.
1313
- The Markdown editor toolbar can insert the local date at the cursor.
14+
- The Markdown editor toolbar can insert the local date and time at the cursor.
1415
- The Markdown editor's long-press menu can now turn a clipboard web URL into a Markdown link whose
1516
label is fetched from the page title.
1617
- Note view now provides an information dialog with modified time, Markdown size, text statistics,

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
4444
import com.nextcloud.android.sso.model.SingleSignOnAccount
4545
import java.io.IOException
4646
import java.time.LocalDateTime
47+
import java.time.format.DateTimeFormatter
4748
import kotlinx.coroutines.CompletableDeferred
4849
import kotlinx.coroutines.flow.first
4950
import kotlinx.coroutines.runBlocking
@@ -1672,6 +1673,32 @@ class AppLaunchTest {
16721673
onView(withId(R.id.markdown_editor)).check(matches(withText("before after")))
16731674
}
16741675

1676+
@Test
1677+
fun toolbarInsertsLocalDateTimeAtTheSelection() {
1678+
importAccount("alice", "Existing note", "etag-1", 10)
1679+
composeRule.onNodeWithText("Existing note").performClick()
1680+
composeRule.enterEditMode()
1681+
onView(withId(R.id.markdown_editor)).perform(click(), replaceText("before after"))
1682+
composeRule.runOnUiThread {
1683+
composeRule.activity.findViewById<org.qownnotes.mobile.markdown.MarkdownEditText>(
1684+
R.id.markdown_editor
1685+
).setSelection(7, 12)
1686+
}
1687+
1688+
val before = LocalDateTime.now()
1689+
composeRule.onNodeWithTag("insert-datetime").performScrollTo().performClick()
1690+
val after = LocalDateTime.now()
1691+
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
1692+
composeRule.waitUntil(timeoutMillis = 10_000) {
1693+
val text = composeRule.runOnIdle {
1694+
composeRule.activity.findViewById<TextView>(R.id.markdown_editor).text.toString()
1695+
}
1696+
text == "before ${before.format(formatter)}" ||
1697+
text == "before ${after.format(formatter)}"
1698+
}
1699+
onView(withId(R.id.markdown_editor)).check(matches(hasFocus()))
1700+
}
1701+
16751702
@Test
16761703
fun toolbarCreatesListAndCheckboxListItems() {
16771704
importAccount("alice", "Existing note", "etag-1", 10)

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import androidx.compose.material.icons.filled.Bookmarks
6565
import androidx.compose.material.icons.filled.Checklist
6666
import androidx.compose.material.icons.filled.Close
6767
import androidx.compose.material.icons.filled.Code
68+
import androidx.compose.material.icons.filled.DateRange
6869
import androidx.compose.material.icons.filled.Delete
6970
import androidx.compose.material.icons.filled.Done
7071
import androidx.compose.material.icons.filled.Edit
@@ -83,8 +84,8 @@ import androidx.compose.material.icons.filled.Star
8384
import androidx.compose.material.icons.filled.StrikethroughS
8485
import androidx.compose.material.icons.filled.TextDecrease
8586
import androidx.compose.material.icons.filled.TextIncrease
86-
import androidx.compose.material.icons.filled.Today
8787
import androidx.compose.material.icons.filled.Title
88+
import androidx.compose.material.icons.filled.Today
8889
import androidx.compose.material3.AlertDialog
8990
import androidx.compose.material3.Button
9091
import androidx.compose.material3.Checkbox
@@ -2984,6 +2985,19 @@ private fun NoteDetailScreen(
29842985
editor?.focusForInput()
29852986
}
29862987
)
2988+
ActionIconButton(
2989+
icon = Icons.Filled.DateRange,
2990+
description = "Insert date and time",
2991+
testTag = "insert-datetime",
2992+
onClick = {
2993+
editor?.insertText(
2994+
LocalDateTime.now().format(
2995+
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
2996+
)
2997+
)
2998+
editor?.focusForInput()
2999+
}
3000+
)
29873001
FormatButton(
29883002
Icons.Filled.Title,
29893003
MarkdownFormatAction.HEADING,

0 commit comments

Comments
 (0)