Skip to content

Commit bd602a3

Browse files
committed
Add a button to copy logs
1 parent 55ad4d7 commit bd602a3

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

  • llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/screens

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/screens/LogsScreen.kt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88

99
package com.example.executorchllamademo.ui.screens
1010

11+
import android.widget.Toast
1112
import androidx.compose.foundation.background
1213
import androidx.compose.foundation.layout.Column
1314
import androidx.compose.foundation.layout.fillMaxSize
1415
import androidx.compose.foundation.layout.fillMaxWidth
1516
import androidx.compose.foundation.layout.padding
1617
import androidx.compose.foundation.lazy.LazyColumn
1718
import androidx.compose.foundation.lazy.items
19+
import androidx.compose.foundation.text.selection.SelectionContainer
1820
import androidx.compose.material.icons.Icons
1921
import androidx.compose.material.icons.filled.Delete
2022
import androidx.compose.material.icons.filled.Warning
23+
import androidx.compose.material.icons.outlined.ContentCopy
2124
import androidx.compose.material3.AlertDialog
2225
import androidx.compose.material3.Icon
2326
import androidx.compose.material3.IconButton
@@ -33,8 +36,11 @@ import androidx.compose.runtime.setValue
3336
import androidx.compose.ui.Alignment
3437
import androidx.lifecycle.Lifecycle
3538
import androidx.lifecycle.LifecycleEventObserver
39+
import androidx.compose.ui.platform.LocalClipboardManager
40+
import androidx.compose.ui.platform.LocalContext
3641
import androidx.compose.ui.platform.LocalLifecycleOwner
3742
import androidx.compose.ui.Modifier
43+
import androidx.compose.ui.text.AnnotatedString
3844
import androidx.compose.ui.text.font.FontWeight
3945
import androidx.compose.ui.unit.dp
4046
import androidx.compose.ui.unit.sp
@@ -50,6 +56,8 @@ fun LogsScreen(
5056
var showClearDialog by remember { mutableStateOf(false) }
5157
val lifecycleOwner = LocalLifecycleOwner.current
5258
val appColors = LocalAppColors.current
59+
val clipboardManager = LocalClipboardManager.current
60+
val context = LocalContext.current
5361

5462
// Load logs on resume (like the old onResume behavior)
5563
DisposableEffect(lifecycleOwner) {
@@ -86,6 +94,18 @@ fun LogsScreen(
8694
modifier = Modifier.weight(1f)
8795
)
8896

97+
IconButton(onClick = {
98+
val allLogs = viewModel.logs.joinToString("\n") { it.getFormattedLog() }
99+
clipboardManager.setText(AnnotatedString(allLogs))
100+
Toast.makeText(context, "Logs copied to clipboard", Toast.LENGTH_SHORT).show()
101+
}) {
102+
Icon(
103+
imageVector = Icons.Outlined.ContentCopy,
104+
contentDescription = "Copy logs",
105+
tint = appColors.textOnNavBar
106+
)
107+
}
108+
89109
IconButton(onClick = { showClearDialog = true }) {
90110
Icon(
91111
imageVector = Icons.Filled.Delete,
@@ -96,13 +116,15 @@ fun LogsScreen(
96116
}
97117

98118
// Logs list
99-
LazyColumn(
100-
modifier = Modifier
101-
.fillMaxSize()
102-
.padding(8.dp)
103-
) {
104-
items(viewModel.logs) { log ->
105-
LogItem(log = log)
119+
SelectionContainer {
120+
LazyColumn(
121+
modifier = Modifier
122+
.fillMaxSize()
123+
.padding(8.dp)
124+
) {
125+
items(viewModel.logs) { log ->
126+
LogItem(log = log)
127+
}
106128
}
107129
}
108130
}

0 commit comments

Comments
 (0)