|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025-2026 NewPipe e.V. <https://newpipe-ev.de> |
| 3 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +package org.schabi.newpipe.ui.screens |
| 7 | + |
| 8 | +import android.content.res.Configuration |
| 9 | +import androidx.compose.foundation.horizontalScroll |
| 10 | +import androidx.compose.foundation.layout.Column |
| 11 | +import androidx.compose.foundation.layout.Row |
| 12 | +import androidx.compose.foundation.layout.Spacer |
| 13 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 14 | +import androidx.compose.foundation.layout.height |
| 15 | +import androidx.compose.foundation.layout.padding |
| 16 | +import androidx.compose.foundation.rememberScrollState |
| 17 | +import androidx.compose.foundation.text.selection.SelectionContainer |
| 18 | +import androidx.compose.foundation.verticalScroll |
| 19 | +import androidx.compose.material3.Button |
| 20 | +import androidx.compose.material3.MaterialTheme |
| 21 | +import androidx.compose.material3.OutlinedTextField |
| 22 | +import androidx.compose.material3.Surface |
| 23 | +import androidx.compose.material3.Text |
| 24 | +import androidx.compose.runtime.Composable |
| 25 | +import androidx.compose.runtime.getValue |
| 26 | +import androidx.compose.runtime.mutableStateOf |
| 27 | +import androidx.compose.runtime.saveable.rememberSaveable |
| 28 | +import androidx.compose.runtime.setValue |
| 29 | +import androidx.compose.ui.Modifier |
| 30 | +import androidx.compose.ui.res.stringResource |
| 31 | +import androidx.compose.ui.text.font.FontFamily |
| 32 | +import androidx.compose.ui.text.font.FontWeight |
| 33 | +import androidx.compose.ui.text.style.TextAlign |
| 34 | +import androidx.compose.ui.tooling.preview.Preview |
| 35 | +import androidx.compose.ui.unit.dp |
| 36 | +import org.schabi.newpipe.R |
| 37 | +import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar |
| 38 | +import org.schabi.newpipe.ui.theme.AppTheme |
| 39 | + |
| 40 | +@Composable |
| 41 | +fun ErrorReportScreen( |
| 42 | + sorryMessage: String, |
| 43 | + errorMessage: String, |
| 44 | + infoLabels: String, |
| 45 | + infoValues: String, |
| 46 | + errorDetails: String, |
| 47 | + onBackClick: () -> Unit, |
| 48 | + onReportViaEmail: (comment: String) -> Unit, |
| 49 | + onCopyForGitHub: (comment: String) -> Unit, |
| 50 | + onReportOnGitHub: () -> Unit |
| 51 | +) { |
| 52 | + var comment by rememberSaveable { mutableStateOf("") } |
| 53 | + |
| 54 | + ScaffoldWithToolbar( |
| 55 | + title = stringResource(R.string.error_report_title), |
| 56 | + onBackClick = onBackClick |
| 57 | + ) { paddingValues -> |
| 58 | + Column( |
| 59 | + modifier = Modifier |
| 60 | + .padding(paddingValues) |
| 61 | + .verticalScroll(rememberScrollState()) |
| 62 | + .padding(16.dp) |
| 63 | + ) { |
| 64 | + // Sorry header |
| 65 | + Text( |
| 66 | + text = sorryMessage, |
| 67 | + style = MaterialTheme.typography.titleLarge, |
| 68 | + fontWeight = FontWeight.Bold, |
| 69 | + textAlign = TextAlign.Center, |
| 70 | + modifier = Modifier.fillMaxWidth() |
| 71 | + ) |
| 72 | + |
| 73 | + // What happened |
| 74 | + Spacer(modifier = Modifier.height(16.dp)) |
| 75 | + Text( |
| 76 | + text = stringResource(R.string.what_happened_headline), |
| 77 | + style = MaterialTheme.typography.titleMedium |
| 78 | + ) |
| 79 | + Text( |
| 80 | + text = errorMessage, |
| 81 | + color = MaterialTheme.colorScheme.primary |
| 82 | + ) |
| 83 | + |
| 84 | + // Device info |
| 85 | + Spacer(modifier = Modifier.height(16.dp)) |
| 86 | + Text( |
| 87 | + text = stringResource(R.string.what_device_headline), |
| 88 | + style = MaterialTheme.typography.titleMedium |
| 89 | + ) |
| 90 | + Row { |
| 91 | + Text( |
| 92 | + text = infoLabels, |
| 93 | + color = MaterialTheme.colorScheme.primary |
| 94 | + ) |
| 95 | + Text( |
| 96 | + text = infoValues, |
| 97 | + modifier = Modifier |
| 98 | + .padding(start = 16.dp) |
| 99 | + .horizontalScroll(rememberScrollState()) |
| 100 | + ) |
| 101 | + } |
| 102 | + |
| 103 | + // Error details |
| 104 | + Spacer(modifier = Modifier.height(16.dp)) |
| 105 | + Text( |
| 106 | + text = stringResource(R.string.error_details_headline), |
| 107 | + style = MaterialTheme.typography.titleMedium |
| 108 | + ) |
| 109 | + SelectionContainer { |
| 110 | + Text( |
| 111 | + text = errorDetails, |
| 112 | + fontFamily = FontFamily.Monospace, |
| 113 | + modifier = Modifier.horizontalScroll(rememberScrollState()) |
| 114 | + ) |
| 115 | + } |
| 116 | + |
| 117 | + // User comment |
| 118 | + Spacer(modifier = Modifier.height(16.dp)) |
| 119 | + Text( |
| 120 | + text = stringResource(R.string.your_comment), |
| 121 | + style = MaterialTheme.typography.titleMedium |
| 122 | + ) |
| 123 | + OutlinedTextField( |
| 124 | + value = comment, |
| 125 | + onValueChange = { comment = it }, |
| 126 | + modifier = Modifier.fillMaxWidth() |
| 127 | + ) |
| 128 | + |
| 129 | + // Report via email button |
| 130 | + Spacer(modifier = Modifier.height(16.dp)) |
| 131 | + Button( |
| 132 | + onClick = { onReportViaEmail(comment) }, |
| 133 | + modifier = Modifier.fillMaxWidth() |
| 134 | + ) { |
| 135 | + Text(text = stringResource(R.string.error_report_button_text)) |
| 136 | + } |
| 137 | + |
| 138 | + // GitHub notice |
| 139 | + Text( |
| 140 | + text = stringResource(R.string.error_report_open_github_notice), |
| 141 | + fontWeight = FontWeight.Bold, |
| 142 | + modifier = Modifier.padding(top = 10.dp, bottom = 5.dp) |
| 143 | + ) |
| 144 | + |
| 145 | + // Copy for GitHub button |
| 146 | + Button( |
| 147 | + onClick = { onCopyForGitHub(comment) }, |
| 148 | + modifier = Modifier.fillMaxWidth() |
| 149 | + ) { |
| 150 | + Text(text = stringResource(R.string.copy_for_github)) |
| 151 | + } |
| 152 | + |
| 153 | + // Report on GitHub button |
| 154 | + Button( |
| 155 | + onClick = onReportOnGitHub, |
| 156 | + modifier = Modifier.fillMaxWidth() |
| 157 | + ) { |
| 158 | + Text(text = stringResource(R.string.error_report_open_issue_button_text)) |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO) |
| 165 | +@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES) |
| 166 | +@Composable |
| 167 | +private fun ErrorReportScreenPreview() { |
| 168 | + AppTheme { |
| 169 | + Surface(color = MaterialTheme.colorScheme.background) { |
| 170 | + ErrorReportScreen( |
| 171 | + sorryMessage = "Sorry, that should not have happened.", |
| 172 | + errorMessage = "Requested list not handled", |
| 173 | + infoLabels = "What:\nRequest:\nContent Language:\nContent Country:\nApp Language:\nService:\nTimestamp:\nPackage:\nVersion:\nOS version:", |
| 174 | + infoValues = "Requested list\nnone\nen\nUS\nen_US\nYouTube\n2026-04-17T12:00:00Z\norg.schabi.newpipe\n0.27.5\nAndroid 14 - 34", |
| 175 | + errorDetails = "java.lang.IllegalArgumentException: ...\n\tat org.schabi.newpipe.SomeClass.method(SomeClass.kt:42)", |
| 176 | + onBackClick = {}, |
| 177 | + onReportViaEmail = {}, |
| 178 | + onCopyForGitHub = {}, |
| 179 | + onReportOnGitHub = {} |
| 180 | + ) |
| 181 | + } |
| 182 | + } |
| 183 | +} |
0 commit comments