From fdf36cbad61d5995b87244ae576f2e41b0610f68 Mon Sep 17 00:00:00 2001 From: Stypox Date: Mon, 11 Nov 2024 15:20:38 +0100 Subject: [PATCH] Deduplicate and improve Scrollbar theme --- .../newpipe/ui/components/common/Scrollbar.kt | 30 +++++++++++++++++++ .../newpipe/ui/components/items/ItemList.kt | 13 ++------ .../video/comment/CommentRepliesDialog.kt | 13 ++------ .../video/comment/CommentSection.kt | 13 ++------ 4 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/ui/components/common/Scrollbar.kt diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/common/Scrollbar.kt b/app/src/main/java/org/schabi/newpipe/ui/components/common/Scrollbar.kt new file mode 100644 index 00000000000..eb1595467f9 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/ui/components/common/Scrollbar.kt @@ -0,0 +1,30 @@ +package org.schabi.newpipe.ui.components.common + +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.ScrollbarSettings + +@Composable +fun defaultThemedScrollbarSettings(): ScrollbarSettings = ScrollbarSettings.Default.copy( + thumbUnselectedColor = MaterialTheme.colorScheme.primary, + thumbSelectedColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.75f), +) + +@Composable +fun LazyColumnThemedScrollbar( + state: LazyListState, + modifier: Modifier = Modifier, + settings: ScrollbarSettings = defaultThemedScrollbarSettings(), + indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null, + content: @Composable () -> Unit +) { + my.nanihadesuka.compose.LazyColumnScrollbar( + state = state, + modifier = modifier, + settings = settings, + indicatorContent = indicatorContent, + content = content, + ) +} diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/items/ItemList.kt b/app/src/main/java/org/schabi/newpipe/ui/components/items/ItemList.kt index 237a5766737..4562e17aff7 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/items/ItemList.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/items/ItemList.kt @@ -10,24 +10,21 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext 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 my.nanihadesuka.compose.ScrollbarSettings 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.md_theme_dark_primary import org.schabi.newpipe.util.DependentPreferenceHelper import org.schabi.newpipe.util.NavigationHelper @@ -75,13 +72,7 @@ fun ItemList( } else { val state = rememberLazyListState() - LazyColumnScrollbar( - state = state, - settings = ScrollbarSettings.Default.copy( - thumbSelectedColor = md_theme_dark_primary, - thumbUnselectedColor = Color.Red - ) - ) { + LazyColumnThemedScrollbar(state = state) { LazyColumn(modifier = nestedScrollModifier, state = state) { listHeader() diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt index ba6ba75176e..17ea900a544 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt @@ -17,7 +17,6 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.rememberNestedScrollInteropConnection import androidx.compose.ui.res.pluralStringResource @@ -33,16 +32,14 @@ import androidx.paging.compose.collectAsLazyPagingItems import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.launch -import my.nanihadesuka.compose.LazyColumnScrollbar -import my.nanihadesuka.compose.ScrollbarSettings import org.schabi.newpipe.R import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.stream.Description import org.schabi.newpipe.paging.CommentRepliesSource +import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar import org.schabi.newpipe.ui.components.common.LoadingIndicator import org.schabi.newpipe.ui.components.common.NoItemsMessage import org.schabi.newpipe.ui.theme.AppTheme -import org.schabi.newpipe.ui.theme.md_theme_dark_primary @Composable fun CommentRepliesDialog( @@ -94,13 +91,7 @@ private fun CommentRepliesDialog( // content color for MaterialTheme.colorScheme.background instead LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background) ) { - LazyColumnScrollbar( - state = listState, - settings = ScrollbarSettings.Default.copy( - thumbSelectedColor = md_theme_dark_primary, - thumbUnselectedColor = Color.Red - ) - ) { + LazyColumnThemedScrollbar(state = listState) { LazyColumn( modifier = Modifier.nestedScroll(nestedScrollInterop), state = listState diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt index cd0a6271c9e..f1740c70a94 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt @@ -10,7 +10,6 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.rememberNestedScrollInteropConnection import androidx.compose.ui.res.pluralStringResource @@ -23,16 +22,14 @@ import androidx.paging.PagingData import androidx.paging.compose.collectAsLazyPagingItems import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf -import my.nanihadesuka.compose.LazyColumnScrollbar -import my.nanihadesuka.compose.ScrollbarSettings import org.schabi.newpipe.R import org.schabi.newpipe.extractor.Page import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.stream.Description +import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar import org.schabi.newpipe.ui.components.common.LoadingIndicator import org.schabi.newpipe.ui.components.common.NoItemsMessage import org.schabi.newpipe.ui.theme.AppTheme -import org.schabi.newpipe.ui.theme.md_theme_dark_primary import org.schabi.newpipe.viewmodels.CommentsViewModel import org.schabi.newpipe.viewmodels.util.Resource @@ -52,13 +49,7 @@ private fun CommentSection( val state = rememberLazyListState() Surface(color = MaterialTheme.colorScheme.background) { - LazyColumnScrollbar( - state = state, - settings = ScrollbarSettings.Default.copy( - thumbSelectedColor = md_theme_dark_primary, - thumbUnselectedColor = Color.Red - ) - ) { + LazyColumnThemedScrollbar(state = state) { LazyColumn( modifier = Modifier.nestedScroll(nestedScrollInterop), state = state