Skip to content

Commit 6ea715a

Browse files
Clean up unnecessary manual color specification in Compose code
1 parent a56debf commit 6ea715a

9 files changed

Lines changed: 59 additions & 81 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.schabi.newpipe.fragments.list.comments
33
import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.ViewGroup
6-
import androidx.compose.material3.MaterialTheme
76
import androidx.compose.material3.Surface
87
import androidx.core.os.bundleOf
98
import androidx.fragment.app.Fragment
@@ -20,7 +19,7 @@ class CommentsFragment : Fragment() {
2019
savedInstanceState: Bundle?
2120
) = content {
2221
AppTheme {
23-
Surface(color = MaterialTheme.colorScheme.background) {
22+
Surface {
2423
CommentSection()
2524
}
2625
}

app/src/main/java/org/schabi/newpipe/ui/components/common/LoadingIndicator.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@ package org.schabi.newpipe.ui.components.common
33
import androidx.compose.foundation.layout.fillMaxSize
44
import androidx.compose.foundation.layout.wrapContentSize
55
import androidx.compose.material3.CircularProgressIndicator
6-
import androidx.compose.material3.MaterialTheme
76
import androidx.compose.runtime.Composable
87
import androidx.compose.ui.Alignment
98
import androidx.compose.ui.Modifier
109

1110
@Composable
1211
fun LoadingIndicator(modifier: Modifier = Modifier) {
13-
CircularProgressIndicator(
14-
modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center),
15-
color = MaterialTheme.colorScheme.primary,
16-
trackColor = MaterialTheme.colorScheme.surfaceVariant,
17-
)
12+
CircularProgressIndicator(modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center))
1813
}

app/src/main/java/org/schabi/newpipe/ui/components/common/Scrollbar.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.foundation.lazy.LazyListState
44
import androidx.compose.material3.MaterialTheme
55
import androidx.compose.runtime.Composable
66
import androidx.compose.ui.Modifier
7+
import my.nanihadesuka.compose.LazyColumnScrollbar
78
import my.nanihadesuka.compose.ScrollbarSettings
89

910
@Composable
@@ -20,7 +21,7 @@ fun LazyColumnThemedScrollbar(
2021
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null,
2122
content: @Composable () -> Unit
2223
) {
23-
my.nanihadesuka.compose.LazyColumnScrollbar(
24+
LazyColumnScrollbar(
2425
state = state,
2526
modifier = modifier,
2627
settings = settings,

app/src/main/java/org/schabi/newpipe/ui/components/items/ItemList.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
1616
import androidx.compose.ui.res.stringResource
1717
import androidx.preference.PreferenceManager
1818
import androidx.window.core.layout.WindowWidthSizeClass
19-
import my.nanihadesuka.compose.LazyColumnScrollbar
2019
import org.schabi.newpipe.R
2120
import org.schabi.newpipe.extractor.InfoItem
2221
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
2322
import org.schabi.newpipe.extractor.stream.StreamInfoItem
2423
import org.schabi.newpipe.info_list.ItemViewMode
2524
import org.schabi.newpipe.ktx.findFragmentActivity
25+
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
2626
import org.schabi.newpipe.ui.components.items.playlist.PlaylistListItem
2727
import org.schabi.newpipe.ui.components.items.stream.StreamListItem
28-
import org.schabi.newpipe.ui.theme.NewPipeScrollbarSettings
2928
import org.schabi.newpipe.util.DependentPreferenceHelper
3029
import org.schabi.newpipe.util.NavigationHelper
3130

@@ -73,7 +72,7 @@ fun ItemList(
7372
} else {
7473
val state = rememberLazyListState()
7574

76-
LazyColumnScrollbar(state = state, settings = NewPipeScrollbarSettings) {
75+
LazyColumnThemedScrollbar(state = state) {
7776
LazyColumn(modifier = nestedScrollModifier, state = state) {
7877
listHeader()
7978

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/Comment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private fun CommentPreview(
257257
@PreviewParameter(CommentPreviewProvider::class) commentsInfoItem: CommentsInfoItem
258258
) {
259259
AppTheme {
260-
Surface(color = MaterialTheme.colorScheme.background) {
260+
Surface {
261261
Comment(commentsInfoItem) {}
262262
}
263263
}
@@ -267,7 +267,7 @@ private fun CommentPreview(
267267
@Composable
268268
private fun CommentListPreview() {
269269
AppTheme {
270-
Surface(color = MaterialTheme.colorScheme.background) {
270+
Surface {
271271
Column {
272272
for (comment in CommentPreviewProvider().values) {
273273
Comment(comment) {}

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ import androidx.compose.foundation.lazy.LazyColumn
66
import androidx.compose.foundation.lazy.rememberLazyListState
77
import androidx.compose.material3.ExperimentalMaterial3Api
88
import androidx.compose.material3.HorizontalDivider
9-
import androidx.compose.material3.LocalContentColor
109
import androidx.compose.material3.MaterialTheme
1110
import androidx.compose.material3.ModalBottomSheet
1211
import androidx.compose.material3.Text
13-
import androidx.compose.material3.contentColorFor
1412
import androidx.compose.material3.rememberModalBottomSheetState
1513
import androidx.compose.runtime.Composable
16-
import androidx.compose.runtime.CompositionLocalProvider
1714
import androidx.compose.runtime.remember
1815
import androidx.compose.runtime.rememberCoroutineScope
1916
import androidx.compose.ui.Modifier
@@ -85,67 +82,60 @@ private fun CommentRepliesDialog(
8582
sheetState = sheetState,
8683
onDismissRequest = onDismissRequest,
8784
) {
88-
CompositionLocalProvider(
89-
// contentColorFor(MaterialTheme.colorScheme.containerColor), i.e. ModalBottomSheet's
90-
// default background color, does not resolve correctly, so need to manually set the
91-
// content color for MaterialTheme.colorScheme.background instead
92-
LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background)
93-
) {
94-
LazyColumnThemedScrollbar(state = listState) {
95-
LazyColumn(
96-
modifier = Modifier.nestedScroll(nestedScrollInterop),
97-
state = listState
98-
) {
85+
LazyColumnThemedScrollbar(state = listState) {
86+
LazyColumn(
87+
modifier = Modifier.nestedScroll(nestedScrollInterop),
88+
state = listState
89+
) {
90+
item {
91+
CommentRepliesHeader(
92+
comment = parentComment,
93+
onCommentAuthorOpened = nestedOnCommentAuthorOpened,
94+
)
95+
HorizontalDivider(
96+
thickness = 1.dp,
97+
modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
98+
)
99+
}
100+
101+
if (parentComment.replyCount >= 0) {
99102
item {
100-
CommentRepliesHeader(
101-
comment = parentComment,
102-
onCommentAuthorOpened = nestedOnCommentAuthorOpened,
103-
)
104-
HorizontalDivider(
105-
thickness = 1.dp,
106-
modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
103+
Text(
104+
modifier = Modifier.padding(
105+
horizontal = 12.dp,
106+
vertical = 4.dp
107+
),
108+
text = pluralStringResource(
109+
R.plurals.replies,
110+
parentComment.replyCount,
111+
parentComment.replyCount,
112+
),
113+
maxLines = 1,
114+
style = MaterialTheme.typography.titleMedium
107115
)
108116
}
117+
}
109118

110-
if (parentComment.replyCount >= 0) {
111-
item {
112-
Text(
113-
modifier = Modifier.padding(
114-
horizontal = 12.dp,
115-
vertical = 4.dp
116-
),
117-
text = pluralStringResource(
118-
R.plurals.replies,
119-
parentComment.replyCount,
120-
parentComment.replyCount,
121-
),
122-
maxLines = 1,
123-
style = MaterialTheme.typography.titleMedium
124-
)
125-
}
126-
}
127-
128-
if (comments.itemCount == 0) {
129-
item {
130-
val refresh = comments.loadState.refresh
131-
if (refresh is LoadState.Loading) {
132-
LoadingIndicator(modifier = Modifier.padding(top = 8.dp))
119+
if (comments.itemCount == 0) {
120+
item {
121+
val refresh = comments.loadState.refresh
122+
if (refresh is LoadState.Loading) {
123+
LoadingIndicator(modifier = Modifier.padding(top = 8.dp))
124+
} else {
125+
val message = if (refresh is LoadState.Error) {
126+
R.string.error_unable_to_load_comments
133127
} else {
134-
val message = if (refresh is LoadState.Error) {
135-
R.string.error_unable_to_load_comments
136-
} else {
137-
R.string.no_comments
138-
}
139-
NoItemsMessage(message)
128+
R.string.no_comments
140129
}
130+
NoItemsMessage(message)
141131
}
142-
} else {
143-
items(comments.itemCount) {
144-
Comment(
145-
comment = comments[it]!!,
146-
onCommentAuthorOpened = nestedOnCommentAuthorOpened,
147-
)
148-
}
132+
}
133+
} else {
134+
items(comments.itemCount) {
135+
Comment(
136+
comment = comments[it]!!,
137+
onCommentAuthorOpened = nestedOnCommentAuthorOpened,
138+
)
149139
}
150140
}
151141
}

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesHeader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fun CommentRepliesHeaderPreview() {
143143
)
144144

145145
AppTheme {
146-
Surface(color = MaterialTheme.colorScheme.background) {
146+
Surface {
147147
CommentRepliesHeader(comment) {}
148148
}
149149
}

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private fun CommentSection(
123123
@Composable
124124
private fun CommentSectionLoadingPreview() {
125125
AppTheme {
126-
Surface(color = MaterialTheme.colorScheme.background) {
126+
Surface {
127127
CommentSection(uiState = Resource.Loading, commentsFlow = flowOf())
128128
}
129129
}
@@ -151,7 +151,7 @@ private fun CommentSectionSuccessPreview() {
151151
}
152152

153153
AppTheme {
154-
Surface(color = MaterialTheme.colorScheme.background) {
154+
Surface {
155155
CommentSection(
156156
uiState = Resource.Success(
157157
CommentInfo(
@@ -170,7 +170,7 @@ private fun CommentSectionSuccessPreview() {
170170
@Composable
171171
private fun CommentSectionErrorPreview() {
172172
AppTheme {
173-
Surface(color = MaterialTheme.colorScheme.background) {
173+
Surface {
174174
CommentSection(uiState = Resource.Error(RuntimeException()), commentsFlow = flowOf())
175175
}
176176
}

app/src/main/java/org/schabi/newpipe/ui/theme/Theme.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import androidx.compose.runtime.Composable
88
import androidx.compose.ui.graphics.Color
99
import androidx.compose.ui.platform.LocalContext
1010
import androidx.preference.PreferenceManager
11-
import my.nanihadesuka.compose.ScrollbarSettings
1211

1312
private val lightScheme = lightColorScheme(
1413
primary = primaryLight,
@@ -88,11 +87,6 @@ private val darkScheme = darkColorScheme(
8887

8988
private val blackScheme = darkScheme.copy(surface = Color.Black)
9089

91-
val NewPipeScrollbarSettings = ScrollbarSettings(
92-
thumbSelectedColor = primaryDark,
93-
thumbUnselectedColor = primaryLight
94-
)
95-
9690
@Composable
9791
fun AppTheme(useDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
9892
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LocalContext.current)

0 commit comments

Comments
 (0)