@@ -1,6 +1,7 @@
1package soy.iko.opencode.ui.settings
1package soy.iko.opencode.ui.settings
3import android.content.Intent
3import android.content.Intent
4+import android.util.Log
4import androidx.compose.foundation.clickable
5import androidx.compose.foundation.clickable
5import androidx.compose.foundation.layout.Arrangement
6import androidx.compose.foundation.layout.Arrangement
6import androidx.compose.foundation.layout.Column
7import androidx.compose.foundation.layout.Column
@@ -33,6 +34,7 @@ import androidx.compose.runtime.getValue
33import androidx.compose.runtime.mutableStateOf
34import androidx.compose.runtime.mutableStateOf
34import androidx.compose.runtime.remember
35import androidx.compose.runtime.remember
35import androidx.compose.runtime.rememberCoroutineScope
36import androidx.compose.runtime.rememberCoroutineScope
37+import androidx.compose.runtime.saveable.rememberSaveable
36import androidx.compose.runtime.setValue
38import androidx.compose.runtime.setValue
37import kotlinx.coroutines.Dispatchers
39import kotlinx.coroutines.Dispatchers
38import kotlinx.coroutines.launch
40import kotlinx.coroutines.launch
@@ -57,7 +59,7 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
57 val context = LocalContext.current
59 val context = LocalContext.current
58 val logger = remember { CrashLogger.get(context) }
60 val logger = remember { CrashLogger.get(context) }
59 val reports by logger.reports.collectAsStateWithLifecycle()
61 val reports by logger.reports.collectAsStateWithLifecycle()
60− var viewing by remember { mutableStateOf<String?>(null) }
62+ var viewing by rememberSaveable { mutableStateOf<String?>(null) }
61 val shareScope = rememberCoroutineScope()
63 val shareScope = rememberCoroutineScope()
62 val shareLabel = stringResource(R.string.share)
64 val shareLabel = stringResource(R.string.share)
@@ -73,7 +75,10 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
73 actions = {
75 actions = {
74 if (reports.isNotEmpty()) {
76 if (reports.isNotEmpty()) {
75 IconButton(onClick = {
77 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) }
78 Icon(Icons.Filled.DeleteSweep, contentDescription = stringResource(R.string.clear_all))
83 Icon(Icons.Filled.DeleteSweep, contentDescription = stringResource(R.string.clear_all))
@@ -139,6 +144,7 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
139 putExtra(Intent.EXTRA_TEXT, content)
144 putExtra(Intent.EXTRA_TEXT, content)
141 runCatching { context.startActivity(Intent.createChooser(send, shareLabel)) }
146 runCatching { context.startActivity(Intent.createChooser(send, shareLabel)) }
147+ .onFailure { Log.w("Diagnostics", "Failed to share crash report", it) }
144 Icon(Icons.Filled.Share, contentDescription = stringResource(R.string.share))
150 Icon(Icons.Filled.Share, contentDescription = stringResource(R.string.share))
@@ -173,10 +179,14 @@ fun DiagnosticsScreen(onBack: () -> Unit) {
173 putExtra(Intent.EXTRA_TEXT, content.orEmpty())
179 putExtra(Intent.EXTRA_TEXT, content.orEmpty())
175 runCatching { context.startActivity(Intent.createChooser(send, shareLabel2)) }
181 runCatching { context.startActivity(Intent.createChooser(send, shareLabel2)) }
182+ .onFailure { Log.w("Diagnostics", "Failed to share crash report", it) }
176 }) { Text(stringResource(R.string.share)) }
183 }) { Text(stringResource(R.string.share)) }
177 Spacer(Modifier.size(8.dp))
184 Spacer(Modifier.size(8.dp))
178 TextButton(onClick = {
185 TextButton(onClick = {
186+ shareScope.launch(Dispatchers.IO) {
179− shareScope.launch(Dispatchers.IO) { runCatching { logger.deleteReport(reportName) } }
187+ runCatching { logger.deleteReport(reportName) }
188+ .onFailure { Log.w("Diagnostics", "Failed to delete crash report", it) }
180 viewing = null
190 viewing = null
181 }) { Text(stringResource(R.string.delete)) }
191 }) { Text(stringResource(R.string.delete)) }