2022-10-16 22:35:20 +02:00
|
|
|
package eu.kanade.presentation.crash
|
|
|
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
import androidx.compose.material.icons.outlined.BugReport
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.draw.clip
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
import androidx.compose.ui.res.stringResource
|
2022-12-30 23:14:29 -05:00
|
|
|
import eu.kanade.presentation.components.InfoScaffold
|
|
|
|
import eu.kanade.presentation.theme.TachiyomiTheme
|
|
|
|
import eu.kanade.presentation.util.ThemePreviews
|
2022-11-13 18:11:51 +01:00
|
|
|
import eu.kanade.presentation.util.padding
|
2022-10-16 22:35:20 +02:00
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
|
import eu.kanade.tachiyomi.util.CrashLogUtil
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun CrashScreen(
|
|
|
|
exception: Throwable?,
|
|
|
|
onRestartClick: () -> Unit,
|
|
|
|
) {
|
|
|
|
val scope = rememberCoroutineScope()
|
|
|
|
val context = LocalContext.current
|
2022-12-30 23:14:29 -05:00
|
|
|
|
|
|
|
InfoScaffold(
|
|
|
|
icon = Icons.Outlined.BugReport,
|
|
|
|
headingText = stringResource(R.string.crash_screen_title),
|
|
|
|
subtitleText = stringResource(R.string.crash_screen_description, stringResource(R.string.app_name)),
|
|
|
|
acceptText = stringResource(R.string.pref_dump_crash_logs),
|
|
|
|
onAcceptClick = {
|
|
|
|
scope.launch {
|
|
|
|
CrashLogUtil(context).dumpLogs()
|
2022-10-16 22:35:20 +02:00
|
|
|
}
|
|
|
|
},
|
2022-12-30 23:14:29 -05:00
|
|
|
rejectText = stringResource(R.string.crash_screen_restart_application),
|
|
|
|
onRejectClick = onRestartClick,
|
|
|
|
) {
|
|
|
|
Box(
|
2022-10-16 22:35:20 +02:00
|
|
|
modifier = Modifier
|
2022-12-30 23:14:29 -05:00
|
|
|
.padding(vertical = MaterialTheme.padding.small)
|
|
|
|
.clip(MaterialTheme.shapes.small)
|
|
|
|
.fillMaxWidth()
|
|
|
|
.background(MaterialTheme.colorScheme.surfaceVariant),
|
2022-10-16 22:35:20 +02:00
|
|
|
) {
|
|
|
|
Text(
|
2022-12-30 23:14:29 -05:00
|
|
|
text = exception.toString(),
|
2022-10-16 22:35:20 +02:00
|
|
|
modifier = Modifier
|
2022-12-30 23:14:29 -05:00
|
|
|
.padding(all = MaterialTheme.padding.small),
|
|
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
2022-10-16 22:35:20 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-30 23:14:29 -05:00
|
|
|
|
|
|
|
@ThemePreviews
|
|
|
|
@Composable
|
|
|
|
private fun CrashScreenPreview() {
|
|
|
|
TachiyomiTheme {
|
|
|
|
CrashScreen(exception = RuntimeException("Dummy")) {}
|
|
|
|
}
|
|
|
|
}
|