Clean up unnecessary manual color specification in Compose code
This commit is contained in:
parent
a56debfce6
commit
6ea715a18d
|
@ -3,7 +3,6 @@ package org.schabi.newpipe.fragments.list.comments
|
|||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.Fragment
|
||||
|
@ -20,7 +19,7 @@ class CommentsFragment : Fragment() {
|
|||
savedInstanceState: Bundle?
|
||||
) = content {
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Surface {
|
||||
CommentSection()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,11 @@ package org.schabi.newpipe.ui.components.common
|
|||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun LoadingIndicator(modifier: Modifier = Modifier) {
|
||||
CircularProgressIndicator(
|
||||
modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
trackColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||
)
|
||||
CircularProgressIndicator(modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center))
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.lazy.LazyListState
|
|||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import my.nanihadesuka.compose.LazyColumnScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
|
@ -20,7 +21,7 @@ fun LazyColumnThemedScrollbar(
|
|||
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
my.nanihadesuka.compose.LazyColumnScrollbar(
|
||||
LazyColumnScrollbar(
|
||||
state = state,
|
||||
modifier = modifier,
|
||||
settings = settings,
|
||||
|
|
|
@ -16,16 +16,15 @@ import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
|
|||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.window.core.layout.WindowWidthSizeClass
|
||||
import my.nanihadesuka.compose.LazyColumnScrollbar
|
||||
import org.schabi.newpipe.R
|
||||
import org.schabi.newpipe.extractor.InfoItem
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.info_list.ItemViewMode
|
||||
import org.schabi.newpipe.ktx.findFragmentActivity
|
||||
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
|
||||
import org.schabi.newpipe.ui.components.items.playlist.PlaylistListItem
|
||||
import org.schabi.newpipe.ui.components.items.stream.StreamListItem
|
||||
import org.schabi.newpipe.ui.theme.NewPipeScrollbarSettings
|
||||
import org.schabi.newpipe.util.DependentPreferenceHelper
|
||||
import org.schabi.newpipe.util.NavigationHelper
|
||||
|
||||
|
@ -73,7 +72,7 @@ fun ItemList(
|
|||
} else {
|
||||
val state = rememberLazyListState()
|
||||
|
||||
LazyColumnScrollbar(state = state, settings = NewPipeScrollbarSettings) {
|
||||
LazyColumnThemedScrollbar(state = state) {
|
||||
LazyColumn(modifier = nestedScrollModifier, state = state) {
|
||||
listHeader()
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ private fun CommentPreview(
|
|||
@PreviewParameter(CommentPreviewProvider::class) commentsInfoItem: CommentsInfoItem
|
||||
) {
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Surface {
|
||||
Comment(commentsInfoItem) {}
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ private fun CommentPreview(
|
|||
@Composable
|
||||
private fun CommentListPreview() {
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Surface {
|
||||
Column {
|
||||
for (comment in CommentPreviewProvider().values) {
|
||||
Comment(comment) {}
|
||||
|
|
|
@ -6,14 +6,11 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.contentColorFor
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -85,67 +82,60 @@ private fun CommentRepliesDialog(
|
|||
sheetState = sheetState,
|
||||
onDismissRequest = onDismissRequest,
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
// contentColorFor(MaterialTheme.colorScheme.containerColor), i.e. ModalBottomSheet's
|
||||
// default background color, does not resolve correctly, so need to manually set the
|
||||
// content color for MaterialTheme.colorScheme.background instead
|
||||
LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background)
|
||||
) {
|
||||
LazyColumnThemedScrollbar(state = listState) {
|
||||
LazyColumn(
|
||||
modifier = Modifier.nestedScroll(nestedScrollInterop),
|
||||
state = listState
|
||||
) {
|
||||
LazyColumnThemedScrollbar(state = listState) {
|
||||
LazyColumn(
|
||||
modifier = Modifier.nestedScroll(nestedScrollInterop),
|
||||
state = listState
|
||||
) {
|
||||
item {
|
||||
CommentRepliesHeader(
|
||||
comment = parentComment,
|
||||
onCommentAuthorOpened = nestedOnCommentAuthorOpened,
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
if (parentComment.replyCount >= 0) {
|
||||
item {
|
||||
CommentRepliesHeader(
|
||||
comment = parentComment,
|
||||
Text(
|
||||
modifier = Modifier.padding(
|
||||
horizontal = 12.dp,
|
||||
vertical = 4.dp
|
||||
),
|
||||
text = pluralStringResource(
|
||||
R.plurals.replies,
|
||||
parentComment.replyCount,
|
||||
parentComment.replyCount,
|
||||
),
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (comments.itemCount == 0) {
|
||||
item {
|
||||
val refresh = comments.loadState.refresh
|
||||
if (refresh is LoadState.Loading) {
|
||||
LoadingIndicator(modifier = Modifier.padding(top = 8.dp))
|
||||
} else {
|
||||
val message = if (refresh is LoadState.Error) {
|
||||
R.string.error_unable_to_load_comments
|
||||
} else {
|
||||
R.string.no_comments
|
||||
}
|
||||
NoItemsMessage(message)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items(comments.itemCount) {
|
||||
Comment(
|
||||
comment = comments[it]!!,
|
||||
onCommentAuthorOpened = nestedOnCommentAuthorOpened,
|
||||
)
|
||||
HorizontalDivider(
|
||||
thickness = 1.dp,
|
||||
modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
if (parentComment.replyCount >= 0) {
|
||||
item {
|
||||
Text(
|
||||
modifier = Modifier.padding(
|
||||
horizontal = 12.dp,
|
||||
vertical = 4.dp
|
||||
),
|
||||
text = pluralStringResource(
|
||||
R.plurals.replies,
|
||||
parentComment.replyCount,
|
||||
parentComment.replyCount,
|
||||
),
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (comments.itemCount == 0) {
|
||||
item {
|
||||
val refresh = comments.loadState.refresh
|
||||
if (refresh is LoadState.Loading) {
|
||||
LoadingIndicator(modifier = Modifier.padding(top = 8.dp))
|
||||
} else {
|
||||
val message = if (refresh is LoadState.Error) {
|
||||
R.string.error_unable_to_load_comments
|
||||
} else {
|
||||
R.string.no_comments
|
||||
}
|
||||
NoItemsMessage(message)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items(comments.itemCount) {
|
||||
Comment(
|
||||
comment = comments[it]!!,
|
||||
onCommentAuthorOpened = nestedOnCommentAuthorOpened,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ fun CommentRepliesHeaderPreview() {
|
|||
)
|
||||
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Surface {
|
||||
CommentRepliesHeader(comment) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ private fun CommentSection(
|
|||
@Composable
|
||||
private fun CommentSectionLoadingPreview() {
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Surface {
|
||||
CommentSection(uiState = Resource.Loading, commentsFlow = flowOf())
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ private fun CommentSectionSuccessPreview() {
|
|||
}
|
||||
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Surface {
|
||||
CommentSection(
|
||||
uiState = Resource.Success(
|
||||
CommentInfo(
|
||||
|
@ -170,7 +170,7 @@ private fun CommentSectionSuccessPreview() {
|
|||
@Composable
|
||||
private fun CommentSectionErrorPreview() {
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Surface {
|
||||
CommentSection(uiState = Resource.Error(RuntimeException()), commentsFlow = flowOf())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.preference.PreferenceManager
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
private val lightScheme = lightColorScheme(
|
||||
primary = primaryLight,
|
||||
|
@ -88,11 +87,6 @@ private val darkScheme = darkColorScheme(
|
|||
|
||||
private val blackScheme = darkScheme.copy(surface = Color.Black)
|
||||
|
||||
val NewPipeScrollbarSettings = ScrollbarSettings(
|
||||
thumbSelectedColor = primaryDark,
|
||||
thumbUnselectedColor = primaryLight
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun AppTheme(useDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LocalContext.current)
|
||||
|
|
Loading…
Reference in New Issue