diff --git a/app/src/main/java/eu/kanade/core/preference/PreferenceMutableState.kt b/app/src/main/java/eu/kanade/core/preference/PreferenceMutableState.kt index 2c641ccc0..cb91e700a 100644 --- a/app/src/main/java/eu/kanade/core/preference/PreferenceMutableState.kt +++ b/app/src/main/java/eu/kanade/core/preference/PreferenceMutableState.kt @@ -31,7 +31,7 @@ class PreferenceMutableState( } override fun component2(): (T) -> Unit { - return { preference.set(it) } + return preference::set } } diff --git a/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt b/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt index 948f5ad56..78329d3e5 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt @@ -16,7 +16,6 @@ import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.stringResource import eu.kanade.presentation.components.TabbedDialog import eu.kanade.presentation.components.TabbedDialogPaddings -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel import tachiyomi.core.preference.TriState @@ -31,6 +30,7 @@ import tachiyomi.presentation.core.components.SettingsChipRow import tachiyomi.presentation.core.components.SliderItem import tachiyomi.presentation.core.components.SortItem import tachiyomi.presentation.core.components.TriStateItem +import tachiyomi.presentation.core.util.collectAsState @Composable fun LibrarySettingsDialog( @@ -211,59 +211,35 @@ private fun ColumnScope.DisplayPage( } else { stringResource(R.string.label_default) }, - onChange = { columnPreference.set(it) }, + onChange = columnPreference::set, ) } HeadingItem(R.string.overlay_header) - val downloadBadge by screenModel.libraryPreferences.downloadBadge().collectAsState() CheckboxItem( label = stringResource(R.string.action_display_download_badge), - checked = downloadBadge, - onClick = { - screenModel.togglePreference(LibraryPreferences::downloadBadge) - }, + pref = screenModel.libraryPreferences.downloadBadge(), ) - val localBadge by screenModel.libraryPreferences.localBadge().collectAsState() CheckboxItem( label = stringResource(R.string.action_display_local_badge), - checked = localBadge, - onClick = { - screenModel.togglePreference(LibraryPreferences::localBadge) - }, + pref = screenModel.libraryPreferences.localBadge(), ) - val languageBadge by screenModel.libraryPreferences.languageBadge().collectAsState() CheckboxItem( label = stringResource(R.string.action_display_language_badge), - checked = languageBadge, - onClick = { - screenModel.togglePreference(LibraryPreferences::languageBadge) - }, + pref = screenModel.libraryPreferences.languageBadge(), ) - val showContinueReadingButton by screenModel.libraryPreferences.showContinueReadingButton().collectAsState() CheckboxItem( label = stringResource(R.string.action_display_show_continue_reading_button), - checked = showContinueReadingButton, - onClick = { - screenModel.togglePreference(LibraryPreferences::showContinueReadingButton) - }, + pref = screenModel.libraryPreferences.showContinueReadingButton(), ) HeadingItem(R.string.tabs_header) - val categoryTabs by screenModel.libraryPreferences.categoryTabs().collectAsState() CheckboxItem( label = stringResource(R.string.action_display_show_tabs), - checked = categoryTabs, - onClick = { - screenModel.togglePreference(LibraryPreferences::categoryTabs) - }, + pref = screenModel.libraryPreferences.categoryTabs(), ) - val categoryNumberOfItems by screenModel.libraryPreferences.categoryNumberOfItems().collectAsState() CheckboxItem( label = stringResource(R.string.action_display_show_number_of_items), - checked = categoryNumberOfItems, - onClick = { - screenModel.togglePreference(LibraryPreferences::categoryNumberOfItems) - }, + pref = screenModel.libraryPreferences.categoryNumberOfItems(), ) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt index fc383e2f5..b7190a4a7 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceItem.kt @@ -22,10 +22,10 @@ import eu.kanade.presentation.more.settings.widget.MultiSelectListPreferenceWidg import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget import eu.kanade.presentation.more.settings.widget.TrackingPreferenceWidget -import eu.kanade.presentation.util.collectAsState import kotlinx.coroutines.launch import tachiyomi.core.preference.PreferenceStore import tachiyomi.presentation.core.components.SliderItem +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get 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 20a91ee0d..411009e39 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 @@ -30,7 +30,6 @@ import eu.kanade.domain.base.BasePreferences import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.screen.advanced.ClearDatabaseScreen import eu.kanade.presentation.more.settings.screen.debug.DebugInfoScreen -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.download.DownloadCache @@ -65,6 +64,7 @@ import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.system.logcat import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.manga.repository.MangaRepository +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt index 699304f75..9ae42cd5f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt @@ -21,7 +21,6 @@ import eu.kanade.domain.ui.model.TabletUiMode import eu.kanade.domain.ui.model.ThemeMode import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode import eu.kanade.presentation.more.settings.Preference -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.toast @@ -29,6 +28,7 @@ import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.merge import org.xmlpull.v1.XmlPullParser +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.Date 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 aa6f699ea..8b16f3af9 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 @@ -42,7 +42,6 @@ import androidx.core.net.toUri import com.hippo.unifile.UniFile import eu.kanade.presentation.extensions.RequestStoragePermission import eu.kanade.presentation.more.settings.Preference -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.backup.BackupConst import eu.kanade.tachiyomi.data.backup.BackupCreateJob @@ -57,6 +56,7 @@ import kotlinx.coroutines.launch import tachiyomi.domain.backup.service.BackupPreferences import tachiyomi.presentation.core.components.ScrollbarLazyColumn import tachiyomi.presentation.core.components.material.Divider +import tachiyomi.presentation.core.util.collectAsState import tachiyomi.presentation.core.util.isScrolledToEnd import tachiyomi.presentation.core.util.isScrolledToStart import uy.kohesive.injekt.Injekt diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt index fa6b0af2b..172a962a6 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt @@ -22,12 +22,12 @@ import com.hippo.unifile.UniFile import eu.kanade.presentation.category.visualName import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.widget.TriStateListDialog -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import kotlinx.coroutines.runBlocking import tachiyomi.domain.category.interactor.GetCategories import tachiyomi.domain.category.model.Category import tachiyomi.domain.download.service.DownloadPreferences +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt index 755d788f3..e48bd5cdd 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt @@ -36,7 +36,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.presentation.category.visualName import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.widget.TriStateListDialog -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.track.TrackManager @@ -58,6 +57,7 @@ import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_R import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_OUTSIDE_RELEASE_PERIOD import tachiyomi.domain.manga.interactor.MAX_GRACE_PERIOD import tachiyomi.presentation.core.components.WheelTextPicker +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt index d327b4e52..bb73b89ec 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt @@ -9,12 +9,12 @@ import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource import eu.kanade.presentation.more.settings.Preference -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType import eu.kanade.tachiyomi.util.system.isReleaseBuildType +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.text.NumberFormat diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt index 044aac9d6..6dcbaa1ed 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt @@ -10,11 +10,11 @@ import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.fragment.app.FragmentActivity import eu.kanade.presentation.more.settings.Preference -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.core.security.SecurityPreferences import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt index 94aa4fe9a..d38220d9b 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/ColorFilterPage.kt @@ -11,14 +11,13 @@ import androidx.core.graphics.alpha import androidx.core.graphics.blue import androidx.core.graphics.green import androidx.core.graphics.red -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import tachiyomi.core.preference.getAndSet import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.SettingsChipRow import tachiyomi.presentation.core.components.SliderItem +import tachiyomi.presentation.core.util.collectAsState @Composable internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) { @@ -44,10 +43,7 @@ internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) val customBrightness by screenModel.preferences.customBrightness().collectAsState() CheckboxItem( label = stringResource(R.string.pref_custom_brightness), - checked = customBrightness, - onClick = { - screenModel.togglePreference(ReaderPreferences::customBrightness) - }, + pref = screenModel.preferences.customBrightness(), ) /** @@ -71,10 +67,7 @@ internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) val colorFilter by screenModel.preferences.colorFilter().collectAsState() CheckboxItem( label = stringResource(R.string.pref_custom_color_filter), - checked = colorFilter, - onClick = { - screenModel.togglePreference(ReaderPreferences::colorFilter) - }, + pref = screenModel.preferences.colorFilter(), ) if (colorFilter) { val colorFilterValue by screenModel.preferences.colorFilterValue().collectAsState() @@ -135,21 +128,13 @@ internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) } } - val grayscale by screenModel.preferences.grayscale().collectAsState() CheckboxItem( label = stringResource(R.string.pref_grayscale), - checked = grayscale, - onClick = { - screenModel.togglePreference(ReaderPreferences::grayscale) - }, + pref = screenModel.preferences.grayscale(), ) - val invertedColors by screenModel.preferences.invertedColors().collectAsState() CheckboxItem( label = stringResource(R.string.pref_inverted_colors), - checked = invertedColors, - onClick = { - screenModel.togglePreference(ReaderPreferences::invertedColors) - }, + pref = screenModel.preferences.invertedColors(), ) } diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt index 74dd37f67..884570dfa 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/GeneralSettingsPage.kt @@ -6,12 +6,11 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.res.stringResource -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.SettingsChipRow +import tachiyomi.presentation.core.util.collectAsState private val themes = listOf( R.string.black_background to 1, @@ -33,67 +32,39 @@ internal fun ColumnScope.GeneralPage(screenModel: ReaderSettingsScreenModel) { } } - val showPageNumber by screenModel.preferences.showPageNumber().collectAsState() CheckboxItem( label = stringResource(R.string.pref_show_page_number), - checked = showPageNumber, - onClick = { - screenModel.togglePreference(ReaderPreferences::showPageNumber) - }, + pref = screenModel.preferences.showPageNumber(), ) - val fullscreen by screenModel.preferences.fullscreen().collectAsState() CheckboxItem( label = stringResource(R.string.pref_fullscreen), - checked = fullscreen, - onClick = { - screenModel.togglePreference(ReaderPreferences::fullscreen) - }, + pref = screenModel.preferences.fullscreen(), ) // TODO: hide if there's no cutout - val cutoutShort by screenModel.preferences.cutoutShort().collectAsState() CheckboxItem( label = stringResource(R.string.pref_cutout_short), - checked = cutoutShort, - onClick = { - screenModel.togglePreference(ReaderPreferences::cutoutShort) - }, + pref = screenModel.preferences.cutoutShort(), ) - val keepScreenOn by screenModel.preferences.keepScreenOn().collectAsState() CheckboxItem( label = stringResource(R.string.pref_keep_screen_on), - checked = keepScreenOn, - onClick = { - screenModel.togglePreference(ReaderPreferences::keepScreenOn) - }, + pref = screenModel.preferences.keepScreenOn(), ) - val readWithLongTap by screenModel.preferences.readWithLongTap().collectAsState() CheckboxItem( label = stringResource(R.string.pref_read_with_long_tap), - checked = readWithLongTap, - onClick = { - screenModel.togglePreference(ReaderPreferences::readWithLongTap) - }, + pref = screenModel.preferences.readWithLongTap(), ) - val alwaysShowChapterTransition by screenModel.preferences.alwaysShowChapterTransition().collectAsState() CheckboxItem( label = stringResource(R.string.pref_always_show_chapter_transition), - checked = alwaysShowChapterTransition, - onClick = { - screenModel.togglePreference(ReaderPreferences::alwaysShowChapterTransition) - }, + pref = screenModel.preferences.alwaysShowChapterTransition(), ) - val pageTransitions by screenModel.preferences.pageTransitions().collectAsState() CheckboxItem( label = stringResource(R.string.pref_page_transitions), - checked = pageTransitions, - onClick = { - screenModel.togglePreference(ReaderPreferences::pageTransitions) - }, + pref = screenModel.preferences.pageTransitions(), ) } diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt index 883d61bd2..874a053cd 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt @@ -10,7 +10,6 @@ import androidx.compose.runtime.remember import androidx.compose.ui.res.stringResource import eu.kanade.domain.manga.model.orientationType import eu.kanade.domain.manga.model.readingModeType -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences @@ -22,6 +21,7 @@ import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.HeadingItem import tachiyomi.presentation.core.components.SettingsChipRow import tachiyomi.presentation.core.components.SliderItem +import tachiyomi.presentation.core.util.collectAsState import java.text.NumberFormat private val readingModeOptions = ReadingModeType.entries.map { it.stringRes to it } @@ -98,70 +98,44 @@ private fun ColumnScope.PagerViewerSettings(screenModel: ReaderSettingsScreenMod } } - val cropBorders by screenModel.preferences.cropBorders().collectAsState() CheckboxItem( label = stringResource(R.string.pref_crop_borders), - checked = cropBorders, - onClick = { - screenModel.togglePreference(ReaderPreferences::cropBorders) - }, + pref = screenModel.preferences.cropBorders(), ) - val landscapeZoom by screenModel.preferences.landscapeZoom().collectAsState() CheckboxItem( label = stringResource(R.string.pref_landscape_zoom), - checked = landscapeZoom, - onClick = { - screenModel.togglePreference(ReaderPreferences::landscapeZoom) - }, + pref = screenModel.preferences.landscapeZoom(), ) - val navigateToPan by screenModel.preferences.navigateToPan().collectAsState() CheckboxItem( label = stringResource(R.string.pref_navigate_pan), - checked = navigateToPan, - onClick = { - screenModel.togglePreference(ReaderPreferences::navigateToPan) - }, + pref = screenModel.preferences.navigateToPan(), ) val dualPageSplitPaged by screenModel.preferences.dualPageSplitPaged().collectAsState() CheckboxItem( label = stringResource(R.string.pref_dual_page_split), - checked = dualPageSplitPaged, - onClick = { - screenModel.togglePreference(ReaderPreferences::dualPageSplitPaged) - }, + pref = screenModel.preferences.dualPageSplitPaged(), ) if (dualPageSplitPaged) { - val dualPageInvertPaged by screenModel.preferences.dualPageInvertPaged().collectAsState() CheckboxItem( label = stringResource(R.string.pref_dual_page_invert), - checked = dualPageInvertPaged, - onClick = { - screenModel.togglePreference(ReaderPreferences::dualPageInvertPaged) - }, + pref = screenModel.preferences.dualPageInvertPaged(), ) } val dualPageRotateToFit by screenModel.preferences.dualPageRotateToFit().collectAsState() CheckboxItem( label = stringResource(R.string.pref_page_rotate), - checked = dualPageRotateToFit, - onClick = { - screenModel.togglePreference(ReaderPreferences::dualPageRotateToFit) - }, + pref = screenModel.preferences.dualPageRotateToFit(), ) if (dualPageRotateToFit) { - val dualPageRotateToFitInvert by screenModel.preferences.dualPageRotateToFitInvert().collectAsState() CheckboxItem( label = stringResource(R.string.pref_page_rotate_invert), - checked = dualPageRotateToFitInvert, - onClick = { - screenModel.togglePreference(ReaderPreferences::dualPageRotateToFitInvert) - }, + pref = screenModel.preferences.dualPageRotateToFitInvert(), ) } } @@ -193,55 +167,34 @@ private fun ColumnScope.WebtoonViewerSettings(screenModel: ReaderSettingsScreenM }, ) - val cropBordersWebtoon by screenModel.preferences.cropBordersWebtoon().collectAsState() CheckboxItem( label = stringResource(R.string.pref_crop_borders), - checked = cropBordersWebtoon, - onClick = { - screenModel.togglePreference(ReaderPreferences::cropBordersWebtoon) - }, + pref = screenModel.preferences.cropBordersWebtoon(), ) val dualPageSplitWebtoon by screenModel.preferences.dualPageSplitWebtoon().collectAsState() CheckboxItem( label = stringResource(R.string.pref_dual_page_split), - checked = dualPageSplitWebtoon, - onClick = { - screenModel.togglePreference(ReaderPreferences::dualPageSplitWebtoon) - }, + pref = screenModel.preferences.dualPageSplitWebtoon(), ) if (dualPageSplitWebtoon) { - val dualPageInvertWebtoon by screenModel.preferences.dualPageInvertWebtoon() - .collectAsState() CheckboxItem( label = stringResource(R.string.pref_dual_page_invert), - checked = dualPageInvertWebtoon, - onClick = { - screenModel.togglePreference(ReaderPreferences::dualPageInvertWebtoon) - }, + pref = screenModel.preferences.dualPageInvertWebtoon(), ) } if (!isReleaseBuildType) { - val longStripSplitWebtoon by screenModel.preferences.longStripSplitWebtoon() - .collectAsState() CheckboxItem( label = stringResource(R.string.pref_long_strip_split), - checked = longStripSplitWebtoon, - onClick = { - screenModel.togglePreference(ReaderPreferences::longStripSplitWebtoon) - }, + pref = screenModel.preferences.longStripSplitWebtoon(), ) } - val webtoonDoubleTapZoomEnabled by screenModel.preferences.webtoonDoubleTapZoomEnabled().collectAsState() CheckboxItem( label = stringResource(R.string.pref_double_tap_zoom), - checked = webtoonDoubleTapZoomEnabled, - onClick = { - screenModel.togglePreference(ReaderPreferences::webtoonDoubleTapZoomEnabled) - }, + pref = screenModel.preferences.webtoonDoubleTapZoomEnabled(), ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index c5a66afab..a493d216f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -14,8 +14,6 @@ import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences -import eu.kanade.tachiyomi.util.preference.minusAssign -import eu.kanade.tachiyomi.util.preference.plusAssign import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.isReleaseBuildType import eu.kanade.tachiyomi.util.system.toast @@ -23,6 +21,8 @@ import eu.kanade.tachiyomi.util.system.workManager import tachiyomi.core.preference.PreferenceStore import tachiyomi.core.preference.TriState import tachiyomi.core.preference.getEnum +import tachiyomi.core.preference.minusAssign +import tachiyomi.core.preference.plusAssign import tachiyomi.domain.backup.service.BackupPreferences import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index fd78e4569..b22da0780 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.extension.util.ExtensionInstallReceiver import eu.kanade.tachiyomi.extension.util.ExtensionInstaller import eu.kanade.tachiyomi.extension.util.ExtensionLoader -import eu.kanade.tachiyomi.util.preference.plusAssign import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow @@ -19,6 +18,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.emptyFlow import logcat.LogPriority +import tachiyomi.core.preference.plusAssign import tachiyomi.core.util.lang.launchNow import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.system.logcat diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt index 12db1e289..a5a21317e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt @@ -4,7 +4,6 @@ import cafe.adriel.voyager.core.model.ScreenModel import cafe.adriel.voyager.core.model.coroutineScope import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.util.preference.toggle import tachiyomi.core.preference.Preference import tachiyomi.core.preference.TriState import tachiyomi.core.preference.getAndSet @@ -29,10 +28,6 @@ class LibrarySettingsScreenModel( val trackServices get() = trackManager.services.filter { it.isLogged } - fun togglePreference(preference: (LibraryPreferences) -> Preference) { - preference(libraryPreferences).toggle() - } - fun toggleFilter(preference: (LibraryPreferences) -> Preference) { preference(libraryPreferences).getAndSet { it.next() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 0dd9c2785..e2516ea7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -59,7 +59,6 @@ import eu.kanade.presentation.components.IncognitoModeBannerBackgroundColor import eu.kanade.presentation.components.IndexingBannerBackgroundColor import eu.kanade.presentation.util.AssistContentScreen import eu.kanade.presentation.util.DefaultNavigatorScreenTransition -import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R @@ -93,6 +92,7 @@ import tachiyomi.core.util.system.logcat import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.release.interactor.GetApplicationRelease import tachiyomi.presentation.core.components.material.Scaffold +import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index eb5c81c06..511226b18 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -73,7 +73,6 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.ui.webview.WebViewActivity -import eu.kanade.tachiyomi.util.preference.toggle import eu.kanade.tachiyomi.util.system.applySystemAnimatorScale import eu.kanade.tachiyomi.util.system.hasDisplayCutout import eu.kanade.tachiyomi.util.system.isNightMode @@ -95,6 +94,7 @@ import kotlinx.coroutines.flow.sample import kotlinx.coroutines.launch import logcat.LogPriority import tachiyomi.core.Constants +import tachiyomi.core.preference.toggle import tachiyomi.core.util.lang.launchIO import tachiyomi.core.util.lang.launchNonCancellable import tachiyomi.core.util.lang.withUIContext diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt index 0f55c2241..38ec9361d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt @@ -50,9 +50,7 @@ internal class HttpPageLoader( } } .filter { it.status == Page.State.QUEUE } - .collect { - _loadPage(it) - } + .collect(::internalLoadPage) } } @@ -80,32 +78,30 @@ internal class HttpPageLoader( /** * Loads a page through the queue. Handles re-enqueueing pages if they were evicted from the cache. */ - override suspend fun loadPage(page: ReaderPage) { - withIOContext { - val imageUrl = page.imageUrl + override suspend fun loadPage(page: ReaderPage) = withIOContext { + val imageUrl = page.imageUrl - // Check if the image has been deleted - if (page.status == Page.State.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) { - page.status = Page.State.QUEUE - } + // Check if the image has been deleted + if (page.status == Page.State.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) { + page.status = Page.State.QUEUE + } - // Automatically retry failed pages when subscribed to this page - if (page.status == Page.State.ERROR) { - page.status = Page.State.QUEUE - } + // Automatically retry failed pages when subscribed to this page + if (page.status == Page.State.ERROR) { + page.status = Page.State.QUEUE + } - val queuedPages = mutableListOf() - if (page.status == Page.State.QUEUE) { - queuedPages += PriorityPage(page, 1).also { queue.offer(it) } - } - queuedPages += preloadNextPages(page, preloadSize) + val queuedPages = mutableListOf() + if (page.status == Page.State.QUEUE) { + queuedPages += PriorityPage(page, 1).also { queue.offer(it) } + } + queuedPages += preloadNextPages(page, preloadSize) - suspendCancellableCoroutine { continuation -> - continuation.invokeOnCancellation { - queuedPages.forEach { - if (it.page.status == Page.State.QUEUE) { - queue.remove(it) - } + suspendCancellableCoroutine { continuation -> + continuation.invokeOnCancellation { + queuedPages.forEach { + if (it.page.status == Page.State.QUEUE) { + queue.remove(it) } } } @@ -128,8 +124,7 @@ internal class HttpPageLoader( queue.clear() // Cache current page list progress for online chapters to allow a faster reopen - val pages = chapter.pages - if (pages != null) { + chapter.pages?.let { pages -> launchIO { try { // Convert to pages without reader information @@ -171,7 +166,7 @@ internal class HttpPageLoader( * * @param page the page whose source image has to be downloaded. */ - private suspend fun _loadPage(page: ReaderPage) { + private suspend fun internalLoadPage(page: ReaderPage) { try { if (page.imageUrl.isNullOrEmpty()) { page.status = Page.State.LOAD_PAGE diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt index 11125ac77..6aad27710 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderSettingsScreenModel.kt @@ -3,13 +3,11 @@ package eu.kanade.tachiyomi.ui.reader.setting import cafe.adriel.voyager.core.model.ScreenModel import eu.kanade.presentation.util.ioCoroutineScope import eu.kanade.tachiyomi.ui.reader.ReaderViewModel -import eu.kanade.tachiyomi.util.preference.toggle import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn -import tachiyomi.core.preference.Preference import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -29,8 +27,4 @@ class ReaderSettingsScreenModel( .map { it.manga } .distinctUntilChanged() .stateIn(ioCoroutineScope, SharingStarted.Lazily, null) - - fun togglePreference(preference: (ReaderPreferences) -> Preference) { - preference(preferences).toggle() - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt deleted file mode 100644 index 887fc7e2e..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt +++ /dev/null @@ -1,16 +0,0 @@ -package eu.kanade.tachiyomi.util.preference - -import tachiyomi.core.preference.Preference - -operator fun Preference>.plusAssign(item: T) { - set(get() + item) -} - -operator fun Preference>.minusAssign(item: T) { - set(get() - item) -} - -fun Preference.toggle(): Boolean { - set(!get()) - return get() -} diff --git a/core/src/main/java/tachiyomi/core/preference/Preference.kt b/core/src/main/java/tachiyomi/core/preference/Preference.kt index c276141e9..67b7a44f4 100644 --- a/core/src/main/java/tachiyomi/core/preference/Preference.kt +++ b/core/src/main/java/tachiyomi/core/preference/Preference.kt @@ -24,3 +24,16 @@ interface Preference { } inline fun Preference.getAndSet(crossinline block: (T) -> R) = set(block(get())) + +operator fun Preference>.plusAssign(item: T) { + set(get() + item) +} + +operator fun Preference>.minusAssign(item: T) { + set(get() - item) +} + +fun Preference.toggle(): Boolean { + set(!get()) + return get() +} diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt index c980e98be..70b1599fc 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt @@ -39,8 +39,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp +import tachiyomi.core.preference.Preference import tachiyomi.core.preference.TriState +import tachiyomi.core.preference.toggle import tachiyomi.presentation.core.theme.header +import tachiyomi.presentation.core.util.collectAsState object SettingsItemsPaddings { val Horizontal = 24.dp @@ -118,6 +121,19 @@ fun SortItem( ) } +@Composable +fun CheckboxItem( + label: String, + pref: Preference, +) { + val checked by pref.collectAsState() + CheckboxItem( + label = label, + checked = checked, + onClick = { pref.toggle() }, + ) +} + @Composable fun CheckboxItem( label: String, diff --git a/app/src/main/java/eu/kanade/presentation/util/Preference.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/util/Preference.kt similarity index 90% rename from app/src/main/java/eu/kanade/presentation/util/Preference.kt rename to presentation-core/src/main/java/tachiyomi/presentation/core/util/Preference.kt index 4b67009c6..c68818927 100644 --- a/app/src/main/java/eu/kanade/presentation/util/Preference.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/util/Preference.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.util +package tachiyomi.presentation.core.util import androidx.compose.runtime.Composable import androidx.compose.runtime.State