From dfd38db7e33bd708ccb688f3fe02d4e0105083f2 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 27 May 2023 09:22:31 -0400 Subject: [PATCH] Use primitive state holders --- .../presentation/library/components/LibraryPager.kt | 4 ++-- .../java/eu/kanade/presentation/manga/MangaScreen.kt | 4 ++-- .../manga/components/MangaChapterListItem.kt | 3 ++- .../presentation/manga/components/MangaInfoHeader.kt | 5 +++-- .../more/settings/screen/SettingsAdvancedScreen.kt | 3 ++- .../more/settings/screen/SettingsBackupScreen.kt | 3 ++- .../java/eu/kanade/presentation/updates/UpdatesUiItem.kt | 4 ++-- .../browse/extension/details/SourcePreferencesScreen.kt | 3 ++- .../presentation/core/components/AdaptiveSheet.kt | 4 ++-- .../presentation/core/components/VerticalFastScroller.kt | 6 +++--- .../presentation/core/components/WheelPicker.kt | 3 ++- .../tachiyomi/presentation/core/util/LazyListState.kt | 9 +++++---- 12 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt index 763587eb61..7c32ee09b4 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt @@ -11,7 +11,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -69,7 +69,7 @@ fun LibraryPager( remember(isLandscape) { getColumnsForOrientation(isLandscape) } } else { - remember { mutableStateOf(0) } + remember { mutableIntStateOf(0) } } when (displayMode) { diff --git a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt index 1d2c27e8c5..3a8dfe0753 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -32,7 +32,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment @@ -488,7 +488,7 @@ fun MangaScreenLargeImpl( val chapters = remember(state) { state.processedChapters.toList() } val insetPadding = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal).asPaddingValues() - var topBarHeight by remember { mutableStateOf(0) } + var topBarHeight by remember { mutableIntStateOf(0) } PullRefresh( refreshing = state.isRefreshingData, onRefresh = onRefresh, diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaChapterListItem.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaChapterListItem.kt index 5ba73ed92d..953f2c3d72 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaChapterListItem.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaChapterListItem.kt @@ -34,6 +34,7 @@ import androidx.compose.material3.contentColorFor import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -191,7 +192,7 @@ fun MangaChapterListItem( horizontalArrangement = Arrangement.spacedBy(2.dp), verticalAlignment = Alignment.CenterVertically, ) { - var textHeight by remember { mutableStateOf(0) } + var textHeight by remember { mutableIntStateOf(0) } if (!read) { Icon( imageVector = Icons.Filled.Circle, diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt index 15c7014f42..538cb727ec 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt @@ -48,6 +48,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable @@ -573,8 +574,8 @@ private fun MangaSummary( expanded: Boolean, modifier: Modifier = Modifier, ) { - var expandedHeight by remember { mutableStateOf(0) } - var shrunkHeight by remember { mutableStateOf(0) } + var expandedHeight by remember { mutableIntStateOf(0) } + var shrunkHeight by remember { mutableIntStateOf(0) } val heightDelta = remember(expandedHeight, shrunkHeight) { expandedHeight - shrunkHeight } val animProgress by animateFloatAsState(if (expanded) 1f else 0f) val scrimHeight = with(LocalDensity.current) { remember { 24.sp.roundToPx() } } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index f067af9a88..f470522f92 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -165,7 +166,7 @@ object SettingsAdvancedScreen : SearchableSettings { val libraryPreferences = remember { Injekt.get() } val chapterCache = remember { Injekt.get() } - var readableSizeSema by remember { mutableStateOf(0) } + var readableSizeSema by remember { mutableIntStateOf(0) } val readableSize = remember(readableSizeSema) { chapterCache.readableSize } return Preference.PreferenceGroup( diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt index bc7acebca3..ff52ce1fba 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt @@ -26,6 +26,7 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -86,7 +87,7 @@ object SettingsBackupScreen : SearchableSettings { val scope = rememberCoroutineScope() val context = LocalContext.current - var flag by rememberSaveable { mutableStateOf(0) } + var flag by rememberSaveable { mutableIntStateOf(0) } val chooseBackupDir = rememberLauncherForActivityResult( contract = ActivityResultContracts.CreateDocument("application/*"), ) { diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt index c8496ff86a..50ef6840ba 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt @@ -22,7 +22,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment @@ -198,7 +198,7 @@ private fun UpdatesUiItem( ) Row(verticalAlignment = Alignment.CenterVertically) { - var textHeight by remember { mutableStateOf(0) } + var textHeight by remember { mutableIntStateOf(0) } if (!update.read) { Icon( imageVector = Icons.Filled.Circle, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt index a130516f27..2e5ed932f2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/SourcePreferencesScreen.kt @@ -15,6 +15,7 @@ import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue @@ -93,7 +94,7 @@ class SourcePreferencesScreen(val sourceId: Long) : Screen() { commit: FragmentTransaction.(containerId: Int) -> Unit, ) { val containerId by rememberSaveable { - mutableStateOf(View.generateViewId()) + mutableIntStateOf(View.generateViewId()) } var initialized by rememberSaveable { mutableStateOf(false) } AndroidView( diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt index ee47ea68cb..d9f90ad540 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt @@ -26,7 +26,7 @@ import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue @@ -61,7 +61,7 @@ fun AdaptiveSheet( ) { val scope = rememberCoroutineScope() if (isTabletUi) { - var targetAlpha by remember { mutableStateOf(0f) } + var targetAlpha by remember { mutableFloatStateOf(0f) } val alpha by animateFloatAsState( targetValue = targetAlpha, animationSpec = SheetAnimationSpec, diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt index b7d769f357..a0589f1d96 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt @@ -28,7 +28,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier @@ -83,7 +83,7 @@ fun VerticalFastScroller( if (!showScroller) return@subcompose val thumbTopPadding = with(LocalDensity.current) { topContentPadding.toPx() } - var thumbOffsetY by remember(thumbTopPadding) { mutableStateOf(thumbTopPadding) } + var thumbOffsetY by remember(thumbTopPadding) { mutableFloatStateOf(thumbTopPadding) } val dragInteractionSource = remember { MutableInteractionSource() } val isThumbDragged by dragInteractionSource.collectIsDraggedAsState() @@ -248,7 +248,7 @@ fun VerticalGridFastScroller( val showScroller = layoutInfo.visibleItemsInfo.size < layoutInfo.totalItemsCount if (!showScroller) return@subcompose val thumbTopPadding = with(LocalDensity.current) { topContentPadding.toPx() } - var thumbOffsetY by remember(thumbTopPadding) { mutableStateOf(thumbTopPadding) } + var thumbOffsetY by remember(thumbTopPadding) { mutableFloatStateOf(thumbTopPadding) } val dragInteractionSource = remember { MutableInteractionSource() } val isThumbDragged by dragInteractionSource.collectIsDraggedAsState() diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt index e244d08cc3..e1d2fd3207 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt @@ -20,6 +20,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -113,7 +114,7 @@ private fun WheelPicker( val haptic = LocalHapticFeedback.current val lazyListState = rememberLazyListState(startIndex) - var internalIndex by remember { mutableStateOf(startIndex) } + var internalIndex by remember { mutableIntStateOf(startIndex) } val internalOnSelectionChanged: (Int) -> Unit = { internalIndex = it onSelectionChanged(it) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/util/LazyListState.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/util/LazyListState.kt index c0b3264644..1b2aa1ab83 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/util/LazyListState.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/util/LazyListState.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -30,8 +31,8 @@ fun LazyListState.isScrolledToEnd(): Boolean { @Composable fun LazyListState.isScrollingUp(): Boolean { - var previousIndex by remember { mutableStateOf(firstVisibleItemIndex) } - var previousScrollOffset by remember { mutableStateOf(firstVisibleItemScrollOffset) } + var previousIndex by remember { mutableIntStateOf(firstVisibleItemIndex) } + var previousScrollOffset by remember { mutableIntStateOf(firstVisibleItemScrollOffset) } return remember { derivedStateOf { if (previousIndex != firstVisibleItemIndex) { @@ -48,8 +49,8 @@ fun LazyListState.isScrollingUp(): Boolean { @Composable fun LazyListState.isScrollingDown(): Boolean { - var previousIndex by remember { mutableStateOf(firstVisibleItemIndex) } - var previousScrollOffset by remember { mutableStateOf(firstVisibleItemScrollOffset) } + var previousIndex by remember { mutableIntStateOf(firstVisibleItemIndex) } + var previousScrollOffset by remember { mutableIntStateOf(firstVisibleItemScrollOffset) } return remember { derivedStateOf { if (previousIndex != firstVisibleItemIndex) {