feat: v0.4.2.0 — voice notes (Opus 32 kbps mono), toolbar reorder, backup-first release notes
Voice notes: record in-note via framework MediaRecorder; takes stored as compact Opus-in-Ogg (.opus, 32 kbps, single channel, 48 kHz) on API 29+ with AAC/.m4a fallback on API 26-28; MediaPlayer bar with Download to system Downloads. Editor toolbar reordered Photo / Voice / Attach / Tasks / Shopping list, hashtag justified flush right. Release notes across README / PREVIOUS_HISTORY / ReleaseNotes / CONTRIBUTING / Development Plan now open every release with a back-up-before-installing warning (standing convention). versionCode 38, versionName 0.4.2.0, APP_VERSION lockstep; assembleDebug + assembleRelease green.
This commit is contained in:
1 parent
1d97376aef
commit
f87ca17ded
18 files changed
+1012
-59
No files matched your search
@@ -130,8 +130,8 @@ data class BackupNote(
|
||||
val isDraft: Boolean = false,
|
||||
/**
|
||||
* v0.3.8.0 — serialised as the [org.incido.domain.model.NoteType]
|
||||
* enum name ("TEXT" / "TASK_LIST" / "SHOPPING_LIST"). Defaulted so
|
||||
* pre-v0.3.8.0 backup files import as plain-text notes.
|
||||
* enum name ("TEXT" / "TASK_LIST" / "SHOPPING_LIST" / "VOICE_NOTE").
|
||||
* Defaulted so pre-v0.3.8.0 backup files import as plain-text notes.
|
||||
*/
|
||||
val noteType: String = "TEXT",
|
||||
)
|
||||
|
||||
@@ -25,6 +25,43 @@ object ReleaseNotes {
|
||||
* Append a new entry on top each release.
|
||||
*/
|
||||
val RECENT: List<ReleaseNote> = listOf(
|
||||
ReleaseNote(
|
||||
version = "0.4.2.0",
|
||||
date = "2026-09-23",
|
||||
bullets = listOf(
|
||||
"Before you update: please make certain you have a " +
|
||||
"current backup — Settings → Backup & Restore → " +
|
||||
"Export (plus your encryption key under Settings → " +
|
||||
"Security if encryption is on) — before installing " +
|
||||
"this version. Every future release will remind " +
|
||||
"you the same way.",
|
||||
"Voice notes: the editor's bottom toolbar gained a mic " +
|
||||
"button, right after the camera — the row is now " +
|
||||
"Photo · Voice · Attach · Tasks · Shopping list, " +
|
||||
"with the hashtag button moved to the far right. " +
|
||||
"Tap it and the note grows a recording card " +
|
||||
"at the top of its body — tap record, stop when " +
|
||||
"you're done, and your take gets a media player with " +
|
||||
"play / pause, a seek bar, and elapsed / total time.",
|
||||
"Recordings are captured as compact Opus audio " +
|
||||
"(.opus files \u2014 32 kbps, single channel): tiny " +
|
||||
"files, clear speech. Phones on Android 8.x / 9 " +
|
||||
"fall back to the old AAC format automatically.",
|
||||
"Your recording is saved with the note like any other " +
|
||||
"attachment — encrypted at rest when encryption " +
|
||||
"is on, riding along in backups — and a download " +
|
||||
"button copies it out to the system Downloads folder " +
|
||||
"when you need the file itself.",
|
||||
"Voice notes are still normal notes: title, text body, " +
|
||||
"colours, tags, favourites, drafts, and search all " +
|
||||
"work as before. Re-recording replaces the old take; " +
|
||||
"converting back to a text note keeps the recording " +
|
||||
"as an ordinary attachment.",
|
||||
"Voice note cards carry a mic badge, and the microphone " +
|
||||
"permission is only asked for on the first tap into " +
|
||||
"voice mode — recordings never leave the device.",
|
||||
),
|
||||
),
|
||||
ReleaseNote(
|
||||
version = "0.4.1.1",
|
||||
date = "2026-09-23",
|
||||
@@ -119,25 +156,6 @@ object ReleaseNotes {
|
||||
"only \"+ Create\\u2026\" ever showed).",
|
||||
),
|
||||
),
|
||||
ReleaseNote(
|
||||
version = "0.3.7.1",
|
||||
date = "2026-08-30",
|
||||
bullets = listOf(
|
||||
"Cleaner Add / Edit screen: camera, attach-file, and " +
|
||||
"add-tag moved out of the crowded title bar into a " +
|
||||
"bottom action row — the title and remaining buttons " +
|
||||
"now fit comfortably on every screen.",
|
||||
"Fixed a false error message that flashed whenever you " +
|
||||
"opened a saved image in the full-screen viewer.",
|
||||
"Search now focuses automatically when opened and shows " +
|
||||
"a clear (✕) button while you type.",
|
||||
"Long tag lists in the navigation drawer now scroll " +
|
||||
"instead of being cut off at the bottom.",
|
||||
"The add-tag sheet opens with the keyboard already up.",
|
||||
"New app icon: a flatter, cleaner take on the shield " +
|
||||
"and pen-nib artwork.",
|
||||
),
|
||||
),
|
||||
// v0.4.1.1 push drops v0.3.8.1 off the "5 most recent" tail.
|
||||
// v0.4.2.0 push drops v0.3.7.1 off the "5 most recent" tail.
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.incido.compose.ui.editor
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.widget.Toast
|
||||
@@ -50,6 +51,7 @@ import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Description
|
||||
import androidx.compose.material.icons.filled.Done
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.Mic
|
||||
import androidx.compose.material.icons.filled.ShoppingBasket
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.filled.Tag
|
||||
@@ -107,6 +109,7 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
@@ -236,6 +239,39 @@ fun NoteEditorScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// v0.4.2.0 — voice notes. RECORD_AUDIO is requested the first time
|
||||
// the user toggles the mic mode; on grant the note converts. The
|
||||
// grant state is checked LIVE on every tap (a revoke from Settings
|
||||
// mid-session must not slip through a cached flag).
|
||||
val micPermissionLauncher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { granted ->
|
||||
if (granted) {
|
||||
viewModel.convertTo(NoteType.VOICE_NOTE)
|
||||
} else {
|
||||
Toast.makeText(ctx, "Microphone permission denied", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
fun micPermissionGranted(): Boolean =
|
||||
ContextCompat.checkSelfPermission(
|
||||
ctx,
|
||||
Manifest.permission.RECORD_AUDIO,
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
fun toggleVoiceMode() {
|
||||
if (state.type == NoteType.VOICE_NOTE) {
|
||||
// Toggling back needs no mic at all — the take survives as
|
||||
// an ordinary attachment.
|
||||
viewModel.convertTo(NoteType.VOICE_NOTE)
|
||||
return
|
||||
}
|
||||
if (micPermissionGranted()) {
|
||||
viewModel.convertTo(NoteType.VOICE_NOTE)
|
||||
} else {
|
||||
micPermissionLauncher.launch(Manifest.permission.RECORD_AUDIO)
|
||||
}
|
||||
}
|
||||
|
||||
fun launchCamera() {
|
||||
val (uri, _) = createTempCameraUri(ctx)
|
||||
if (uri == null) {
|
||||
@@ -414,7 +450,35 @@ fun NoteEditorScreen(
|
||||
// field whenever the note is a task / shopping list; the
|
||||
// rows live in NoteEditorUiState.items and the view-model
|
||||
// keeps `content` synchronised with their serialisation.
|
||||
if (state.type == NoteType.TEXT) {
|
||||
// v0.4.2.0 — voice recorder / media-player card pinned at
|
||||
// the very top of the note body, directly above the text
|
||||
// field (which keeps working exactly like the plain-text
|
||||
// editor: title = first line).
|
||||
if (state.type == NoteType.VOICE_NOTE) {
|
||||
val voicePending = state.pendingAttachments
|
||||
.lastOrNull { it.mimeType.startsWith("audio/") }
|
||||
val voicePersisted = state.attachments.lastOrNull { it.isAudio }
|
||||
VoiceNoteSection(
|
||||
voicePending = voicePending,
|
||||
voicePendingBytes = voicePending?.let {
|
||||
state.pendingAttachmentBytes[it.tempId]
|
||||
},
|
||||
voicePersisted = voicePersisted,
|
||||
repository = repository,
|
||||
hasMicPermission = { micPermissionGranted() },
|
||||
onRequestPermission = {
|
||||
micPermissionLauncher.launch(Manifest.permission.RECORD_AUDIO)
|
||||
},
|
||||
onTakeRecorded = viewModel::setVoiceRecording,
|
||||
onDeleteTake = {
|
||||
voicePending?.let { viewModel.removePendingAttachment(it.tempId) }
|
||||
?: voicePersisted?.let { viewModel.deletePersistedAttachment(it.id) }
|
||||
},
|
||||
securityManager = securityManager,
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
)
|
||||
}
|
||||
if (state.type == NoteType.TEXT || state.type == NoteType.VOICE_NOTE) {
|
||||
OutlinedTextField(
|
||||
value = state.content,
|
||||
onValueChange = viewModel::onContentChange,
|
||||
@@ -488,7 +552,9 @@ fun NoteEditorScreen(
|
||||
// into this bottom action row so the top bar always fits
|
||||
// (the six-action cluster used to crowd the title on narrow
|
||||
// screens). Keep-style placement, above the nav bar /
|
||||
// keyboard.
|
||||
// keyboard. Order: Photo · Voice · Attach · Tasks · Shopping
|
||||
// list, then the hashtag button sits flush right — a
|
||||
// weighted spacer separates it from the action cluster.
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@@ -503,6 +569,18 @@ fun NoteEditorScreen(
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
// v0.4.2.0 — voice-note toggle, first after Photo:
|
||||
// converts the note to / from voice mode (mic permission
|
||||
// is requested on the first tap into the mode).
|
||||
IconButton(onClick = { toggleVoiceMode() }) {
|
||||
Icon(
|
||||
Icons.Filled.Mic,
|
||||
contentDescription = "Voice note",
|
||||
tint = if (state.type == NoteType.VOICE_NOTE)
|
||||
MaterialTheme.colorScheme.primary
|
||||
else MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
IconButton(onClick = {
|
||||
// v0.3.4.0 hotfix: the SAF picker backgrounds
|
||||
// the app; with Auto-Lock = Immediate the return
|
||||
@@ -516,21 +594,9 @@ fun NoteEditorScreen(
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
onClick = { viewModel.openAddTagSheet() },
|
||||
enabled = state.canAddMoreTags,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Tag,
|
||||
contentDescription = "Add tag",
|
||||
tint = if (state.canAddMoreTags)
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
else MaterialTheme.colorScheme.outlineVariant,
|
||||
)
|
||||
}
|
||||
// v0.3.8.0 — task-list toggle next to the # button.
|
||||
// Converts the body into editable checklist rows (and
|
||||
// back); the active mode tints with the primary colour.
|
||||
// v0.3.8.0 — task-list toggle: converts the body into
|
||||
// editable checklist rows (and back); the active mode
|
||||
// tints with the primary colour.
|
||||
IconButton(onClick = { viewModel.convertTo(NoteType.TASK_LIST) }) {
|
||||
Icon(
|
||||
Icons.Filled.Checklist,
|
||||
@@ -552,6 +618,21 @@ fun NoteEditorScreen(
|
||||
else MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
// Push the hashtag button to the far right, visually
|
||||
// separated from the action cluster above.
|
||||
Spacer(Modifier.weight(1f))
|
||||
IconButton(
|
||||
onClick = { viewModel.openAddTagSheet() },
|
||||
enabled = state.canAddMoreTags,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Tag,
|
||||
contentDescription = "Add tag",
|
||||
tint = if (state.canAddMoreTags)
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
else MaterialTheme.colorScheme.outlineVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1252,8 +1333,11 @@ private fun editorFieldStyle(): TextStyle =
|
||||
* the "Draft" branch.)
|
||||
*/
|
||||
private fun draftBarTitle(state: NoteEditorUiState): String {
|
||||
// v0.4.2.0: voice notes keep the plain content field (title = first
|
||||
// line), so they read their title from `content` like TEXT does.
|
||||
val titleSource =
|
||||
if (state.type == NoteType.TEXT) state.content else state.listHeader
|
||||
if (state.type == NoteType.TEXT || state.type == NoteType.VOICE_NOTE) state.content
|
||||
else state.listHeader
|
||||
val hasTitle = titleSource.lineSequence().any { it.isNotBlank() }
|
||||
return if (hasTitle) "Draft" else "${state.type.displayName} - (draft)"
|
||||
}
|
||||
|
||||
@@ -93,12 +93,26 @@ data class NoteEditorUiState(
|
||||
*/
|
||||
val fullScreenAttachmentId: ViewerAttachmentId? = null,
|
||||
) {
|
||||
/** `true` while content is non-blank and not in the middle of saving. */
|
||||
val canSave: Boolean get() = content.isNotBlank() && !isSaving
|
||||
|
||||
/** `true` when editing an existing note (existing != null). */
|
||||
val isEditing: Boolean get() = existing != null
|
||||
|
||||
/**
|
||||
* v0.4.2.0 — `true` once a voice take exists (staged pending or
|
||||
* already persisted as an attachment).
|
||||
*/
|
||||
val hasVoiceTake: Boolean get() =
|
||||
pendingAttachments.any { it.mimeType.startsWith("audio/") } ||
|
||||
attachments.any { it.mimeType.startsWith("audio/") }
|
||||
|
||||
/**
|
||||
* `true` while content is non-blank and not in the middle of
|
||||
* saving. v0.4.2.0: a VOICE_NOTE may also save on the strength of
|
||||
* its recording alone — the take IS the note's content.
|
||||
*/
|
||||
val canSave: Boolean get() =
|
||||
(content.isNotBlank() || (type == NoteType.VOICE_NOTE && hasVoiceTake)) &&
|
||||
!isSaving
|
||||
|
||||
/** `true` while this note is an auto-saved draft (see Note.isDraft). */
|
||||
val isDraft: Boolean get() = existing?.isDraft == true
|
||||
|
||||
@@ -450,13 +464,28 @@ class NoteEditorViewModel(
|
||||
fun convertTo(target: NoteType) {
|
||||
_state.update { s ->
|
||||
val next = if (s.type == target) NoteType.TEXT else target
|
||||
if (next == NoteType.TEXT) {
|
||||
if (next == NoteType.VOICE_NOTE) {
|
||||
// v0.4.2.0 — voice mode keeps the plain text field
|
||||
// (title = first line) exactly like TEXT; a list body
|
||||
// folds back to its plain form first. The recording is
|
||||
// NOT body content — it's an ordinary audio attachment,
|
||||
// so it also survives converting back to plain text.
|
||||
val source =
|
||||
if (s.type == NoteType.TEXT || s.type == NoteType.VOICE_NOTE) s.content
|
||||
else Note.serializeListContent(s.listHeader, s.items, NoteType.TEXT)
|
||||
s.copy(
|
||||
type = next,
|
||||
listHeader = "",
|
||||
items = emptyList(),
|
||||
content = source,
|
||||
)
|
||||
} else if (next == NoteType.TEXT) {
|
||||
// Content already holds the serialised `- [ ]` rows;
|
||||
// just drop out of the structured editor (the inline
|
||||
// GFM checklist rendering from v0.2.0.0 still applies).
|
||||
s.copy(type = NoteType.TEXT, listHeader = "", items = emptyList())
|
||||
} else {
|
||||
val source = if (s.type == NoteType.TEXT) {
|
||||
val source = if (s.type == NoteType.TEXT || s.type == NoteType.VOICE_NOTE) {
|
||||
s.content
|
||||
} else {
|
||||
// Serialise through the FOLDED legacy form (plain
|
||||
@@ -483,6 +512,7 @@ class NoteEditorViewModel(
|
||||
snackbar = when (it.type) {
|
||||
NoteType.TASK_LIST -> "Task list mode — first line stays the title."
|
||||
NoteType.SHOPPING_LIST -> "Shopping list mode — check an item once it's in your basket."
|
||||
NoteType.VOICE_NOTE -> "Voice note mode — record with the mic card above the text."
|
||||
else -> "Back to plain text."
|
||||
},
|
||||
)
|
||||
@@ -630,6 +660,46 @@ class NoteEditorViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.4.2.0 — stage/persist the finished take of a voice note.
|
||||
* One take per note: any previous take (pending or already
|
||||
* persisted) is discarded first. The bytes then ride the ordinary
|
||||
* attachment pipeline — staged as a [PendingAttachment] while the
|
||||
* note is unsaved, written straight to the DB afterwards — so
|
||||
* encryption, backup/restore, and the trash cascade all apply
|
||||
* without any voice-specific storage.
|
||||
*
|
||||
* [mimeType] is the container the recorder actually produced —
|
||||
* `audio/ogg` (Opus, 32 kbps mono) on API 29+, `audio/mp4` (AAC)
|
||||
* on API 26–28; the display-name extension follows suit.
|
||||
*/
|
||||
fun setVoiceRecording(bytes: ByteArray, mimeType: String = "audio/ogg") {
|
||||
if (bytes.size < 2048) {
|
||||
_state.update { it.copy(snackbar = "Recording too short \u2014 try again.") }
|
||||
return
|
||||
}
|
||||
viewModelScope.launch {
|
||||
_state.value.pendingAttachments
|
||||
.filter { it.mimeType.startsWith("audio/") }
|
||||
.forEach { removePendingAttachment(it.tempId) }
|
||||
val stalePersisted = _state.value.attachments
|
||||
.filter { it.mimeType.startsWith("audio/") }
|
||||
if (stalePersisted.isNotEmpty()) {
|
||||
withContext(Dispatchers.IO) {
|
||||
stalePersisted.forEach { repository.removeAttachment(it.id) }
|
||||
}
|
||||
}
|
||||
val stamp = java.text.SimpleDateFormat("yyyyMMdd_HHmmss", java.util.Locale.US)
|
||||
.format(java.util.Date())
|
||||
val ext = if (mimeType == "audio/mp4") "m4a" else "opus"
|
||||
importAttachmentBytes(
|
||||
bytes = bytes,
|
||||
mimeType = mimeType,
|
||||
displayName = "Voice_$stamp.$ext",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Open the full-screen image viewer for [viewerId]. */
|
||||
fun openFullScreen(viewerId: ViewerAttachmentId) {
|
||||
_state.update { it.copy(fullScreenAttachmentId = viewerId) }
|
||||
|
||||
@@ -0,0 +1,539 @@
|
||||
package org.incido.compose.ui.editor
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.MediaPlayer
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.FiberManualRecord
|
||||
import androidx.compose.material.icons.filled.Mic
|
||||
import androidx.compose.material.icons.filled.Pause
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Stop
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.FileProvider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.incido.compose.data.security.SecurityManager
|
||||
import org.incido.domain.model.NoteAttachment
|
||||
import org.incido.domain.repository.NoteRepository
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* v0.4.2.0 — the voice-note body section: sits at the very top of the
|
||||
* note body (above the text field) whenever the editor is in
|
||||
* [org.incido.domain.model.NoteType.VOICE_NOTE] mode.
|
||||
*
|
||||
* Three states:
|
||||
* * **No take** — "tap to record" card.
|
||||
* * **Recording** — live elapsed timer with stop / discard controls.
|
||||
* * **Take ready** (pending *or* persisted) — media player bar with
|
||||
* play/pause, seek, a **Download** action that copies the file to
|
||||
* the system Downloads folder, and a delete action (re-record via
|
||||
* the mic button — the ViewModel replaces the old take when a new
|
||||
* recording lands).
|
||||
*
|
||||
* The take rides the existing attachment pipeline: while the note is
|
||||
* unsaved it is a [PendingAttachment] whose bytes live in the UI
|
||||
* state; after save it is an ordinary `audio/ogg` attachment row
|
||||
* (encrypted at rest like every other attachment, backed up with the
|
||||
* note, and still visible in the attachment strip below).
|
||||
*/
|
||||
@Composable
|
||||
fun VoiceNoteSection(
|
||||
/** Pending (unsaved) voice take, or null. */
|
||||
voicePending: PendingAttachment?,
|
||||
/** Bytes of the pending take (null while still unrecorded). */
|
||||
voicePendingBytes: ByteArray?,
|
||||
/** Persisted voice take of a saved note, or null. */
|
||||
voicePersisted: NoteAttachment?,
|
||||
/** Source of persisted bytes (lazy-loaded by the player). */
|
||||
repository: NoteRepository?,
|
||||
/** Checked on every record tap — reflects RECORD_AUDIO state. */
|
||||
hasMicPermission: () -> Boolean,
|
||||
/** Launches the RECORD_AUDIO permission request. */
|
||||
onRequestPermission: () -> Unit,
|
||||
/** A finished recording is ready to stage/persist (replaces any old take);
|
||||
* second arg is the recorder's actual mime (`audio/ogg`, or `audio/mp4` on API 26–28). */
|
||||
onTakeRecorded: (ByteArray, String) -> Unit,
|
||||
/** Remove the current take (pending or persisted). */
|
||||
onDeleteTake: () -> Unit,
|
||||
/** Suppress auto-lock around the download share-sheet round-trip (API < 29). */
|
||||
securityManager: SecurityManager?,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val recorder = remember { VoiceRecorder() }
|
||||
var isRecording by remember { mutableStateOf(false) }
|
||||
var elapsedMs by remember { mutableStateOf(0L) }
|
||||
|
||||
// Abandon an in-flight take if the editor tears down mid-recording
|
||||
// (back navigation, config change) — no orphan temp files.
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { recorder.cancel() }
|
||||
}
|
||||
|
||||
// Live tick for the recording timer.
|
||||
LaunchedEffect(isRecording) {
|
||||
if (!isRecording) return@LaunchedEffect
|
||||
val startedAt = android.os.SystemClock.elapsedRealtime() - elapsedMs
|
||||
while (isRecording) {
|
||||
elapsedMs = android.os.SystemClock.elapsedRealtime() - startedAt
|
||||
delay(100)
|
||||
}
|
||||
}
|
||||
|
||||
fun startRecording() {
|
||||
if (!hasMicPermission()) {
|
||||
onRequestPermission()
|
||||
return
|
||||
}
|
||||
try {
|
||||
recorder.start(ctx)
|
||||
elapsedMs = 0L
|
||||
isRecording = true
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(ctx, "Couldn't start recording", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
fun stopRecording() {
|
||||
val bytes = recorder.stopAndReadBytes()
|
||||
isRecording = false
|
||||
if (bytes == null) {
|
||||
Toast.makeText(ctx, "Recording failed", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
onTakeRecorded(bytes, recorder.recordedMimeType)
|
||||
}
|
||||
}
|
||||
|
||||
val hasTake = voicePending != null || voicePersisted != null
|
||||
|
||||
// Persisted bytes lazy-load on demand (same pattern as the
|
||||
// attachment thumbnails) so the StateFlow never holds the blob.
|
||||
val lazyPersistedBytes by produceState<ByteArray?>(
|
||||
initialValue = null,
|
||||
key1 = voicePersisted?.id,
|
||||
) {
|
||||
value = if (voicePersisted != null && repository != null) {
|
||||
withContext(Dispatchers.IO) { repository.getAttachmentBytes(voicePersisted.id) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
val takeBytes: ByteArray? = if (voicePending != null) voicePendingBytes else lazyPersistedBytes
|
||||
val takeName: String =
|
||||
voicePending?.displayName ?: voicePersisted?.displayName ?: "voice_note.opus"
|
||||
val takeMime: String =
|
||||
voicePending?.mimeType ?: voicePersisted?.mimeType ?: "audio/ogg"
|
||||
val takeKey: Long = voicePending?.tempId ?: voicePersisted?.id ?: 0L
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 8.dp)
|
||||
.border(
|
||||
1.dp,
|
||||
MaterialTheme.colorScheme.outlineVariant,
|
||||
RoundedCornerShape(12.dp),
|
||||
)
|
||||
.background(
|
||||
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.45f),
|
||||
RoundedCornerShape(12.dp),
|
||||
)
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
) {
|
||||
when {
|
||||
isRecording -> Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.FiberManualRecord,
|
||||
contentDescription = null,
|
||||
tint = Color(0xFFD32F2F),
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(
|
||||
formatVoiceTime(elapsedMs),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
Spacer(Modifier.weight(1f))
|
||||
IconButton(onClick = { stopRecording() }) {
|
||||
Icon(
|
||||
Icons.Filled.Stop,
|
||||
contentDescription = "Stop recording",
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
IconButton(onClick = {
|
||||
recorder.cancel()
|
||||
isRecording = false
|
||||
}) {
|
||||
Icon(
|
||||
Icons.Filled.Close,
|
||||
contentDescription = "Discard recording",
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
hasTake && takeBytes == null -> Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(48.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(18.dp), strokeWidth = 2.dp)
|
||||
Text(
|
||||
"Loading audio\u2026",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
|
||||
hasTake && takeBytes != null -> VoicePlayerBar(
|
||||
bytes = takeBytes,
|
||||
mimeType = takeMime,
|
||||
sourceKey = takeKey,
|
||||
takeName = takeName,
|
||||
onDelete = onDeleteTake,
|
||||
onDownload = { saveVoiceTakeToDevice(ctx, securityManager, takeName, takeMime, takeBytes) },
|
||||
onRecordAgain = { startRecording() },
|
||||
)
|
||||
|
||||
else -> Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { startRecording() }
|
||||
.padding(vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.background(
|
||||
MaterialTheme.colorScheme.primary.copy(alpha = 0.12f),
|
||||
CircleShape,
|
||||
),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Mic,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(22.dp),
|
||||
)
|
||||
}
|
||||
Text(
|
||||
"Tap to record a voice note",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Media-player bar for a recorded take: play/pause + seek + elapsed /
|
||||
* total, plus download, re-record and delete actions. Backed by the
|
||||
* platform [MediaPlayer] — the bytes are written to a small cache file
|
||||
* (`cacheDir/voice_play/`) because MediaPlayer plays paths, not
|
||||
* in-memory blobs; the file is rewritten whenever a new take arrives
|
||||
* and is disposable cache data.
|
||||
*/
|
||||
@Composable
|
||||
private fun VoicePlayerBar(
|
||||
bytes: ByteArray,
|
||||
mimeType: String,
|
||||
sourceKey: Long,
|
||||
takeName: String,
|
||||
onDelete: () -> Unit,
|
||||
onDownload: () -> Unit,
|
||||
onRecordAgain: () -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
|
||||
// Materialise the take into a playable cache file.
|
||||
val playPath by produceState<String?>(
|
||||
initialValue = null,
|
||||
key1 = sourceKey,
|
||||
key2 = bytes,
|
||||
) {
|
||||
value = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
val dir = File(ctx.cacheDir, "voice_play").apply { mkdirs() }
|
||||
val ext = if (mimeType == "audio/ogg") "opus" else "m4a"
|
||||
val file = File(dir, "take_$sourceKey.$ext")
|
||||
file.writeBytes(bytes)
|
||||
file.absolutePath
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
var player by remember(sourceKey) { mutableStateOf<MediaPlayer?>(null) }
|
||||
var prepared by remember(sourceKey) { mutableStateOf(false) }
|
||||
var isPlaying by remember(sourceKey) { mutableStateOf(false) }
|
||||
var positionMs by remember(sourceKey) { mutableStateOf(0L) }
|
||||
var durationMs by remember(sourceKey) { mutableStateOf(0L) }
|
||||
var dragMs by remember(sourceKey) { mutableStateOf<Float?>(null) }
|
||||
|
||||
DisposableEffect(playPath) {
|
||||
val path = playPath
|
||||
if (path == null) {
|
||||
onDispose { }
|
||||
} else {
|
||||
val mp = MediaPlayer()
|
||||
player = mp
|
||||
mp.setOnPreparedListener {
|
||||
durationMs = it.duration.toLong()
|
||||
prepared = true
|
||||
}
|
||||
mp.setOnCompletionListener {
|
||||
isPlaying = false
|
||||
positionMs = durationMs
|
||||
}
|
||||
mp.setOnErrorListener { _, _, _ -> true }
|
||||
runCatching {
|
||||
mp.setDataSource(path)
|
||||
mp.prepareAsync()
|
||||
}
|
||||
onDispose {
|
||||
runCatching { mp.release() }
|
||||
player = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the slider in step while playing.
|
||||
LaunchedEffect(isPlaying, prepared) {
|
||||
if (!isPlaying || !prepared) return@LaunchedEffect
|
||||
while (isPlaying) {
|
||||
player?.let { positionMs = it.currentPosition.toLong() }
|
||||
delay(200)
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
val mp = player ?: return@IconButton
|
||||
if (!prepared) return@IconButton
|
||||
if (mp.isPlaying) {
|
||||
mp.pause()
|
||||
isPlaying = false
|
||||
} else {
|
||||
if (positionMs >= durationMs && durationMs > 0) {
|
||||
mp.seekTo(0)
|
||||
positionMs = 0
|
||||
}
|
||||
mp.start()
|
||||
isPlaying = true
|
||||
}
|
||||
},
|
||||
enabled = prepared,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (isPlaying) Icons.Filled.Pause else Icons.Filled.PlayArrow,
|
||||
contentDescription = if (isPlaying) "Pause" else "Play",
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = formatVoiceTime((dragMs ?: positionMs.toFloat()).toLong()),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
)
|
||||
Slider(
|
||||
value = (dragMs ?: positionMs.toFloat()).coerceIn(
|
||||
0f,
|
||||
durationMs.coerceAtLeast(1).toFloat(),
|
||||
),
|
||||
onValueChange = { dragMs = it },
|
||||
onValueChangeFinished = {
|
||||
val target = dragMs
|
||||
if (target != null) {
|
||||
dragMs = null
|
||||
val seek = target.toInt()
|
||||
player?.let { mp ->
|
||||
if (prepared) {
|
||||
mp.seekTo(seek)
|
||||
positionMs = seek.toLong()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..durationMs.coerceAtLeast(1).toFloat(),
|
||||
enabled = prepared,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = 4.dp),
|
||||
)
|
||||
Text(
|
||||
text = formatVoiceTime(durationMs),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
)
|
||||
// Download = save a copy to the system Downloads folder
|
||||
// (pre-Q devices get the share sheet, which reaches the
|
||||
// same destinations).
|
||||
IconButton(onClick = onDownload) {
|
||||
Icon(
|
||||
Icons.Filled.Download,
|
||||
contentDescription = "Download recording",
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onRecordAgain) {
|
||||
Icon(
|
||||
Icons.Filled.Mic,
|
||||
contentDescription = "Re-record (replaces current take)",
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onDelete) {
|
||||
Icon(
|
||||
Icons.Filled.Delete,
|
||||
contentDescription = "Delete recording",
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = takeName,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the take to the system Downloads folder via MediaStore (API 29+,
|
||||
* no storage permission needed). On API 26–28 — where MediaStore
|
||||
* Downloads doesn't exist — fall back to the v0.3.1.3 FileProvider
|
||||
* outbox + share sheet, which reaches the same destinations plus
|
||||
* "Save to device" handlers.
|
||||
*/
|
||||
private fun saveVoiceTakeToDevice(
|
||||
ctx: Context,
|
||||
securityManager: SecurityManager?,
|
||||
displayName: String,
|
||||
mimeType: String,
|
||||
bytes: ByteArray,
|
||||
) {
|
||||
val safeName = displayName
|
||||
.replace(Regex("[/\\\\:*?\"<>|]"), "_")
|
||||
.ifEmpty { "voice_note.opus" }
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val saved = runCatching {
|
||||
val values = ContentValues().apply {
|
||||
put(MediaStore.Downloads.DISPLAY_NAME, safeName)
|
||||
put(MediaStore.Downloads.MIME_TYPE, mimeType)
|
||||
put(
|
||||
MediaStore.Downloads.RELATIVE_PATH,
|
||||
Environment.DIRECTORY_DOWNLOADS,
|
||||
)
|
||||
}
|
||||
val uri = ctx.contentResolver.insert(
|
||||
MediaStore.Downloads.EXTERNAL_CONTENT_URI,
|
||||
values,
|
||||
) ?: return@runCatching false
|
||||
ctx.contentResolver.openOutputStream(uri)?.use { out ->
|
||||
out.write(bytes)
|
||||
} ?: return@runCatching false
|
||||
true
|
||||
}.getOrDefault(false)
|
||||
if (saved) {
|
||||
Toast.makeText(ctx, "Saved to Downloads", Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
// MediaStore refused (provider hiccup) — fall through to the
|
||||
// share sheet as the last resort.
|
||||
}
|
||||
|
||||
runCatching {
|
||||
val outbox = File(ctx.cacheDir, "open_outbox").apply { mkdirs() }
|
||||
val tmp = File(outbox, "dl_${System.currentTimeMillis()}_$safeName")
|
||||
tmp.writeBytes(bytes)
|
||||
val uri = FileProvider.getUriForFile(ctx, "${ctx.packageName}.fileprovider", tmp)
|
||||
val send = Intent(Intent.ACTION_SEND).apply {
|
||||
type = mimeType
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
// Auto-Lock = Immediate must not fire while the chooser is up
|
||||
// (same v0.3.4.0 hotfix as the attachment viewer).
|
||||
securityManager?.beginExternalActivity()
|
||||
ctx.startActivity(Intent.createChooser(send, "Save recording"))
|
||||
}.onFailure {
|
||||
Toast.makeText(ctx, "Couldn't save recording", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
/** ms → "m:ss" (or "h:mm:ss" past an hour). */
|
||||
internal fun formatVoiceTime(ms: Long): String {
|
||||
val totalSec = ms / 1000
|
||||
val h = totalSec / 3600
|
||||
val m = (totalSec % 3600) / 60
|
||||
val s = totalSec % 60
|
||||
return if (h > 0) {
|
||||
String.format(Locale.US, "%d:%02d:%02d", h, m, s)
|
||||
} else {
|
||||
String.format(Locale.US, "%d:%02d", m, s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package org.incido.compose.ui.editor
|
||||
|
||||
import android.content.Context
|
||||
import android.media.MediaRecorder
|
||||
import android.os.Build
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* v0.4.2.0 — thin MediaRecorder wrapper for voice notes.
|
||||
*
|
||||
* Records Opus audio in an Ogg container (`.opus`, mime `audio/ogg`)
|
||||
* at 32 kbps, single channel, 48 kHz — tiny files, excellent speech
|
||||
* quality, and produced by the platform MediaRecorder with no extra
|
||||
* dependencies (the app stays dependency-light per Development Plan
|
||||
* privacy/offline rules). Opus-in-Ogg output via MediaRecorder is
|
||||
* public API only from API 29, so API 26–28 devices keep the previous
|
||||
* AAC/MP4 path (`.m4a`, mime `audio/mp4`); [recordedMimeType] reports
|
||||
* which container [start] actually used.
|
||||
*
|
||||
* Note: the MediaRecorder surface exposes no encoder knobs for Opus
|
||||
* frame size or complexity, so both stay at platform defaults (Opus
|
||||
* on Android encodes 20 ms frames); hitting 120 ms frames /
|
||||
* complexity 10 would require bundling native libopus — deferred.
|
||||
*
|
||||
* The take lands in a temp file under `cacheDir/voice_rec/`; the
|
||||
* caller reads it back as a [ByteArray] on [stopAndReadBytes] and the
|
||||
* temp file is deleted immediately — the bytes then ride the ordinary
|
||||
* attachment pipeline into ObjectBox (same lifecycle as the camera
|
||||
* outbox from v0.3.1.0).
|
||||
*
|
||||
* Not thread-safe: drive it from the main thread only.
|
||||
*/
|
||||
class VoiceRecorder {
|
||||
|
||||
private var recorder: MediaRecorder? = null
|
||||
private var outFile: File? = null
|
||||
private var opus = false
|
||||
|
||||
/** True between a successful [start] and the matching stop/cancel. */
|
||||
val isRecording: Boolean get() = recorder != null
|
||||
|
||||
/**
|
||||
* Mime type of the container [start] actually used — `audio/ogg`
|
||||
* (Opus) on API 29+, `audio/mp4` (AAC) on API 26–28. Valid after
|
||||
* any successful [start]; callers use it to tag the finished take.
|
||||
*/
|
||||
val recordedMimeType: String get() = if (opus) "audio/ogg" else "audio/mp4"
|
||||
|
||||
/**
|
||||
* Start capturing from the mic into a fresh temp file.
|
||||
* Throws [IOException] / [RuntimeException] when the mic is busy,
|
||||
* the permission was revoked mid-session, or the device has none —
|
||||
* callers should catch and surface a snackbar.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
fun start(context: Context) {
|
||||
if (recorder != null) return
|
||||
// Opus-in-Ogg via MediaRecorder is public API only from API 29
|
||||
// (minSdk is 26), so older devices keep the AAC/MP4 path.
|
||||
val useOpus = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
val dir = File(context.cacheDir, "voice_rec").apply { mkdirs() }
|
||||
val file = File(
|
||||
dir,
|
||||
"take_${System.currentTimeMillis()}" + if (useOpus) ".opus" else ".m4a",
|
||||
)
|
||||
val rec = MediaRecorder()
|
||||
try {
|
||||
rec.apply {
|
||||
setAudioSource(MediaRecorder.AudioSource.MIC)
|
||||
if (useOpus) {
|
||||
setOutputFormat(MediaRecorder.OutputFormat.OGG)
|
||||
setAudioEncoder(MediaRecorder.AudioEncoder.OPUS)
|
||||
setAudioEncodingBitRate(32_000) // 32 kbps
|
||||
setAudioChannels(1) // single channel
|
||||
setAudioSamplingRate(48_000) // Opus native rate
|
||||
} else {
|
||||
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
||||
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
||||
setAudioEncodingBitRate(96_000)
|
||||
setAudioSamplingRate(44_100)
|
||||
}
|
||||
setOutputFile(file.absolutePath)
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
recorder = rec
|
||||
outFile = file
|
||||
opus = useOpus
|
||||
} catch (e: Exception) {
|
||||
rec.release()
|
||||
file.delete()
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the capture, read the recorded bytes, and delete the temp
|
||||
* file. Returns `null` when nothing was recorded or the encoder
|
||||
* failed. Always safe to call — a no-op while idle.
|
||||
*/
|
||||
fun stopAndReadBytes(): ByteArray? {
|
||||
val rec = recorder ?: return null
|
||||
recorder = null
|
||||
val file = outFile
|
||||
outFile = null
|
||||
return try {
|
||||
rec.stop()
|
||||
val bytes = file?.readBytes()
|
||||
bytes?.takeIf { it.isNotEmpty() }
|
||||
} catch (e: RuntimeException) {
|
||||
null
|
||||
} finally {
|
||||
rec.release()
|
||||
file?.delete()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandon the in-flight take without reading it (the ✕ while
|
||||
* recording). Always safe to call — a no-op while idle.
|
||||
*/
|
||||
fun cancel() {
|
||||
val rec = recorder ?: return
|
||||
recorder = null
|
||||
val file = outFile
|
||||
outFile = null
|
||||
runCatching { rec.stop() } // stop() throws if nothing was captured
|
||||
rec.release()
|
||||
file?.delete()
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.DeleteForever
|
||||
import androidx.compose.material.icons.filled.Lock
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.Mic
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.PhotoCamera
|
||||
import androidx.compose.material.icons.filled.Restore
|
||||
@@ -444,8 +445,13 @@ private fun NoteCard(
|
||||
// v0.3.8.0: task / shopping lists render marker-free on cards —
|
||||
// header line becomes the title, items show as clean "Name ×qty @$X"
|
||||
// text. The checkbox state lives in the summary row below instead.
|
||||
val (title, body) = if (note.type == NoteType.TEXT) Note.titleAndBody(note.content)
|
||||
else Note.cardPresentation(note.content, note.type)
|
||||
// v0.4.2.0: voice notes carry a plain prose body (title = first
|
||||
// line), so they split like TEXT — the cardPresentation list parser
|
||||
// would mangle their content.
|
||||
val (title, body) =
|
||||
if (note.type == NoteType.TEXT || note.type == NoteType.VOICE_NOTE)
|
||||
Note.titleAndBody(note.content)
|
||||
else Note.cardPresentation(note.content, note.type)
|
||||
// Drafts with no title introduce themselves by kind — "Shopping
|
||||
// List - (draft)" beats a bare "Untitled" in the Drafts view. The
|
||||
// stored content is untouched; this is display-only, so typing a
|
||||
@@ -606,6 +612,27 @@ private fun NoteCard(
|
||||
)
|
||||
}
|
||||
}
|
||||
if (note.type == NoteType.VOICE_NOTE) {
|
||||
// v0.4.2.0: voice notes carry a mic badge so the
|
||||
// kind is recognisable on the card even when the
|
||||
// body is empty (the take itself is an audio
|
||||
// attachment, not visible as a thumbnail).
|
||||
Spacer(modifier = Modifier.padding(top = 4.dp))
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(
|
||||
Icons.Default.Mic,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(14.dp),
|
||||
tint = secondaryColor,
|
||||
)
|
||||
Spacer(Modifier.size(6.dp))
|
||||
Text(
|
||||
text = note.type.displayName,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = secondaryColor,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (note.hashtags.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.padding(top = 4.dp))
|
||||
HashtagRow(
|
||||
|
||||
@@ -354,7 +354,7 @@ class SettingsViewModel(
|
||||
/** The version string baked into backup payloads and shown on
|
||||
* the About card. Mirrors `app/build.gradle.kts` `versionName`
|
||||
* — if you bump one, bump both. */
|
||||
const val APP_VERSION = "0.4.1.1"
|
||||
const val APP_VERSION = "0.4.2.0"
|
||||
|
||||
val Factory: ViewModelProvider.Factory = viewModelFactory {
|
||||
initializer {
|
||||
|
||||
Reference in new issue
Block a user