@@ -1,6 +1,7 @@
11package soy.iko.opencode.ui.settings
22
33import android.content.Intent
4+import android.util.Log
45import androidx.compose.foundation.clickable
56import androidx.compose.foundation.layout.Arrangement
67import androidx.compose.foundation.layout.Column
@@ -33,6 +34,7 @@ import androidx.compose.runtime.getValue
3334import androidx.compose.runtime.mutableStateOf
3435import androidx.compose.runtime.remember
3536import androidx.compose.runtime.rememberCoroutineScope
37+import androidx.compose.runtime.saveable.rememberSaveable
3638import androidx.compose.runtime.setValue
3739import kotlinx.coroutines.Dispatchers
3840import kotlinx.coroutines.launch
@@ -57,7 +59,7 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
5759 val context = LocalContext.current
5860 val logger = remember { CrashLogger.get(context) }
5961 val reports by logger.reports.collectAsStateWithLifecycle()
60− var viewing by remember { mutableStateOf<String?>(null) }
62+ var viewing by rememberSaveable { mutableStateOf<String?>(null) }
6163 val shareScope = rememberCoroutineScope()
6264 val shareLabel = stringResource(R.string.share)
6365
@@ -73,7 +75,10 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
7375 actions = {
7476 if (reports.isNotEmpty()) {
7577 IconButton(onClick = {
76− shareScope.launch(Dispatchers.IO) { runCatching { logger.clearAll() } }
78+ shareScope.launch(Dispatchers.IO) {
79+ runCatching { logger.clearAll() }
80+ .onFailure { Log.w("Diagnostics", "Failed to clear crash reports", it) }
81+ }
7782 }) {
7883 Icon(Icons.Filled.DeleteSweep, contentDescription = stringResource(R.string.clear_all))
7984 }
@@ -139,6 +144,7 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
139144 putExtra(Intent.EXTRA_TEXT, content)
140145 }
141146 runCatching { context.startActivity(Intent.createChooser(send, shareLabel)) }
147+ .onFailure { Log.w("Diagnostics", "Failed to share crash report", it) }
142148 }
143149 }) {
144150 Icon(Icons.Filled.Share, contentDescription = stringResource(R.string.share))
@@ -173,10 +179,14 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
173179 putExtra(Intent.EXTRA_TEXT, content.orEmpty())
174180 }
175181 runCatching { context.startActivity(Intent.createChooser(send, shareLabel2)) }
182+ .onFailure { Log.w("Diagnostics", "Failed to share crash report", it) }
176183 }) { Text(stringResource(R.string.share)) }
177184 Spacer(Modifier.size(8.dp))
178185 TextButton(onClick = {
179− shareScope.launch(Dispatchers.IO) { runCatching { logger.deleteReport(reportName) } }
186+ shareScope.launch(Dispatchers.IO) {
187+ runCatching { logger.deleteReport(reportName) }
188+ .onFailure { Log.w("Diagnostics", "Failed to delete crash report", it) }
189+ }
180190 viewing = null
181191 }) { Text(stringResource(R.string.delete)) }
182192 }