Skip to content

Commit 75626ce

Browse files
committed
create separate privacy policy dialog
1 parent e45f4d7 commit 75626ce

3 files changed

Lines changed: 129 additions & 36 deletions

File tree

app/src/main/java/org/schabi/newpipe/error/ErrorActivity.kt

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55

66
package org.schabi.newpipe.error
77

8-
import android.content.Context
98
import android.content.Intent
109
import android.os.Build
1110
import android.os.Bundle
1211
import android.util.Log
13-
import androidx.appcompat.app.AlertDialog
1412
import androidx.core.content.IntentCompat
1513
import androidx.core.net.toUri
1614
import com.grack.nanojson.JsonWriter
@@ -67,7 +65,7 @@ class ErrorActivity : BaseActivity() {
6765
// print stack trace once again for debugging:
6866
errorInfo.stackTraces.forEach { Log.e(TAG, it) }
6967

70-
val sorryMessage = getString(R.string.sorry_string) + "\n" + getString(R.string.guru_meditation)
68+
val sorryMessage = getString(R.string.sorry_string)
7169
val errorMessage = errorInfo.getMessage(this).toString()
7270
val infoLabels = getString(R.string.info_labels)
7371
val infoValues = buildInfoString()
@@ -81,14 +79,15 @@ class ErrorActivity : BaseActivity() {
8179
infoValues = infoValues,
8280
errorDetails = errorDetails,
8381
onBackClick = { finish() },
84-
onReportViaEmail = { comment ->
85-
openPrivacyPolicyDialog(this, "EMAIL", comment)
86-
},
82+
onReportViaEmail = { comment -> sendErrorEmail(comment) },
8783
onCopyForGitHub = { comment ->
8884
ShareUtils.copyToClipboard(this, buildMarkdown(comment))
8985
},
9086
onReportOnGitHub = {
91-
openPrivacyPolicyDialog(this, "GITHUB")
87+
ShareUtils.openUrlInApp(this, ERROR_GITHUB_ISSUE_URL)
88+
},
89+
onReadPrivacyPolicy = {
90+
ShareUtils.openUrlInApp(this, getString(R.string.privacy_policy_url))
9291
},
9392
onShareError = { comment ->
9493
ShareUtils.shareText(
@@ -101,33 +100,13 @@ class ErrorActivity : BaseActivity() {
101100
}
102101
}
103102

104-
private fun openPrivacyPolicyDialog(
105-
context: Context,
106-
action: String,
107-
comment: String = ""
108-
) {
109-
AlertDialog.Builder(context)
110-
.setIcon(android.R.drawable.ic_dialog_alert)
111-
.setTitle(R.string.privacy_policy_title)
112-
.setMessage(R.string.start_accept_privacy_policy)
113-
.setCancelable(false)
114-
.setNeutralButton(R.string.read_privacy_policy) { _, _ ->
115-
ShareUtils.openUrlInApp(context, context.getString(R.string.privacy_policy_url))
116-
}
117-
.setPositiveButton(R.string.accept) { _, _ ->
118-
if (action == "EMAIL") { // send on email
119-
val intent = Intent(Intent.ACTION_SENDTO)
120-
.setData("mailto:".toUri()) // only email apps should handle this
121-
.putExtra(Intent.EXTRA_EMAIL, arrayOf(ERROR_EMAIL_ADDRESS))
122-
.putExtra(Intent.EXTRA_SUBJECT, errorEmailSubject)
123-
.putExtra(Intent.EXTRA_TEXT, buildJson(comment))
124-
ShareUtils.openIntentInApp(context, intent)
125-
} else if (action == "GITHUB") { // open the NewPipe issue page on GitHub
126-
ShareUtils.openUrlInApp(this, ERROR_GITHUB_ISSUE_URL)
127-
}
128-
}
129-
.setNegativeButton(R.string.decline, null)
130-
.show()
103+
private fun sendErrorEmail(comment: String) {
104+
val intent = Intent(Intent.ACTION_SENDTO)
105+
.setData("mailto:".toUri())
106+
.putExtra(Intent.EXTRA_EMAIL, arrayOf(ERROR_EMAIL_ADDRESS))
107+
.putExtra(Intent.EXTRA_SUBJECT, errorEmailSubject)
108+
.putExtra(Intent.EXTRA_TEXT, buildJson(comment))
109+
ShareUtils.openIntentInApp(this, intent)
131110
}
132111

133112
private fun formErrorText(stacktrace: Array<String>): String {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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.components.common
7+
8+
import android.content.res.Configuration
9+
import androidx.compose.foundation.layout.Column
10+
import androidx.compose.material.icons.Icons
11+
import androidx.compose.material.icons.filled.Warning
12+
import androidx.compose.material3.AlertDialog
13+
import androidx.compose.material3.Icon
14+
import androidx.compose.material3.MaterialTheme
15+
import androidx.compose.material3.Surface
16+
import androidx.compose.material3.Text
17+
import androidx.compose.material3.TextButton
18+
import androidx.compose.runtime.Composable
19+
import androidx.compose.ui.res.stringResource
20+
import androidx.compose.ui.tooling.preview.Preview
21+
import org.schabi.newpipe.R
22+
import org.schabi.newpipe.ui.theme.AppTheme
23+
24+
@Composable
25+
fun PrivacyPolicyDialog(
26+
onAccept: () -> Unit,
27+
onDecline: () -> Unit,
28+
onReadPrivacyPolicy: () -> Unit
29+
) {
30+
AlertDialog(
31+
onDismissRequest = onDecline,
32+
icon = {
33+
Icon(
34+
imageVector = Icons.Default.Warning,
35+
contentDescription = null,
36+
tint = MaterialTheme.colorScheme.error
37+
)
38+
},
39+
title = {
40+
Text(
41+
text = stringResource(R.string.privacy_policy_title),
42+
color = MaterialTheme.colorScheme.onSurface
43+
)
44+
},
45+
text = {
46+
Column {
47+
Text(
48+
text = stringResource(R.string.start_accept_privacy_policy),
49+
color = MaterialTheme.colorScheme.onSurfaceVariant
50+
)
51+
TextButton(onClick = onReadPrivacyPolicy) {
52+
Text(
53+
text = stringResource(R.string.read_privacy_policy),
54+
color = MaterialTheme.colorScheme.primary
55+
)
56+
}
57+
}
58+
},
59+
confirmButton = {
60+
TextButton(onClick = onAccept) {
61+
Text(
62+
text = stringResource(R.string.accept),
63+
color = MaterialTheme.colorScheme.primary
64+
)
65+
}
66+
},
67+
dismissButton = {
68+
TextButton(onClick = onDecline) {
69+
Text(
70+
text = stringResource(R.string.decline),
71+
color = MaterialTheme.colorScheme.error
72+
)
73+
}
74+
},
75+
containerColor = MaterialTheme.colorScheme.surface,
76+
titleContentColor = MaterialTheme.colorScheme.onSurface,
77+
textContentColor = MaterialTheme.colorScheme.onSurfaceVariant
78+
)
79+
}
80+
81+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
82+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
83+
@Composable
84+
private fun PrivacyPolicyDialogPreview() {
85+
AppTheme {
86+
Surface(color = MaterialTheme.colorScheme.background) {
87+
PrivacyPolicyDialog(
88+
onAccept = {},
89+
onDecline = {},
90+
onReadPrivacyPolicy = {}
91+
)
92+
}
93+
}
94+
}

app/src/main/java/org/schabi/newpipe/ui/screens/ErrorReportScreen.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ import androidx.compose.ui.text.style.TextAlign
3737
import androidx.compose.ui.tooling.preview.Preview
3838
import androidx.compose.ui.unit.dp
3939
import org.schabi.newpipe.R
40+
import org.schabi.newpipe.ui.components.common.PrivacyPolicyDialog
4041
import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar
4142
import org.schabi.newpipe.ui.theme.AppTheme
4243

44+
private const val ACTION_EMAIL = "EMAIL"
45+
private const val ACTION_GITHUB = "GITHUB"
46+
4347
@Composable
4448
fun ErrorReportScreen(
4549
sorryMessage: String,
@@ -51,9 +55,25 @@ fun ErrorReportScreen(
5155
onReportViaEmail: (comment: String) -> Unit,
5256
onCopyForGitHub: (comment: String) -> Unit,
5357
onReportOnGitHub: () -> Unit,
58+
onReadPrivacyPolicy: () -> Unit = {},
5459
onShareError: (comment: String) -> Unit = {}
5560
) {
5661
var comment by rememberSaveable { mutableStateOf("") }
62+
var privacyDialogAction by rememberSaveable { mutableStateOf<String?>(null) }
63+
64+
privacyDialogAction?.let { action ->
65+
PrivacyPolicyDialog(
66+
onAccept = {
67+
privacyDialogAction = null
68+
when (action) {
69+
ACTION_EMAIL -> onReportViaEmail(comment)
70+
ACTION_GITHUB -> onReportOnGitHub()
71+
}
72+
},
73+
onDecline = { privacyDialogAction = null },
74+
onReadPrivacyPolicy = onReadPrivacyPolicy
75+
)
76+
}
5777

5878
ScaffoldWithToolbar(
5979
title = stringResource(R.string.error_report_title),
@@ -141,7 +161,7 @@ fun ErrorReportScreen(
141161
// Report via email button
142162
Spacer(modifier = Modifier.height(16.dp))
143163
Button(
144-
onClick = { onReportViaEmail(comment) },
164+
onClick = { privacyDialogAction = ACTION_EMAIL },
145165
modifier = Modifier.fillMaxWidth()
146166
) {
147167
Text(text = stringResource(R.string.error_report_button_text))
@@ -164,7 +184,7 @@ fun ErrorReportScreen(
164184

165185
// Report on GitHub button
166186
Button(
167-
onClick = onReportOnGitHub,
187+
onClick = { privacyDialogAction = ACTION_GITHUB },
168188
modifier = Modifier.fillMaxWidth()
169189
) {
170190
Text(text = stringResource(R.string.error_report_open_issue_button_text))

0 commit comments

Comments
 (0)