Merge branch 'vitorpamplona:main' into kmp-completeness

This commit is contained in:
KotlinGeekDev
2026-03-24 13:27:40 +01:00
committed by GitHub
27 changed files with 309 additions and 65 deletions
+2 -2
View File
@@ -745,8 +745,8 @@ android {
applicationId = "com.vitorpamplona.amethyst" applicationId = "com.vitorpamplona.amethyst"
minSdk = 26 // Android 8.0 (Oreo) minSdk = 26 // Android 8.0 (Oreo)
targetSdk = 36 // Android 15 targetSdk = 36 // Android 15
versionCode = 433 versionCode = 434
versionName = "1.06.0" versionName = "1.06.1"
vectorDrawables { vectorDrawables {
useSupportLibrary = true useSupportLibrary = true
@@ -7,7 +7,7 @@ description: Use when comparing Android strings.xml locale files to find untrans
## Overview ## Overview
Extract string resource keys from the default `values/strings.xml` that are absent in a target locale's `strings.xml`, excluding non-translatable entries. Outputs a table ready for translation. Extract string resource keys from the default `values/strings.xml` that are absent in a target locale's `strings.xml`, excluding non-translatable entries. Outputs missing keys and offers to translate them.
## When to Use ## When to Use
@@ -15,6 +15,17 @@ Extract string resource keys from the default `values/strings.xml` that are abse
- Preparing a batch of strings for a translator - Preparing a batch of strings for a translator
- Checking translation coverage after adding new features - Checking translation coverage after adding new features
## Target Locales
The default set of locales (unless the user specifies otherwise):
| Locale | Language | Directory |
|--------|----------|-----------|
| `cs-rCZ` | Czech | `values-cs-rCZ` |
| `pt-rBR` | Brazilian Portuguese | `values-pt-rBR` |
| `sv-rSE` | Swedish | `values-sv-rSE` |
| `de-rDE` | German | `values-de-rDE` |
## Technique ## Technique
### 1. Identify files ### 1. Identify files
@@ -24,11 +35,9 @@ Default: amethyst/src/main/res/values/strings.xml
Target: amethyst/src/main/res/values-<locale>/strings.xml Target: amethyst/src/main/res/values-<locale>/strings.xml
``` ```
Default locale: `cs-rCZ` if none specified. User may override (e.g., `pt-rBR`, `ja`). ### 2. Find missing keys using cs-rCZ as reference
### 2. Extract and diff keys Always diff against `cs-rCZ` first — it is the most complete locale and serves as the reference. Any keys missing in `cs-rCZ` will also be missing in the other target locales.
Use a single bash pipeline to extract translatable keys from both files and diff them:
```bash ```bash
# Extract translatable keys from default (exclude translatable="false") # Extract translatable keys from default (exclude translatable="false")
@@ -36,11 +45,11 @@ comm -23 \
<(grep '<string name=' amethyst/src/main/res/values/strings.xml \ <(grep '<string name=' amethyst/src/main/res/values/strings.xml \
| grep -v 'translatable="false"' \ | grep -v 'translatable="false"' \
| sed 's/.*name="\([^"]*\)".*/\1/' | sort) \ | sed 's/.*name="\([^"]*\)".*/\1/' | sort) \
<(grep '<string name=' amethyst/src/main/res/values-<LOCALE>/strings.xml \ <(grep '<string name=' amethyst/src/main/res/values-cs-rCZ/strings.xml \
| sed 's/.*name="\([^"]*\)".*/\1/' | sort) | sed 's/.*name="\([^"]*\)".*/\1/' | sort)
``` ```
This gives the list of missing key names. This gives the list of missing key names. Do NOT diff each locale separately — assume the same keys are missing in all target locales.
### 3. Get English values for missing keys ### 3. Get English values for missing keys
@@ -54,13 +63,13 @@ done < <(comm -23 \
<(grep '<string name=' amethyst/src/main/res/values/strings.xml \ <(grep '<string name=' amethyst/src/main/res/values/strings.xml \
| grep -v 'translatable="false"' \ | grep -v 'translatable="false"' \
| sed 's/.*name="\([^"]*\)".*/\1/' | sort) \ | sed 's/.*name="\([^"]*\)".*/\1/' | sort) \
<(grep '<string name=' amethyst/src/main/res/values-<LOCALE>/strings.xml \ <(grep '<string name=' amethyst/src/main/res/values-cs-rCZ/strings.xml \
| sed 's/.*name="\([^"]*\)".*/\1/' | sort)) | sed 's/.*name="\([^"]*\)".*/\1/' | sort))
``` ```
### 4. Present results ### 4. Present results and ask to translate
Output the missing entries as raw XML resource lines (copy-paste ready for the locale file): Output the missing entries as raw XML resource lines (copy-paste ready):
```xml ```xml
<string name="attestation_valid">Valid</string> <string name="attestation_valid">Valid</string>
@@ -70,8 +79,18 @@ Output the missing entries as raw XML resource lines (copy-paste ready for the l
Also check `<string-array>` and `<plurals>` tags using the same approach if the project uses them. Also check `<string-array>` and `<plurals>` tags using the same approach if the project uses them.
**Then ask the user:** "Would you like me to translate these missing strings into [list of target locales]?"
### 5. Adding translations (if approved)
When adding translated strings to locale files:
- **Append new strings at the bottom** of the file, just before the closing `</resources>` tag.
- Do NOT try to insert them in alphabetical or matching order — a separate process handles ordering.
## Common Mistakes ## Common Mistakes
- **Forgetting `translatable="false"`** — these should never appear in locale files - **Forgetting `translatable="false"`** — these should never appear in locale files
- **Not checking string-arrays/plurals** — only checking `<string>` misses other resource types - **Not checking string-arrays/plurals** — only checking `<string>` misses other resource types
- **Modifying files**this is a read-only research task unless the user asks to add entries - **Diffing each locale separately** — only diff against `cs-rCZ`; assume the same keys are missing everywhere
- **Inserting strings in a specific position** — always append at the bottom; ordering is handled separately
+3 -3
View File
@@ -7,7 +7,7 @@ description: Integration guide for using the Quartz Nostr KMP library in externa
Reference for integrating `com.vitorpamplona.quartz:quartz` into external Nostr KMP projects. Reference for integrating `com.vitorpamplona.quartz:quartz` into external Nostr KMP projects.
**Published artifact**: `com.vitorpamplona.quartz:quartz:1.06.0` (Maven Central) **Published artifact**: `com.vitorpamplona.quartz:quartz:1.06.1` (Maven Central)
**Targets**: JVM 21+, Android (minSdk 21+), iOS (XCFramework `quartz-kmpKit`) **Targets**: JVM 21+, Android (minSdk 21+), iOS (XCFramework `quartz-kmpKit`)
**License**: MIT **License**: MIT
@@ -19,7 +19,7 @@ Reference for integrating `com.vitorpamplona.quartz:quartz` into external Nostr
```toml ```toml
[versions] [versions]
quartz = "1.06.0" quartz = "1.06.1"
[libraries] [libraries]
quartz = { module = "com.vitorpamplona.quartz:quartz", version.ref = "quartz" } quartz = { module = "com.vitorpamplona.quartz:quartz", version.ref = "quartz" }
@@ -41,7 +41,7 @@ kotlin {
```kotlin ```kotlin
dependencies { dependencies {
implementation("com.vitorpamplona.quartz:quartz:1.06.0") implementation("com.vitorpamplona.quartz:quartz:1.06.1")
} }
``` ```
@@ -3,7 +3,7 @@
## Current version ## Current version
``` ```
com.vitorpamplona.quartz:quartz:1.06.0 com.vitorpamplona.quartz:quartz:1.06.1
``` ```
Check latest: https://central.sonatype.com/artifact/com.vitorpamplona.quartz/quartz Check latest: https://central.sonatype.com/artifact/com.vitorpamplona.quartz/quartz
@@ -16,7 +16,7 @@ Check latest: https://central.sonatype.com/artifact/com.vitorpamplona.quartz/qua
```toml ```toml
[versions] [versions]
quartz = "1.06.0" quartz = "1.06.1"
[libraries] [libraries]
quartz = { module = "com.vitorpamplona.quartz:quartz", version.ref = "quartz" } quartz = { module = "com.vitorpamplona.quartz:quartz", version.ref = "quartz" }
@@ -55,7 +55,7 @@ kotlin {
```kotlin ```kotlin
// build.gradle.kts (app module) // build.gradle.kts (app module)
dependencies { dependencies {
implementation("com.vitorpamplona.quartz:quartz:1.06.0") implementation("com.vitorpamplona.quartz:quartz:1.06.1")
} }
``` ```
@@ -70,7 +70,7 @@ plugins {
} }
dependencies { dependencies {
implementation("com.vitorpamplona.quartz:quartz:1.06.0") implementation("com.vitorpamplona.quartz:quartz:1.06.1")
// JNA needed for libsodium (NIP-44) on JVM // JNA needed for libsodium (NIP-44) on JVM
implementation("net.java.dev.jna:jna:5.18.1") implementation("net.java.dev.jna:jna:5.18.1")
} }
+1 -1
View File
@@ -17,7 +17,7 @@ The Quartz library was successfully converted from Android-only to full KMP supp
## Current artifact ## Current artifact
``` ```
com.vitorpamplona.quartz:quartz:1.06.0 com.vitorpamplona.quartz:quartz:1.06.1
``` ```
See `.claude/skills/quartz-integration/SKILL.md` for full integration guide. See `.claude/skills/quartz-integration/SKILL.md` for full integration guide.
+1 -1
View File
@@ -55,7 +55,7 @@ android {
minSdk = libs.versions.android.minSdk.get().toInteger() minSdk = libs.versions.android.minSdk.get().toInteger()
targetSdk = libs.versions.android.targetSdk.get().toInteger() targetSdk = libs.versions.android.targetSdk.get().toInteger()
versionCode = 433 versionCode = 433
versionName = generateVersionName("1.06.0") versionName = generateVersionName("1.06.1")
buildConfigField "String", "RELEASE_NOTES_ID", "\"0b6af7660b44215b0edf9c39a1c9c0b4aafba7aba1ae28665ffcecb1a9717195\"" buildConfigField "String", "RELEASE_NOTES_ID", "\"0b6af7660b44215b0edf9c39a1c9c0b4aafba7aba1ae28665ffcecb1a9717195\""
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -50,7 +50,7 @@ fun RecordAudioBox(
modifier: Modifier, modifier: Modifier,
onRecordTaken: (RecordingResult) -> Unit, onRecordTaken: (RecordingResult) -> Unit,
maxDurationSeconds: Int? = null, maxDurationSeconds: Int? = null,
content: @Composable (Boolean, Int) -> Unit, content: @Composable (Boolean, Int, () -> Unit) -> Unit,
) { ) {
val mediaRecorder = remember { mutableStateOf<VoiceMessageRecorder?>(null) } val mediaRecorder = remember { mutableStateOf<VoiceMessageRecorder?>(null) }
val context = LocalContext.current val context = LocalContext.current
@@ -79,7 +79,8 @@ fun RecordAudioBox(
} }
fun stopRecording() { fun stopRecording() {
val result = mediaRecorder.value?.stop() val recorder = mediaRecorder.value ?: return
val result = recorder.stop()
mediaRecorder.value = null mediaRecorder.value = null
if (result != null) { if (result != null) {
onRecordTaken(result) onRecordTaken(result)
@@ -136,6 +137,10 @@ fun RecordAudioBox(
} }
} }
}, },
content = { active -> content(active, elapsedSeconds) }, content = { active ->
content(active, elapsedSeconds) {
stopRecording()
}
},
) )
} }
@@ -50,15 +50,17 @@ fun RecordVoiceButton(
) { ) {
var isRecording by remember { mutableStateOf(false) } var isRecording by remember { mutableStateOf(false) }
var elapsedSeconds by remember { mutableIntStateOf(0) } var elapsedSeconds by remember { mutableIntStateOf(0) }
var onStopRecording: (() -> Unit)? by remember { mutableStateOf(null) }
Column( Column(
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
) { ) {
// Floating recording indicator at the top // Floating recording indicator at the top (outside ToggleableBox to avoid scale/circle)
FloatingRecordingIndicator( FloatingRecordingIndicator(
modifier = Modifier.height(50.dp), modifier = Modifier.height(50.dp),
isRecording = isRecording, isRecording = isRecording,
elapsedSeconds = elapsedSeconds, elapsedSeconds = elapsedSeconds,
onClick = onStopRecording,
) )
RecordAudioBox( RecordAudioBox(
@@ -69,15 +71,11 @@ fun RecordVoiceButton(
onVoiceTaken(recording) onVoiceTaken(recording)
}, },
maxDurationSeconds = maxDurationSeconds, maxDurationSeconds = maxDurationSeconds,
) { recordingState, elapsed -> ) { recordingState, elapsed, onStop ->
// Update parent state after composition completes
SideEffect { SideEffect {
if (isRecording != recordingState) { isRecording = recordingState
isRecording = recordingState elapsedSeconds = elapsed
} onStopRecording = onStop
if (elapsedSeconds != elapsed) {
elapsedSeconds = elapsed
}
} }
Box( Box(
@@ -27,6 +27,7 @@ import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
@@ -176,6 +177,7 @@ fun FloatingRecordingIndicator(
isRecording: Boolean, isRecording: Boolean,
elapsedSeconds: Int, elapsedSeconds: Int,
isCompact: Boolean = false, isCompact: Boolean = false,
onClick: (() -> Unit)? = null,
) { ) {
if (!isRecording) return if (!isRecording) return
@@ -199,6 +201,12 @@ fun FloatingRecordingIndicator(
.background( .background(
color = MaterialTheme.colorScheme.primary, color = MaterialTheme.colorScheme.primary,
shape = RoundedCornerShape(12.dp), shape = RoundedCornerShape(12.dp),
).then(
if (onClick != null) {
Modifier.clickable(onClick = onClick)
} else {
Modifier
},
), ),
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
) { ) {
@@ -215,7 +215,7 @@ private fun ReRecordButton(
modifier = Modifier, modifier = Modifier,
onRecordTaken = onRecordTaken, onRecordTaken = onRecordTaken,
maxDurationSeconds = MAX_VOICE_RECORD_SECONDS, maxDurationSeconds = MAX_VOICE_RECORD_SECONDS,
) { isRecording, elapsedSeconds -> ) { isRecording, elapsedSeconds, _ ->
val contentColor = val contentColor =
if (isRecording) { if (isRecording) {
MaterialTheme.colorScheme.onPrimary MaterialTheme.colorScheme.onPrimary
@@ -672,7 +672,7 @@ fun ReplyViaVoiceReaction(
} }
}, },
maxDurationSeconds = MAX_VOICE_RECORD_SECONDS, maxDurationSeconds = MAX_VOICE_RECORD_SECONDS,
) { isRecording, elapsedSeconds -> ) { isRecording, elapsedSeconds, onStop ->
if (voiceRecordingState != null) { if (voiceRecordingState != null) {
SideEffect { SideEffect {
if (voiceRecordingState.value != isRecording) { if (voiceRecordingState.value != isRecording) {
@@ -689,6 +689,7 @@ fun ReplyViaVoiceReaction(
isRecording = true, isRecording = true,
elapsedSeconds = elapsedSeconds, elapsedSeconds = elapsedSeconds,
isCompact = true, isCompact = true,
onClick = onStop,
) )
} else { } else {
VoiceReplyIcon(iconSizeModifier, grayTint) VoiceReplyIcon(iconSizeModifier, grayTint)
@@ -45,9 +45,14 @@ var monthNoDayFormatter = SimpleDateFormat(MONTH_NO_DAY_DATE_FORMAT, locale)
fun timeAgo( fun timeAgo(
time: Long?, time: Long?,
context: Context, context: Context,
prefix: String = "",
seconds: Int = R.string.now,
minutes: Int = R.string.m,
hours: Int = R.string.h,
days: Int = R.string.d,
): String { ): String {
if (time == null) return " " if (time == null) return " "
if (time == 0L) return "${stringRes(context, R.string.never)}" if (time == 0L) return prefix + stringRes(context, R.string.never)
val timeDifference = TimeUtils.now() - time val timeDifference = TimeUtils.now() - time
@@ -60,7 +65,7 @@ fun timeAgo(
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale) monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
} }
"" + yearFormatter.format(time * 1000) prefix + yearFormatter.format(time * 1000)
} else if (timeDifference > TimeUtils.ONE_MONTH) { } else if (timeDifference > TimeUtils.ONE_MONTH) {
// Dec 12 // Dec 12
if (locale != Locale.getDefault()) { if (locale != Locale.getDefault()) {
@@ -69,16 +74,16 @@ fun timeAgo(
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale) monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
} }
"" + monthFormatter.format(time * 1000) prefix + monthFormatter.format(time * 1000)
} else if (timeDifference > TimeUtils.ONE_DAY) { } else if (timeDifference > TimeUtils.ONE_DAY) {
// 2 days // 2 days
"" + (timeDifference / TimeUtils.ONE_DAY).toString() + stringRes(context, R.string.d) prefix + (timeDifference / TimeUtils.ONE_DAY).toString() + stringRes(context, days)
} else if (timeDifference > TimeUtils.ONE_HOUR) { } else if (timeDifference > TimeUtils.ONE_HOUR) {
"" + (timeDifference / TimeUtils.ONE_HOUR).toString() + stringRes(context, R.string.h) prefix + (timeDifference / TimeUtils.ONE_HOUR).toString() + stringRes(context, hours)
} else if (timeDifference > TimeUtils.ONE_MINUTE) { } else if (timeDifference > TimeUtils.ONE_MINUTE) {
"" + (timeDifference / TimeUtils.ONE_MINUTE).toString() + stringRes(context, R.string.m) prefix + (timeDifference / TimeUtils.ONE_MINUTE).toString() + stringRes(context, minutes)
} else { } else {
"" + stringRes(context, R.string.now) prefix + stringRes(context, seconds)
} }
} }
@@ -36,6 +36,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox import androidx.compose.material3.Checkbox
@@ -56,7 +57,13 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFontFamilyResolver
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.TextMeasurer
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -82,11 +89,10 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.mockAccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.mockAccountViewModel
import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.BigPadding import com.vitorpamplona.amethyst.ui.theme.BigPadding
import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer
import com.vitorpamplona.amethyst.ui.theme.Size25dp import com.vitorpamplona.amethyst.ui.theme.Size25dp
import com.vitorpamplona.amethyst.ui.theme.SmallishBorder import com.vitorpamplona.amethyst.ui.theme.SmallishBorder
import com.vitorpamplona.amethyst.ui.theme.SpacedBy10dp
import com.vitorpamplona.amethyst.ui.theme.SpacedBy5dp import com.vitorpamplona.amethyst.ui.theme.SpacedBy5dp
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
import com.vitorpamplona.amethyst.ui.theme.allGoodColor import com.vitorpamplona.amethyst.ui.theme.allGoodColor
import com.vitorpamplona.amethyst.ui.theme.grayText import com.vitorpamplona.amethyst.ui.theme.grayText
@@ -178,7 +184,7 @@ fun InnerRenderPoll(
TranslatableRichTextViewer( TranslatableRichTextViewer(
content = label, content = label,
canPreview = canPreview, canPreview = canPreview,
quotesLeft = 1, quotesLeft = if (quotesLeft > 0) 1 else 0,
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
@@ -328,10 +334,13 @@ private fun ColumnScope.RenderSingleChoiceOptions(
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
val hasSpaceToClick =
remember {
it.label.contains(' ') || it.label.contains('\n')
}
Column( Column(
modifier = modifier = if (hasSpaceToClick) Modifier.fillMaxWidth() else Modifier.fillMaxWidth(0.9f),
Modifier
.fillMaxWidth(),
) { ) {
labelContent(it.code, it.label) labelContent(it.code, it.label)
} }
@@ -418,12 +427,13 @@ private fun RenderClosedItem(
) { ) {
val tally by item.results.collectAsStateWithLifecycle(item.currentResults()) val tally by item.results.collectAsStateWithLifecycle(item.currentResults())
RenderClosedItem(tally, resultContent, labelContent) RenderClosedItem(tally, item.label, resultContent, labelContent)
} }
@Composable @Composable
private fun RenderClosedItem( private fun RenderClosedItem(
tally: TallyResults, tally: TallyResults,
label: String,
resultContent: @Composable RowScope.(user: User) -> Unit, resultContent: @Composable RowScope.(user: User) -> Unit,
labelContent: @Composable ColumnScope.() -> Unit, labelContent: @Composable ColumnScope.() -> Unit,
) { ) {
@@ -481,18 +491,21 @@ private fun RenderClosedItem(
content = labelContent, content = labelContent,
) )
Spacer(StdHorzSpacer) Spacer(DoubleHorzSpacer)
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = SpacedBy10dp,
) { ) {
UserGallery(tally, resultContent) if (label.length < 30) {
UserGallery(tally, resultContent)
}
Text( Text(
text = "${(tally.percent * 100).toInt()}%", text = "${(tally.percent * 100).toInt()}%",
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
textAlign = TextAlign.End,
modifier = measure100PercentWidthModifier(MaterialTheme.typography.bodyMedium),
maxLines = 1, maxLines = 1,
) )
} }
@@ -500,6 +513,24 @@ private fun RenderClosedItem(
} }
} }
@Composable
fun measure100PercentWidthModifier(textStyle: TextStyle): Modifier {
val fontFamilyResolver = LocalFontFamilyResolver.current
val density = LocalDensity.current
val layoutDirection = LocalLayoutDirection.current
return remember(fontFamilyResolver, density, textStyle) {
val widthPx =
TextMeasurer(fontFamilyResolver, density, layoutDirection, 1)
.measure("100%", style = textStyle.copy(fontWeight = FontWeight.Bold))
.size
.width
with(density) {
Modifier.width(widthPx.toDp())
}
}
}
@Composable @Composable
fun UserGallery( fun UserGallery(
tally: TallyResults, tally: TallyResults,
@@ -510,13 +541,13 @@ fun UserGallery(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy((-10).dp), horizontalArrangement = Arrangement.spacedBy((-10).dp),
) { ) {
tally.users.take(6).forEach { tally.users.take(4).forEach {
key(it.pubkeyHex) { key(it.pubkeyHex) {
galleryUser(it) galleryUser(it)
} }
} }
if (tally.users.size > 6) { if (tally.users.size > 4) {
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = modifier =
@@ -526,7 +557,7 @@ fun UserGallery(
.background(MaterialTheme.colorScheme.secondaryContainer), .background(MaterialTheme.colorScheme.secondaryContainer),
) { ) {
Text( Text(
text = "+" + showCount(tally.users.size - 6), text = "+" + showCount(tally.users.size - 4),
fontSize = 10.sp, fontSize = 10.sp,
color = MaterialTheme.colorScheme.onSurface, color = MaterialTheme.colorScheme.onSurface,
) )
@@ -584,6 +615,54 @@ fun RenderPollManualPreview() {
} }
} }
@Preview
@Composable
fun RenderPollManualLongPreview() {
val poll =
PollCard(
options =
listOf(
PollItemCard(
code = "1",
label = "Yes".repeat(300),
results = flow {},
currentResults = {
TallyResults(
percent = 1.0f,
isWinning = true,
)
},
),
PollItemCard(
code = "2",
label = "No".repeat(300),
results = flow {},
currentResults = {
TallyResults(
percent = 0.0f,
isWinning = false,
)
},
),
),
type = PollType.SINGLE_CHOICE,
endsAt = null,
isMyPoll = true,
haveIVotedFlow = flow {},
haveIVoted = { true },
)
ThemeComparisonColumn {
Column(Modifier.padding(10.dp)) {
RenderPollCard(poll, {}, {}) { _, label ->
Text(
text = label,
)
}
}
}
}
@SuppressLint("StateFlowValueCalledInComposition") @SuppressLint("StateFlowValueCalledInComposition")
@Preview @Preview
@Composable @Composable
@@ -309,7 +309,7 @@ fun DisplayLastSeen(
lastSeen?.let { timestamp -> lastSeen?.let { timestamp ->
val context = LocalContext.current val context = LocalContext.current
Text( Text(
text = stringRes(R.string.last_seen, timeAgo(timestamp, context)), text = stringRes(R.string.last_seen, timeAgo(timestamp, context, prefix = "", seconds = R.string.seconds)),
color = MaterialTheme.colorScheme.placeholderText, color = MaterialTheme.colorScheme.placeholderText,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
@@ -290,6 +290,7 @@
<string name="nip_05">Nostr Adresa</string> <string name="nip_05">Nostr Adresa</string>
<string name="never">nikdy</string> <string name="never">nikdy</string>
<string name="now">nyní</string> <string name="now">nyní</string>
<string name="seconds">sekundy</string>
<string name="h">h</string> <string name="h">h</string>
<string name="m">m</string> <string name="m">m</string>
<string name="d">d</string> <string name="d">d</string>
@@ -294,6 +294,7 @@ anz der Bedingungen ist erforderlich</string>
<string name="nip_05">Nostr-Adresse</string> <string name="nip_05">Nostr-Adresse</string>
<string name="never">nie</string> <string name="never">nie</string>
<string name="now">jetzt</string> <string name="now">jetzt</string>
<string name="seconds">Sekunden</string>
<string name="h">s</string> <string name="h">s</string>
<string name="m">m</string> <string name="m">m</string>
<string name="d">t</string> <string name="d">t</string>
@@ -71,7 +71,7 @@
<string name="quote">Zacytuj</string> <string name="quote">Zacytuj</string>
<string name="fork">Sklonuj</string> <string name="fork">Sklonuj</string>
<string name="propose_an_edit">Zaproponuj zmianę</string> <string name="propose_an_edit">Zaproponuj zmianę</string>
<string name="new_amount_in_sats">Nowa kwota w Satsach</string> <string name="new_amount_in_sats">Nowa kwota w satoszach</string>
<string name="add">Dodaj</string> <string name="add">Dodaj</string>
<string name="replying_to">"odpowiadając do "</string> <string name="replying_to">"odpowiadając do "</string>
<string name="and">" i "</string> <string name="and">" i "</string>
@@ -92,7 +92,7 @@
<string name="lightning_tips">Lightning transfer</string> <string name="lightning_tips">Lightning transfer</string>
<string name="note_to_receiver">Wiadomość dla odbiorcy</string> <string name="note_to_receiver">Wiadomość dla odbiorcy</string>
<string name="thank_you_so_much">Dziękuję bardzo!</string> <string name="thank_you_so_much">Dziękuję bardzo!</string>
<string name="amount_in_sats">Kwota w Satsach</string> <string name="amount_in_sats">Kwota w satoszach</string>
<string name="send_sats">Wyślij</string> <string name="send_sats">Wyślij</string>
<string name="secret_emoji_maker">Kreator tajnych emoji</string> <string name="secret_emoji_maker">Kreator tajnych emoji</string>
<string name="secret_emoji_maker_explainer">Dodaj emoji z ukrytą wiadomością do wpisu</string> <string name="secret_emoji_maker_explainer">Dodaj emoji z ukrytą wiadomością do wpisu</string>
@@ -1101,6 +1101,13 @@
<string name="new_community_note">Nowy wpis w społeczności</string> <string name="new_community_note">Nowy wpis w społeczności</string>
<string name="new_product">Nowy produkt</string> <string name="new_product">Nowy produkt</string>
<string name="new_exclusive_geo_note">Nowy GEO-ekskluzywny Wpis</string> <string name="new_exclusive_geo_note">Nowy GEO-ekskluzywny Wpis</string>
<string name="new_long_form_post">Nowy artykuł</string>
<string name="article_title">Tytuł</string>
<string name="article_summary">Podsumowanie (opcjonalnie)</string>
<string name="article_cover_image_url">Adres URL miniaturki (opcjonalnie)</string>
<string name="write_your_article_in_markdown">Napisz artykuł w formacie markdown…</string>
<string name="markdown_preview">Podgląd</string>
<string name="markdown_edit">Edytuj</string>
<string name="open_all_reactions_to_this_post">Otwórz wszystkie odzewy na ten post</string> <string name="open_all_reactions_to_this_post">Otwórz wszystkie odzewy na ten post</string>
<string name="close_all_reactions_to_this_post">Zamknij wszystkie odzewy na ten post</string> <string name="close_all_reactions_to_this_post">Zamknij wszystkie odzewy na ten post</string>
<string name="reply_description">Odpowiedź</string> <string name="reply_description">Odpowiedź</string>
@@ -1238,6 +1245,7 @@
<string name="existed_since">OTS: %1$s</string> <string name="existed_since">OTS: %1$s</string>
<string name="ots_info_title">Potwierdzenie znacznika czasu</string> <string name="ots_info_title">Potwierdzenie znacznika czasu</string>
<string name="ots_info_description">Istnieje dowód na to, że ten post został podpisany przed %1$s. Dowód został opatrzony pieczęcią w łańcuchu bloków Bitcoin w tym dniu i czasie.</string> <string name="ots_info_description">Istnieje dowód na to, że ten post został podpisany przed %1$s. Dowód został opatrzony pieczęcią w łańcuchu bloków Bitcoin w tym dniu i czasie.</string>
<string name="edit_article">Redaguj artykuł</string>
<string name="edit_post">Edytuj wpis</string> <string name="edit_post">Edytuj wpis</string>
<string name="proposal_to_edit">Propozycja ulepszenia wpisu</string> <string name="proposal_to_edit">Propozycja ulepszenia wpisu</string>
<string name="message_to_author">Podsumowanie zmian</string> <string name="message_to_author">Podsumowanie zmian</string>
@@ -1560,6 +1568,7 @@
<string name="name_search_npub1_alice_example_com">wyszukaj, npub1…, alicja@domena.pl</string> <string name="name_search_npub1_alice_example_com">wyszukaj, npub1…, alicja@domena.pl</string>
<string name="supports_npub_nip_05_hex_and_namecoin_bit_d_id">Obsługuje npub, nprofile, NIP-05, hex, i namecoin (.bit, d/, id/)</string> <string name="supports_npub_nip_05_hex_and_namecoin_bit_d_id">Obsługuje npub, nprofile, NIP-05, hex, i namecoin (.bit, d/, id/)</string>
<string name="look_up_follow_list">Sprawdź listę obserwowanych</string> <string name="look_up_follow_list">Sprawdź listę obserwowanych</string>
<string name="tip">Porada</string>
<string name="accounts_found">Znaleziono %1$d kont(a)</string> <string name="accounts_found">Znaleziono %1$d kont(a)</string>
<string name="num_selected">Wybrano: %1$d</string> <string name="num_selected">Wybrano: %1$d</string>
<string name="resolved_via_namecoin">Rozwiązane przez Namecoin</string> <string name="resolved_via_namecoin">Rozwiązane przez Namecoin</string>
@@ -1659,4 +1668,11 @@
<string name="attestor_proficiency_for_kinds">Biegłość w sprawdzaniu typów: %1$s</string> <string name="attestor_proficiency_for_kinds">Biegłość w sprawdzaniu typów: %1$s</string>
<string name="attestation_attests_to">Certyfikat dla</string> <string name="attestation_attests_to">Certyfikat dla</string>
<string name="attestation_requests_attestation_to">Żądanie certyfikatu do</string> <string name="attestation_requests_attestation_to">Żądanie certyfikatu do</string>
<string name="event_sync_date_filter_title">Przedział czasu</string>
<string name="event_sync_date_filter_since">Od</string>
<string name="event_sync_date_filter_until">Do</string>
<string name="event_sync_date_filter_now">Teraz</string>
<string name="event_sync_date_filter_all_time">Cały czas</string>
<string name="event_sync_date_filter_last_sync">Ostatnia synchronizacja %1$s</string>
<string name="event_sync_date_filter_since_last_sync">Od ostatniej synchronizacji</string>
</resources> </resources>
@@ -290,6 +290,7 @@
<string name="nip_05">Endereço Nostr</string> <string name="nip_05">Endereço Nostr</string>
<string name="never">nunca</string> <string name="never">nunca</string>
<string name="now">agora</string> <string name="now">agora</string>
<string name="seconds">segundos</string>
<string name="h">h</string> <string name="h">h</string>
<string name="m">m</string> <string name="m">m</string>
<string name="d">d</string> <string name="d">d</string>
@@ -290,6 +290,7 @@
<string name="nip_05">Nostr-adress</string> <string name="nip_05">Nostr-adress</string>
<string name="never">aldrig</string> <string name="never">aldrig</string>
<string name="now">nu</string> <string name="now">nu</string>
<string name="seconds">sekunder</string>
<string name="h">t</string> <string name="h">t</string>
<string name="m">m</string> <string name="m">m</string>
<string name="d">d</string> <string name="d">d</string>
@@ -290,6 +290,7 @@
<string name="nip_05">Nostr 地址</string> <string name="nip_05">Nostr 地址</string>
<string name="never">从不</string> <string name="never">从不</string>
<string name="now">现在</string> <string name="now">现在</string>
<string name="seconds"></string>
<string name="h"></string> <string name="h"></string>
<string name="m"></string> <string name="m"></string>
<string name="d"></string> <string name="d"></string>
@@ -1104,6 +1105,13 @@
<string name="new_community_note">新社区笔记</string> <string name="new_community_note">新社区笔记</string>
<string name="new_product">新产品</string> <string name="new_product">新产品</string>
<string name="new_exclusive_geo_note">新建地理位置限定帖文</string> <string name="new_exclusive_geo_note">新建地理位置限定帖文</string>
<string name="new_long_form_post">新文章</string>
<string name="article_title">标题</string>
<string name="article_summary">摘要(选填)</string>
<string name="article_cover_image_url">封面图片URL (可选)</string>
<string name="write_your_article_in_markdown">用 markdown 格式撰写文章…</string>
<string name="markdown_preview">预览</string>
<string name="markdown_edit">编辑</string>
<string name="open_all_reactions_to_this_post">展开对此帖子的所有回应</string> <string name="open_all_reactions_to_this_post">展开对此帖子的所有回应</string>
<string name="close_all_reactions_to_this_post">收起对此帖子的所有回应</string> <string name="close_all_reactions_to_this_post">收起对此帖子的所有回应</string>
<string name="reply_description">回复</string> <string name="reply_description">回复</string>
@@ -1241,6 +1249,7 @@
<string name="existed_since">OTS%1$s</string> <string name="existed_since">OTS%1$s</string>
<string name="ots_info_title">OpenTimestamps 证明</string> <string name="ots_info_title">OpenTimestamps 证明</string>
<string name="ots_info_description">%1$s之前的某个时候签署了此帖子的证明。此证明是在那个日期和时间在比特币区块链中盖章的。</string> <string name="ots_info_description">%1$s之前的某个时候签署了此帖子的证明。此证明是在那个日期和时间在比特币区块链中盖章的。</string>
<string name="edit_article">编辑文章</string>
<string name="edit_post">编辑帖子</string> <string name="edit_post">编辑帖子</string>
<string name="proposal_to_edit">提议改进帖子</string> <string name="proposal_to_edit">提议改进帖子</string>
<string name="message_to_author">变动摘要</string> <string name="message_to_author">变动摘要</string>
@@ -1664,4 +1673,11 @@
<string name="attestor_proficiency_for_kinds">熟练验证类型:%1$s</string> <string name="attestor_proficiency_for_kinds">熟练验证类型:%1$s</string>
<string name="attestation_attests_to">证明</string> <string name="attestation_attests_to">证明</string>
<string name="attestation_requests_attestation_to">请求证明</string> <string name="attestation_requests_attestation_to">请求证明</string>
<string name="event_sync_date_filter_title">日期范围</string>
<string name="event_sync_date_filter_since"></string>
<string name="event_sync_date_filter_until"></string>
<string name="event_sync_date_filter_now">刚刚</string>
<string name="event_sync_date_filter_all_time">全部时间</string>
<string name="event_sync_date_filter_last_sync">上次同步: %1$s</string>
<string name="event_sync_date_filter_since_last_sync">自上次同步后</string>
</resources> </resources>
+1
View File
@@ -309,6 +309,7 @@
<string name="lnurl" translatable="false">LNURL…</string> <string name="lnurl" translatable="false">LNURL…</string>
<string name="never">never</string> <string name="never">never</string>
<string name="now">now</string> <string name="now">now</string>
<string name="seconds">seconds</string>
<string name="h">h</string> <string name="h">h</string>
<string name="m">m</string> <string name="m">m</string>
<string name="d">d</string> <string name="d">d</string>
@@ -281,6 +281,18 @@ class UrlParserTest {
Urls(withScheme = emptySet()), Urls(withScheme = emptySet()),
) )
/**
* Regression test for PR #1907: parsing a note whose content is only the Japanese phrase
* "今北産業" (a common internet abbreviation) must not throw a StringIndexOutOfBoundsException
* from Url.getPart() and must produce no detected URLs.
*/
@Test
fun testImakitaSangyo() =
test(
"今北産業",
Urls(),
)
@Test @Test
fun testHour() = fun testHour() =
test( test(
+1 -1
View File
@@ -351,7 +351,7 @@ mavenPublishing {
coordinates( coordinates(
groupId = "com.vitorpamplona.quartz", groupId = "com.vitorpamplona.quartz",
artifactId = "quartz", artifactId = "quartz",
version = "1.06.0", version = "1.06.1",
) )
// Configure publishing to Maven Central // Configure publishing to Maven Central
@@ -36,7 +36,7 @@ class RelayOfflineTracker(
const val TAG = "RelayOfflineTracker" const val TAG = "RelayOfflineTracker"
} }
val cannotConnectRelays = mutableSetOf<NormalizedRelayUrl>() var cannotConnectRelays = setOf<NormalizedRelayUrl>()
private val clientListener = private val clientListener =
object : IRelayClientListener { object : IRelayClientListener {
@@ -45,14 +45,14 @@ class RelayOfflineTracker(
pingMillis: Int, pingMillis: Int,
compressed: Boolean, compressed: Boolean,
) { ) {
cannotConnectRelays.remove(relay.url) cannotConnectRelays -= relay.url
} }
override fun onCannotConnect( override fun onCannotConnect(
relay: IRelayClient, relay: IRelayClient,
errorMessage: String, errorMessage: String,
) { ) {
cannotConnectRelays.add(relay.url) cannotConnectRelays += relay.url
} }
} }
@@ -228,11 +228,17 @@ class Url(
return null return null
} }
val startIndex = urlMarker.indexOf(part)
if (startIndex < 0 || startIndex >= originalUrl.length) {
return null
}
val nextPart = nextExistingPart(part) val nextPart = nextExistingPart(part)
return if (nextPart == null) { return if (nextPart == null) {
originalUrl.substring(urlMarker.indexOf(part)) originalUrl.substring(startIndex)
} else { } else {
originalUrl.substring(urlMarker.indexOf(part), urlMarker.indexOf(nextPart)) val endIndex = urlMarker.indexOf(nextPart)
originalUrl.substring(startIndex, minOf(endIndex, originalUrl.length))
} }
} }
@@ -41,4 +41,14 @@ class UrlsDetectorTest {
assertContains(detectedLinks, "https://mysite.xyz") assertContains(detectedLinks, "https://mysite.xyz")
assertContains(detectedLinks, "https://myblog.xyz") assertContains(detectedLinks, "https://myblog.xyz")
} }
/**
* Regression test for PR #1907: the Japanese phrase "今北産業" must not crash the URL
* detector with a StringIndexOutOfBoundsException and must return no URLs.
*/
@Test
fun doesNotCrashOnJapaneseText() {
val detectedLinks = fastFindURLs("今北産業")
assertEquals(0, detectedLinks.size)
}
} }
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.utils.urldetector
import com.vitorpamplona.quartz.utils.urldetector.detection.UrlDetector
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
/**
* Regression tests for PR #1907: StringIndexOutOfBoundsException in [Url.getPart] when
* processing the Japanese text "今北産業".
*/
class UrlTest {
/**
* Regression: detecting URLs in "今北産業" must not throw and must return no URLs.
*/
@Test
fun detectingImakitaSangyoDoesNotThrow() {
val urls = UrlDetector("今北産業").detect()
assertEquals(0, urls.size)
}
/**
* Regression: constructing a Url with "今北産業" as the original string and a HOST
* marker at 0 with PORT at the string length (simulating a trimmed trailing character)
* must not throw StringIndexOutOfBoundsException when accessing any property.
*
* "今北産業" has length 4. PORT at 4 == length triggers the startIndex >= length guard
* added to getPart() in PR #1907.
*/
@Test
fun urlPropertiesDoNotThrowForImakitaSangyoWithOutOfRangeMarker() {
val marker = UrlMarker()
marker.setIndex(UrlPart.HOST, 0)
marker.setIndex(UrlPart.PORT, 4) // == "今北産業".length
val url = marker.createUrl("今北産業")
assertNotNull(url.scheme)
assertNotNull(url.host)
assertNotNull(url.path)
assertNotNull(url.query)
assertNotNull(url.fragment)
assertEquals(-1, url.port) // getPart(PORT) returns null → -1
}
}