-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathNavDisplay.kt
More file actions
163 lines (137 loc) · 5.9 KB
/
NavDisplay.kt
File metadata and controls
163 lines (137 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* SPDX-FileCopyrightText: 2025-2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package org.schabi.newpipe.navigation
import androidx.activity.compose.LocalActivity
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.core.content.IntentCompat
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
import androidx.navigation3.runtime.NavKey
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.rememberNavBackStack
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
import androidx.navigation3.ui.NavDisplay
import org.schabi.newpipe.ComposeActivity
import org.schabi.newpipe.R
import org.schabi.newpipe.error.ErrorInfo
import org.schabi.newpipe.error.ErrorReportHelper
import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar
import org.schabi.newpipe.ui.screens.AboutScreen
import org.schabi.newpipe.ui.screens.ErrorReportEvent
import org.schabi.newpipe.ui.screens.ErrorReportScreen
import org.schabi.newpipe.ui.screens.settings.debug.DebugScreen
import org.schabi.newpipe.ui.screens.settings.home.SettingsHomeScreen
/**
* Top-level navigation display for all Compose screens in the app.
* @param startDestination the initial screen to display, resolved from the launching Intent.
*/
@Composable
fun NavDisplay(startDestination: NavKey) {
val backstack = rememberNavBackStack(startDestination)
val context = LocalContext.current
// TODO: Drop this logic once everything is in Compose
val activity = LocalActivity.current
fun onNavigateUp() {
if (backstack.size > 1) {
backstack.removeLastOrNull()
} else {
activity?.finish()
}
}
NavDisplay(
backStack = backstack,
onBack = ::onNavigateUp,
entryDecorators = listOf(
rememberSaveableStateHolderNavEntryDecorator(),
rememberViewModelStoreNavEntryDecorator()
),
entryProvider = entryProvider {
// About
entry<Screen.About> {
ScaffoldWithToolbar(
title = stringResource(R.string.title_activity_about),
onBackClick = ::onNavigateUp
) { padding ->
AboutScreen(padding)
}
}
// Error Report
entry<Screen.Error> {
val errorInfo = remember {
IntentCompat.getParcelableExtra(
activity!!.intent,
ComposeActivity.EXTRA_ERROR_INFO,
ErrorInfo::class.java
)!!
}
ErrorReportScreen(
errorInfo = errorInfo,
onEvent = { event ->
when (event) {
is ErrorReportEvent.ReportViaEmail ->
ErrorReportHelper.sendErrorEmail(context, errorInfo, event.comment)
is ErrorReportEvent.CopyForGitHub ->
ErrorReportHelper.copyForGitHub(context, errorInfo, event.comment)
is ErrorReportEvent.ReportOnGitHub ->
ErrorReportHelper.openGitHubIssues(context)
is ErrorReportEvent.ReadPrivacyPolicy ->
ErrorReportHelper.openPrivacyPolicy(context)
is ErrorReportEvent.ShareError ->
ErrorReportHelper.shareError(context, errorInfo, event.comment)
is ErrorReportEvent.NavigateUp ->
onNavigateUp()
}
}
)
}
// Settings
entry<Screen.Settings.Home> {
SettingsHomeScreen(
onNavigate = { screen -> backstack.add(screen) },
onBackClick = ::onNavigateUp
)
}
entry<Screen.Settings.Player> {
Text(stringResource(id = R.string.settings_category_player_title))
}
entry<Screen.Settings.Behaviour> {
Text(stringResource(id = R.string.settings_category_player_behavior_title))
}
entry<Screen.Settings.Download> {
Text(stringResource(id = R.string.settings_category_downloads_title))
}
entry<Screen.Settings.LookFeel> {
Text(stringResource(id = R.string.settings_category_look_and_feel_title))
}
entry<Screen.Settings.HistoryCache> {
Text(stringResource(id = R.string.settings_category_history_title))
}
entry<Screen.Settings.Content> {
Text(stringResource(id = R.string.settings_category_content_title))
}
entry<Screen.Settings.Feed> {
Text(stringResource(id = R.string.settings_category_feed_title))
}
entry<Screen.Settings.Services> {
Text(stringResource(id = R.string.settings_category_services_title))
}
entry<Screen.Settings.Language> {
Text(stringResource(id = R.string.settings_category_language_title))
}
entry<Screen.Settings.BackupRestore> {
Text(stringResource(id = R.string.settings_category_backup_restore_title))
}
entry<Screen.Settings.Updates> {
Text(stringResource(id = R.string.settings_category_updates_title))
}
entry<Screen.Settings.Debug> {
DebugScreen(onBackClick = { backstack.removeLastOrNull() })
}
}
)
}