Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions android/app/src/main/java/com/therealaleph/mhrv/ui/HomeScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.therealaleph.mhrv.ui

import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
Expand All @@ -9,6 +10,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
Expand All @@ -23,7 +25,9 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
Expand Down Expand Up @@ -1231,6 +1235,8 @@ private fun LiveLogPane() {
val lines = remember { mutableStateListOf<String>() }
val listState = rememberLazyListState()
val scope = rememberCoroutineScope()
val clipboard = LocalClipboardManager.current
val ctx = LocalContext.current

// Pull from the ring buffer periodically. We pull even while the
// section is collapsed (cheap), so re-expanding shows fresh tail.
Expand Down Expand Up @@ -1260,24 +1266,41 @@ private fun LiveLogPane() {
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.weight(1f),
)
TextButton(onClick = { lines.clear() }) { Text("Clear") }
TextButton(
enabled = lines.isNotEmpty(),
onClick = {
clipboard.setText(AnnotatedString(lines.joinToString("\n")))
Toast.makeText(
ctx,
ctx.getString(R.string.snack_logs_copied),
Toast.LENGTH_SHORT,
).show()
},
) { Text(stringResource(R.string.btn_copy)) }
TextButton(onClick = { lines.clear() }) { Text(stringResource(R.string.btn_clear)) }
}
Surface(
color = MaterialTheme.colorScheme.surfaceVariant,
shape = RoundedCornerShape(8.dp),
modifier = Modifier.fillMaxWidth().heightIn(min = 160.dp, max = 320.dp),
) {
LazyColumn(
state = listState,
modifier = Modifier.padding(8.dp),
) {
items(lines) { line ->
Text(
line,
style = MaterialTheme.typography.bodySmall,
fontFamily = FontFamily.Monospace,
fontSize = 11.sp,
)
// SelectionContainer makes log lines selectable for manual
// copy of partial ranges. Cross-line selection works within the
// currently rendered window; for "copy everything" the Copy
// button above is the reliable path.
SelectionContainer {
LazyColumn(
state = listState,
modifier = Modifier.padding(8.dp),
) {
items(lines) { line ->
Text(
line,
style = MaterialTheme.typography.bodySmall,
fontFamily = FontFamily.Monospace,
fontSize = 11.sp,
)
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="btn_test">تست</string>
<string name="btn_add">افزودن</string>
<string name="btn_clear">پاک</string>
<string name="btn_copy">کپی</string>
<string name="btn_install">نصب</string>
<string name="btn_cancel">انصراف</string>

Expand Down Expand Up @@ -78,6 +79,7 @@
<string name="snack_google_ip_updated">google_ip به %1$s به‌روزرسانی شد</string>
<string name="snack_google_ip_current">google_ip قبلاً به‌روز است (%1$s)</string>
<string name="snack_dns_lookup_failed">خطای DNS — اتصال شبکه را بررسی کنید</string>
<string name="snack_logs_copied">لاگ‌ها در کلیپ‌بورد کپی شدند</string>

<!-- Usage today card -->
<string name="sec_usage_today">مصرف امروز (تخمینی)</string>
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="btn_test">Test</string>
<string name="btn_add">Add</string>
<string name="btn_clear">Clear</string>
<string name="btn_copy">Copy</string>
<string name="btn_install">Install</string>
<string name="btn_cancel">Cancel</string>

Expand Down Expand Up @@ -78,6 +79,7 @@
<string name="snack_google_ip_updated">google_ip updated to %1$s</string>
<string name="snack_google_ip_current">google_ip already current (%1$s)</string>
<string name="snack_dns_lookup_failed">DNS lookup failed — check network</string>
<string name="snack_logs_copied">Logs copied to clipboard</string>

<!-- Usage today card -->
<string name="sec_usage_today">Usage today (estimated)</string>
Expand Down