11package com.therealaleph.mhrv.ui
22
3+ import android.widget.Toast
34import androidx.compose.animation.AnimatedVisibility
45import androidx.compose.foundation.background
56import androidx.compose.foundation.layout.*
@@ -9,6 +10,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
910import androidx.compose.foundation.rememberScrollState
1011import androidx.compose.foundation.shape.RoundedCornerShape
1112import androidx.compose.foundation.text.KeyboardOptions
13+ import androidx.compose.foundation.text.selection.SelectionContainer
1214import androidx.compose.foundation.verticalScroll
1315import androidx.compose.material.icons.Icons
1416import androidx.compose.material.icons.filled.CheckCircle
@@ -23,7 +25,9 @@ import androidx.compose.runtime.saveable.rememberSaveable
2325import androidx.compose.ui.Alignment
2426import androidx.compose.ui.Modifier
2527import androidx.compose.ui.draw.clip
28+ import androidx.compose.ui.platform.LocalClipboardManager
2629import androidx.compose.ui.platform.LocalContext
30+ import androidx.compose.ui.text.AnnotatedString
2731import androidx.compose.ui.text.font.FontFamily
2832import androidx.compose.ui.text.input.ImeAction
2933import androidx.compose.ui.text.input.KeyboardType
@@ -1231,6 +1235,8 @@ private fun LiveLogPane() {
12311235 val lines = remember { mutableStateListOf<String >() }
12321236 val listState = rememberLazyListState()
12331237 val scope = rememberCoroutineScope()
1238+ val clipboard = LocalClipboardManager .current
1239+ val ctx = LocalContext .current
12341240
12351241 // Pull from the ring buffer periodically. We pull even while the
12361242 // section is collapsed (cheap), so re-expanding shows fresh tail.
@@ -1260,24 +1266,41 @@ private fun LiveLogPane() {
12601266 color = MaterialTheme .colorScheme.onSurfaceVariant,
12611267 modifier = Modifier .weight(1f ),
12621268 )
1263- TextButton (onClick = { lines.clear() }) { Text (" Clear" ) }
1269+ TextButton (
1270+ enabled = lines.isNotEmpty(),
1271+ onClick = {
1272+ clipboard.setText(AnnotatedString (lines.joinToString(" \n " )))
1273+ Toast .makeText(
1274+ ctx,
1275+ ctx.getString(R .string.snack_logs_copied),
1276+ Toast .LENGTH_SHORT ,
1277+ ).show()
1278+ },
1279+ ) { Text (stringResource(R .string.btn_copy)) }
1280+ TextButton (onClick = { lines.clear() }) { Text (stringResource(R .string.btn_clear)) }
12641281 }
12651282 Surface (
12661283 color = MaterialTheme .colorScheme.surfaceVariant,
12671284 shape = RoundedCornerShape (8 .dp),
12681285 modifier = Modifier .fillMaxWidth().heightIn(min = 160 .dp, max = 320 .dp),
12691286 ) {
1270- LazyColumn (
1271- state = listState,
1272- modifier = Modifier .padding(8 .dp),
1273- ) {
1274- items(lines) { line ->
1275- Text (
1276- line,
1277- style = MaterialTheme .typography.bodySmall,
1278- fontFamily = FontFamily .Monospace ,
1279- fontSize = 11 .sp,
1280- )
1287+ // SelectionContainer makes log lines selectable for manual
1288+ // copy of partial ranges. Cross-line selection works within the
1289+ // currently rendered window; for "copy everything" the Copy
1290+ // button above is the reliable path.
1291+ SelectionContainer {
1292+ LazyColumn (
1293+ state = listState,
1294+ modifier = Modifier .padding(8 .dp),
1295+ ) {
1296+ items(lines) { line ->
1297+ Text (
1298+ line,
1299+ style = MaterialTheme .typography.bodySmall,
1300+ fontFamily = FontFamily .Monospace ,
1301+ fontSize = 11 .sp,
1302+ )
1303+ }
12811304 }
12821305 }
12831306 }
0 commit comments