Skip to content

Commit 9bd9a5c

Browse files
Convert ErrorActivity to compose (#13434)
* add error screen compasable * add error activity * create separate privacy policy dialog * move base activity * refactor error activity and tiny tweaks * add new compose activity and navdisplay * refactor app to utilize new compose activity * clean up arguments in the ErrorReportScreen * get rid of redundant colors * tackle review issues * rename getErrorActivityIntent
1 parent ee25b44 commit 9bd9a5c

12 files changed

Lines changed: 751 additions & 401 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
</intent-filter>
8181
</service>
8282

83+
<activity
84+
android:name=".ComposeActivity"
85+
android:exported="false" />
86+
8387
<activity
8488
android:name=".player.PlayQueueActivity"
8589
android:exported="false"
@@ -91,10 +95,6 @@
9195
android:exported="false"
9296
android:label="@string/settings" />
9397

94-
<activity
95-
android:name=".settings.SettingsV2Activity"
96-
android:exported="true"
97-
android:label="@string/settings" />
9898

9999
<activity
100100
android:name=".about.AboutActivity"
@@ -129,10 +129,6 @@
129129
android:label="@string/general_error"
130130
android:theme="@android:style/Theme.NoDisplay" />
131131

132-
<activity
133-
android:name=".error.ErrorActivity"
134-
android:exported="false" />
135-
136132
<!-- giga get related -->
137133
<activity
138134
android:name=".download.DownloadActivity"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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
7+
8+
import android.content.Context
9+
import android.content.Intent
10+
import android.graphics.Color
11+
import android.os.Build
12+
import android.os.Bundle
13+
import androidx.activity.ComponentActivity
14+
import androidx.activity.SystemBarStyle
15+
import androidx.activity.compose.setContent
16+
import androidx.activity.enableEdgeToEdge
17+
import androidx.navigation3.runtime.NavKey
18+
import dagger.hilt.android.AndroidEntryPoint
19+
import org.schabi.newpipe.error.ErrorInfo
20+
import org.schabi.newpipe.navigation.NavDisplay
21+
import org.schabi.newpipe.navigation.Screen
22+
import org.schabi.newpipe.ui.theme.AppTheme
23+
24+
/**
25+
* Single host activity for all Compose-based screens.
26+
* Other parts of the app (including legacy View-based code) launch this activity
27+
* via Intent with extras specifying which screen to display.
28+
*/
29+
@AndroidEntryPoint
30+
class ComposeActivity : ComponentActivity() {
31+
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
enableEdgeToEdge(
34+
navigationBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT)
35+
)
36+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
37+
window.isNavigationBarContrastEnforced = false
38+
}
39+
super.onCreate(savedInstanceState)
40+
41+
val startDestination: NavKey = resolveStartDestination(intent)
42+
43+
setContent {
44+
AppTheme {
45+
NavDisplay(startDestination)
46+
}
47+
}
48+
}
49+
50+
private fun resolveStartDestination(intent: Intent): NavKey {
51+
return when (intent.getStringExtra(EXTRA_SCREEN)) {
52+
SCREEN_ERROR -> Screen.Error
53+
54+
SCREEN_SETTINGS -> Screen.Settings.Home
55+
56+
else -> throw IllegalArgumentException(
57+
"Unknown screen: ${intent.getStringExtra(EXTRA_SCREEN)}"
58+
)
59+
}
60+
}
61+
62+
companion object {
63+
const val EXTRA_SCREEN = "extra_screen"
64+
const val EXTRA_ERROR_INFO = "extra_error_info"
65+
66+
const val SCREEN_ERROR = "error"
67+
const val SCREEN_SETTINGS = "settings"
68+
69+
fun errorIntent(context: Context, errorInfo: ErrorInfo): Intent {
70+
return Intent(context, ComposeActivity::class.java).apply {
71+
putExtra(EXTRA_SCREEN, SCREEN_ERROR)
72+
putExtra(EXTRA_ERROR_INFO, errorInfo)
73+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
74+
}
75+
}
76+
77+
fun settingsIntent(context: Context): Intent {
78+
return Intent(context, ComposeActivity::class.java).apply {
79+
putExtra(EXTRA_SCREEN, SCREEN_SETTINGS)
80+
}
81+
}
82+
}
83+
}

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

Lines changed: 0 additions & 282 deletions
This file was deleted.

0 commit comments

Comments
 (0)