Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 5f372f7

Browse files
committed
Update 1.5.9
1 parent 6b6fc8d commit 5f372f7

19 files changed

Lines changed: 472 additions & 276 deletions

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ android {
1717
applicationId = "com.yangdai.opennote"
1818
minSdk = 29
1919
targetSdk = 35
20-
versionCode = 1580
21-
versionName = "1.5.8"
20+
versionCode = 1590
21+
versionName = "1.5.9"
2222

2323
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2424
vectorDrawables {

app/src/main/java/com/yangdai/opennote/presentation/component/dialog/AudioSelectionDialog.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ fun AudioSelectionDialog(
7979
)
8080
}
8181
},
82-
confirmButton = {},
83-
dismissButton = {}
82+
confirmButton = {}
8483
)
8584
}
8685

app/src/main/java/com/yangdai/opennote/presentation/component/dialog/RatingDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fun RatingDialog(
3232
var rating by remember { mutableIntStateOf(0) }
3333

3434
AlertDialog(
35-
title = { Text(text = stringResource(id = R.string.rate_this_app)) },
35+
title = { Text(text = stringResource(id = R.string.rate_this_app) + " 💖") },
3636
text = {
3737
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
3838
for (i in 1..5) {

app/src/main/java/com/yangdai/opennote/presentation/component/image/FullscreenImageDialog.kt

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,29 +182,19 @@ fun FullscreenImageDialog(
182182
is ImageState.Success -> {
183183
val bitmap = rememberBitmap(
184184
context.applicationContext, state.imagePath, state.isPath
185-
)
186-
187-
bitmap?.let {
185+
)?.also {
188186
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
189-
if (bitmap.hasGainmap()) {
187+
if (it.hasGainmap()) {
190188
isHdr = true
191189
activity?.window?.colorMode = ActivityInfo.COLOR_MODE_HDR
192190
dialogWindow?.colorMode = ActivityInfo.COLOR_MODE_HDR
193191
}
194192
}
195193
}
196194

197-
DisposableEffect(Unit) {
198-
onDispose {
199-
activity?.window?.colorMode = ActivityInfo.COLOR_MODE_DEFAULT
200-
dialogWindow?.colorMode = ActivityInfo.COLOR_MODE_DEFAULT
201-
}
202-
}
203-
204195
val painter = remember(bitmap) {
205-
bitmap?.asImageBitmap()?.let {
206-
BitmapPainter(it)
207-
} ?: ColorPainter(Color.Transparent)
196+
bitmap?.asImageBitmap()?.let { BitmapPainter(it) }
197+
?: ColorPainter(Color.Transparent)
208198
}
209199
ZoomableImage(painter = painter, contentDescription = null)
210200
if (isHdr) {
@@ -236,9 +226,7 @@ fun FullscreenImageDialog(
236226

237227
is ImageState.Error -> onDismiss()
238228

239-
is ImageState.Empty -> {
240-
// 显示占位内容
241-
}
229+
is ImageState.Empty -> {}
242230
}
243231
FilledTonalIconButton(
244232
onClick = onDismiss,

app/src/main/java/com/yangdai/opennote/presentation/component/login/LogoText.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,28 @@ import kotlinx.coroutines.delay
2020
@Composable
2121
fun LogoText() {
2222

23-
val animationDurationMillis = 2500
24-
val animationDelayMillis = 5000L
23+
val duration = 2500
24+
val delay = 5000L
2525

26-
val animatable = remember { Animatable(-1f) }
26+
val offsetAnimator = remember { Animatable(-1f) }
2727

28-
AnimatedGradientText(text = stringResource(id = R.string.app_name), offsetX = animatable.value)
28+
AnimatedGradientText(
29+
text = stringResource(id = R.string.app_name),
30+
offsetX = offsetAnimator.value
31+
)
2932

3033
LaunchedEffect(Unit) {
3134
while (true) {
32-
animatable.stop()
33-
animatable.snapTo(-1f)
34-
animatable.animateTo(
35+
offsetAnimator.stop()
36+
offsetAnimator.snapTo(-1f)
37+
offsetAnimator.animateTo(
3538
targetValue = 0f,
3639
animationSpec = tween(
37-
durationMillis = animationDurationMillis,
40+
durationMillis = duration,
3841
easing = CubicBezierEasing(0.3f, 0f, 0.4f, 1f),
3942
)
4043
)
41-
delay(animationDelayMillis)
44+
delay(delay)
4245
}
4346
}
4447
}

app/src/main/java/com/yangdai/opennote/presentation/component/note/LiteModeMutators.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ fun TextFieldValue.moveCursorDown(): TextFieldValue {
4848
nextLineEnd - (nextLineStart + 1)
4949
}
5050

51-
val offsetInCurrentLine = selection.min - if (currentLineStart == -1) 0 else currentLineStart + 1
51+
val offsetInCurrentLine =
52+
selection.min - if (currentLineStart == -1) 0 else currentLineStart + 1
5253
val offsetInNextLine = offsetInCurrentLine.coerceAtMost(nextLineLength)
5354

5455
return copy(
@@ -114,12 +115,12 @@ fun TextFieldValue.tab(): TextFieldValue {
114115

115116
val initialSelection = selection
116117

117-
val newText = text.replaceRange(lineStart, lineStart, "\t")
118+
val newText = text.replaceRange(lineStart, lineStart, " ") // 4 spaces
118119
return TextFieldValue(
119120
text = newText,
120121
selection = TextRange(
121-
initialSelection.min + "\t".length,
122-
initialSelection.max + "\t".length
122+
initialSelection.min + 4,
123+
initialSelection.max + 4
123124
)
124125
)
125126
}
@@ -132,16 +133,16 @@ fun TextFieldValue.unTab(): TextFieldValue {
132133
?.let { it + 1 }
133134
?: 0
134135

135-
val tabIndex = text.indexOf('\t', lineStart)
136+
val tabIndex = text.indexOf(" ", lineStart)
136137
val initialSelection = selection
137138

138139
return if (tabIndex != -1 && tabIndex < selection.min) {
139-
val newText = text.replaceRange(tabIndex, tabIndex + 1, "")
140+
val newText = text.replaceRange(tabIndex, tabIndex + 4, "")
140141
TextFieldValue(
141142
text = newText,
142143
selection = TextRange(
143-
initialSelection.min - 1,
144-
initialSelection.max - 1
144+
initialSelection.min - 4,
145+
initialSelection.max - 4
145146
)
146147
)
147148
} else {

app/src/main/java/com/yangdai/opennote/presentation/component/note/LiteTextField.kt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import androidx.compose.ui.input.key.onPreviewKeyEvent
4040
import androidx.compose.ui.input.key.type
4141
import androidx.compose.ui.res.stringResource
4242
import androidx.compose.ui.text.TextLayoutResult
43+
import androidx.compose.ui.text.TextRange
4344
import androidx.compose.ui.text.input.ImeAction
4445
import androidx.compose.ui.text.input.KeyboardCapitalization
4546
import androidx.compose.ui.text.input.KeyboardType
@@ -244,6 +245,84 @@ fun LiteTextField(
244245
true
245246
}
246247

248+
Key.Enter, Key.NumPadEnter -> {
249+
val currentText = textFieldValue.text
250+
val selection = textFieldValue.selection
251+
252+
val currentLineStart = currentText.lastIndexOf(
253+
'\n',
254+
(selection.start - 1).coerceIn(0, currentText.length)
255+
).let {
256+
if (it == -1) 0 else it + 1
257+
}
258+
259+
val currentLineEnd =
260+
currentText.indexOf('\n', selection.start).let {
261+
if (it == -1) currentText.length else it
262+
}
263+
264+
if (currentLineStart >= currentLineEnd) {
265+
applyChange(textFieldValue.add("\n"))
266+
return@onPreviewKeyEvent true
267+
}
268+
269+
val currentLine =
270+
currentText.substring(currentLineStart, currentLineEnd)
271+
val trimmedLine = currentLine.trim()
272+
273+
val indentation = currentLine.takeWhile { it.isWhitespace() }
274+
275+
if (selection.start == currentLineEnd &&
276+
(trimmedLine == "- [ ]" || trimmedLine == "-" || trimmedLine == "*" || trimmedLine == "+"
277+
|| trimmedLine.matches(Regex("^\\d+\\.$")))
278+
) {
279+
val newText = StringBuilder(currentText)
280+
.delete(currentLineStart, currentLineEnd)
281+
.toString()
282+
283+
applyChange(
284+
textFieldValue.copy(
285+
text = newText,
286+
selection = TextRange(currentLineStart)
287+
)
288+
)
289+
return@onPreviewKeyEvent true
290+
}
291+
292+
val newLinePrefix = when {
293+
trimmedLine.startsWith("- [ ] ") || trimmedLine.startsWith("- [x] ") -> "- [ ] "
294+
trimmedLine.matches(Regex("^\\d+\\.\\s.*")) -> {
295+
val nextNumber =
296+
trimmedLine.substringBefore(".").toIntOrNull()
297+
?.plus(1) ?: 1
298+
"$nextNumber. "
299+
}
300+
301+
trimmedLine.startsWith("- ") -> "- "
302+
trimmedLine.startsWith("* ") -> "* "
303+
trimmedLine.startsWith("+ ") -> "+ "
304+
else -> ""
305+
}
306+
307+
val newText = StringBuilder(currentText)
308+
.insert(
309+
selection.start,
310+
"\n" + (if (newLinePrefix.isNotEmpty()) indentation + newLinePrefix else "")
311+
)
312+
.toString()
313+
314+
val newCursorPosition = selection.start + 1 +
315+
(if (newLinePrefix.isNotEmpty()) indentation.length + newLinePrefix.length else 0)
316+
317+
applyChange(
318+
textFieldValue.copy(
319+
text = newText,
320+
selection = TextRange(newCursorPosition)
321+
)
322+
)
323+
true
324+
}
325+
247326
else -> false
248327
}
249328
}

0 commit comments

Comments
 (0)