Clean up preference extensions/items a bit

This commit is contained in:
arkon 2023-07-19 21:57:22 -04:00
parent 7a4680603d
commit cf14831fbe
24 changed files with 101 additions and 219 deletions

View File

@ -31,7 +31,7 @@ class PreferenceMutableState<T>(
} }
override fun component2(): (T) -> Unit { override fun component2(): (T) -> Unit {
return { preference.set(it) } return preference::set
} }
} }

View File

@ -16,7 +16,6 @@ import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.kanade.presentation.components.TabbedDialog import eu.kanade.presentation.components.TabbedDialog
import eu.kanade.presentation.components.TabbedDialogPaddings import eu.kanade.presentation.components.TabbedDialogPaddings
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel
import tachiyomi.core.preference.TriState 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.SliderItem
import tachiyomi.presentation.core.components.SortItem import tachiyomi.presentation.core.components.SortItem
import tachiyomi.presentation.core.components.TriStateItem import tachiyomi.presentation.core.components.TriStateItem
import tachiyomi.presentation.core.util.collectAsState
@Composable @Composable
fun LibrarySettingsDialog( fun LibrarySettingsDialog(
@ -211,59 +211,35 @@ private fun ColumnScope.DisplayPage(
} else { } else {
stringResource(R.string.label_default) stringResource(R.string.label_default)
}, },
onChange = { columnPreference.set(it) }, onChange = columnPreference::set,
) )
} }
HeadingItem(R.string.overlay_header) HeadingItem(R.string.overlay_header)
val downloadBadge by screenModel.libraryPreferences.downloadBadge().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.action_display_download_badge), label = stringResource(R.string.action_display_download_badge),
checked = downloadBadge, pref = screenModel.libraryPreferences.downloadBadge(),
onClick = {
screenModel.togglePreference(LibraryPreferences::downloadBadge)
},
) )
val localBadge by screenModel.libraryPreferences.localBadge().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.action_display_local_badge), label = stringResource(R.string.action_display_local_badge),
checked = localBadge, pref = screenModel.libraryPreferences.localBadge(),
onClick = {
screenModel.togglePreference(LibraryPreferences::localBadge)
},
) )
val languageBadge by screenModel.libraryPreferences.languageBadge().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.action_display_language_badge), label = stringResource(R.string.action_display_language_badge),
checked = languageBadge, pref = screenModel.libraryPreferences.languageBadge(),
onClick = {
screenModel.togglePreference(LibraryPreferences::languageBadge)
},
) )
val showContinueReadingButton by screenModel.libraryPreferences.showContinueReadingButton().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.action_display_show_continue_reading_button), label = stringResource(R.string.action_display_show_continue_reading_button),
checked = showContinueReadingButton, pref = screenModel.libraryPreferences.showContinueReadingButton(),
onClick = {
screenModel.togglePreference(LibraryPreferences::showContinueReadingButton)
},
) )
HeadingItem(R.string.tabs_header) HeadingItem(R.string.tabs_header)
val categoryTabs by screenModel.libraryPreferences.categoryTabs().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.action_display_show_tabs), label = stringResource(R.string.action_display_show_tabs),
checked = categoryTabs, pref = screenModel.libraryPreferences.categoryTabs(),
onClick = {
screenModel.togglePreference(LibraryPreferences::categoryTabs)
},
) )
val categoryNumberOfItems by screenModel.libraryPreferences.categoryNumberOfItems().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.action_display_show_number_of_items), label = stringResource(R.string.action_display_show_number_of_items),
checked = categoryNumberOfItems, pref = screenModel.libraryPreferences.categoryNumberOfItems(),
onClick = {
screenModel.togglePreference(LibraryPreferences::categoryNumberOfItems)
},
) )
} }

View File

@ -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.SwitchPreferenceWidget
import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget
import eu.kanade.presentation.more.settings.widget.TrackingPreferenceWidget import eu.kanade.presentation.more.settings.widget.TrackingPreferenceWidget
import eu.kanade.presentation.util.collectAsState
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import tachiyomi.core.preference.PreferenceStore import tachiyomi.core.preference.PreferenceStore
import tachiyomi.presentation.core.components.SliderItem import tachiyomi.presentation.core.components.SliderItem
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get

View File

@ -30,7 +30,6 @@ import eu.kanade.domain.base.BasePreferences
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.more.settings.screen.advanced.ClearDatabaseScreen import eu.kanade.presentation.more.settings.screen.advanced.ClearDatabaseScreen
import eu.kanade.presentation.more.settings.screen.debug.DebugInfoScreen import eu.kanade.presentation.more.settings.screen.debug.DebugInfoScreen
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.download.DownloadCache 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.core.util.system.logcat
import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.repository.MangaRepository import tachiyomi.domain.manga.repository.MangaRepository
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.File import java.io.File

View File

@ -21,7 +21,6 @@ import eu.kanade.domain.ui.model.TabletUiMode
import eu.kanade.domain.ui.model.ThemeMode import eu.kanade.domain.ui.model.ThemeMode
import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.toast 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.drop
import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.merge
import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParser
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.Date import java.util.Date

View File

@ -42,7 +42,6 @@ import androidx.core.net.toUri
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.presentation.extensions.RequestStoragePermission import eu.kanade.presentation.extensions.RequestStoragePermission
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.backup.BackupConst import eu.kanade.tachiyomi.data.backup.BackupConst
import eu.kanade.tachiyomi.data.backup.BackupCreateJob import eu.kanade.tachiyomi.data.backup.BackupCreateJob
@ -57,6 +56,7 @@ import kotlinx.coroutines.launch
import tachiyomi.domain.backup.service.BackupPreferences import tachiyomi.domain.backup.service.BackupPreferences
import tachiyomi.presentation.core.components.ScrollbarLazyColumn import tachiyomi.presentation.core.components.ScrollbarLazyColumn
import tachiyomi.presentation.core.components.material.Divider import tachiyomi.presentation.core.components.material.Divider
import tachiyomi.presentation.core.util.collectAsState
import tachiyomi.presentation.core.util.isScrolledToEnd import tachiyomi.presentation.core.util.isScrolledToEnd
import tachiyomi.presentation.core.util.isScrolledToStart import tachiyomi.presentation.core.util.isScrolledToStart
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt

View File

@ -22,12 +22,12 @@ import com.hippo.unifile.UniFile
import eu.kanade.presentation.category.visualName import eu.kanade.presentation.category.visualName
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.more.settings.widget.TriStateListDialog import eu.kanade.presentation.more.settings.widget.TriStateListDialog
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import tachiyomi.domain.category.interactor.GetCategories import tachiyomi.domain.category.interactor.GetCategories
import tachiyomi.domain.category.model.Category import tachiyomi.domain.category.model.Category
import tachiyomi.domain.download.service.DownloadPreferences import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.File import java.io.File

View File

@ -36,7 +36,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.presentation.category.visualName import eu.kanade.presentation.category.visualName
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.more.settings.widget.TriStateListDialog import eu.kanade.presentation.more.settings.widget.TriStateListDialog
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
import eu.kanade.tachiyomi.data.track.TrackManager 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.library.service.LibraryPreferences.Companion.MANGA_OUTSIDE_RELEASE_PERIOD
import tachiyomi.domain.manga.interactor.MAX_GRACE_PERIOD import tachiyomi.domain.manga.interactor.MAX_GRACE_PERIOD
import tachiyomi.presentation.core.components.WheelTextPicker import tachiyomi.presentation.core.components.WheelTextPicker
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get

View File

@ -9,12 +9,12 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
import eu.kanade.tachiyomi.util.system.isReleaseBuildType import eu.kanade.tachiyomi.util.system.isReleaseBuildType
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.text.NumberFormat import java.text.NumberFormat

View File

@ -10,11 +10,11 @@ import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.core.security.SecurityPreferences import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get

View File

@ -11,14 +11,13 @@ import androidx.core.graphics.alpha
import androidx.core.graphics.blue import androidx.core.graphics.blue
import androidx.core.graphics.green import androidx.core.graphics.green
import androidx.core.graphics.red import androidx.core.graphics.red
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel
import tachiyomi.core.preference.getAndSet import tachiyomi.core.preference.getAndSet
import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.CheckboxItem
import tachiyomi.presentation.core.components.SettingsChipRow import tachiyomi.presentation.core.components.SettingsChipRow
import tachiyomi.presentation.core.components.SliderItem import tachiyomi.presentation.core.components.SliderItem
import tachiyomi.presentation.core.util.collectAsState
@Composable @Composable
internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) { internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel) {
@ -44,10 +43,7 @@ internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel)
val customBrightness by screenModel.preferences.customBrightness().collectAsState() val customBrightness by screenModel.preferences.customBrightness().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_custom_brightness), label = stringResource(R.string.pref_custom_brightness),
checked = customBrightness, pref = screenModel.preferences.customBrightness(),
onClick = {
screenModel.togglePreference(ReaderPreferences::customBrightness)
},
) )
/** /**
@ -71,10 +67,7 @@ internal fun ColumnScope.ColorFilterPage(screenModel: ReaderSettingsScreenModel)
val colorFilter by screenModel.preferences.colorFilter().collectAsState() val colorFilter by screenModel.preferences.colorFilter().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_custom_color_filter), label = stringResource(R.string.pref_custom_color_filter),
checked = colorFilter, pref = screenModel.preferences.colorFilter(),
onClick = {
screenModel.togglePreference(ReaderPreferences::colorFilter)
},
) )
if (colorFilter) { if (colorFilter) {
val colorFilterValue by screenModel.preferences.colorFilterValue().collectAsState() 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( CheckboxItem(
label = stringResource(R.string.pref_grayscale), label = stringResource(R.string.pref_grayscale),
checked = grayscale, pref = screenModel.preferences.grayscale(),
onClick = {
screenModel.togglePreference(ReaderPreferences::grayscale)
},
) )
val invertedColors by screenModel.preferences.invertedColors().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_inverted_colors), label = stringResource(R.string.pref_inverted_colors),
checked = invertedColors, pref = screenModel.preferences.invertedColors(),
onClick = {
screenModel.togglePreference(ReaderPreferences::invertedColors)
},
) )
} }

View File

@ -6,12 +6,11 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel
import tachiyomi.presentation.core.components.CheckboxItem import tachiyomi.presentation.core.components.CheckboxItem
import tachiyomi.presentation.core.components.SettingsChipRow import tachiyomi.presentation.core.components.SettingsChipRow
import tachiyomi.presentation.core.util.collectAsState
private val themes = listOf( private val themes = listOf(
R.string.black_background to 1, R.string.black_background to 1,
@ -33,67 +32,39 @@ internal fun ColumnScope.GeneralPage(screenModel: ReaderSettingsScreenModel) {
} }
} }
val showPageNumber by screenModel.preferences.showPageNumber().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_show_page_number), label = stringResource(R.string.pref_show_page_number),
checked = showPageNumber, pref = screenModel.preferences.showPageNumber(),
onClick = {
screenModel.togglePreference(ReaderPreferences::showPageNumber)
},
) )
val fullscreen by screenModel.preferences.fullscreen().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_fullscreen), label = stringResource(R.string.pref_fullscreen),
checked = fullscreen, pref = screenModel.preferences.fullscreen(),
onClick = {
screenModel.togglePreference(ReaderPreferences::fullscreen)
},
) )
// TODO: hide if there's no cutout // TODO: hide if there's no cutout
val cutoutShort by screenModel.preferences.cutoutShort().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_cutout_short), label = stringResource(R.string.pref_cutout_short),
checked = cutoutShort, pref = screenModel.preferences.cutoutShort(),
onClick = {
screenModel.togglePreference(ReaderPreferences::cutoutShort)
},
) )
val keepScreenOn by screenModel.preferences.keepScreenOn().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_keep_screen_on), label = stringResource(R.string.pref_keep_screen_on),
checked = keepScreenOn, pref = screenModel.preferences.keepScreenOn(),
onClick = {
screenModel.togglePreference(ReaderPreferences::keepScreenOn)
},
) )
val readWithLongTap by screenModel.preferences.readWithLongTap().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_read_with_long_tap), label = stringResource(R.string.pref_read_with_long_tap),
checked = readWithLongTap, pref = screenModel.preferences.readWithLongTap(),
onClick = {
screenModel.togglePreference(ReaderPreferences::readWithLongTap)
},
) )
val alwaysShowChapterTransition by screenModel.preferences.alwaysShowChapterTransition().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_always_show_chapter_transition), label = stringResource(R.string.pref_always_show_chapter_transition),
checked = alwaysShowChapterTransition, pref = screenModel.preferences.alwaysShowChapterTransition(),
onClick = {
screenModel.togglePreference(ReaderPreferences::alwaysShowChapterTransition)
},
) )
val pageTransitions by screenModel.preferences.pageTransitions().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_page_transitions), label = stringResource(R.string.pref_page_transitions),
checked = pageTransitions, pref = screenModel.preferences.pageTransitions(),
onClick = {
screenModel.togglePreference(ReaderPreferences::pageTransitions)
},
) )
} }

View File

@ -10,7 +10,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.kanade.domain.manga.model.orientationType import eu.kanade.domain.manga.model.orientationType
import eu.kanade.domain.manga.model.readingModeType import eu.kanade.domain.manga.model.readingModeType
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences 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.HeadingItem
import tachiyomi.presentation.core.components.SettingsChipRow import tachiyomi.presentation.core.components.SettingsChipRow
import tachiyomi.presentation.core.components.SliderItem import tachiyomi.presentation.core.components.SliderItem
import tachiyomi.presentation.core.util.collectAsState
import java.text.NumberFormat import java.text.NumberFormat
private val readingModeOptions = ReadingModeType.entries.map { it.stringRes to it } 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( CheckboxItem(
label = stringResource(R.string.pref_crop_borders), label = stringResource(R.string.pref_crop_borders),
checked = cropBorders, pref = screenModel.preferences.cropBorders(),
onClick = {
screenModel.togglePreference(ReaderPreferences::cropBorders)
},
) )
val landscapeZoom by screenModel.preferences.landscapeZoom().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_landscape_zoom), label = stringResource(R.string.pref_landscape_zoom),
checked = landscapeZoom, pref = screenModel.preferences.landscapeZoom(),
onClick = {
screenModel.togglePreference(ReaderPreferences::landscapeZoom)
},
) )
val navigateToPan by screenModel.preferences.navigateToPan().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_navigate_pan), label = stringResource(R.string.pref_navigate_pan),
checked = navigateToPan, pref = screenModel.preferences.navigateToPan(),
onClick = {
screenModel.togglePreference(ReaderPreferences::navigateToPan)
},
) )
val dualPageSplitPaged by screenModel.preferences.dualPageSplitPaged().collectAsState() val dualPageSplitPaged by screenModel.preferences.dualPageSplitPaged().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_dual_page_split), label = stringResource(R.string.pref_dual_page_split),
checked = dualPageSplitPaged, pref = screenModel.preferences.dualPageSplitPaged(),
onClick = {
screenModel.togglePreference(ReaderPreferences::dualPageSplitPaged)
},
) )
if (dualPageSplitPaged) { if (dualPageSplitPaged) {
val dualPageInvertPaged by screenModel.preferences.dualPageInvertPaged().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_dual_page_invert), label = stringResource(R.string.pref_dual_page_invert),
checked = dualPageInvertPaged, pref = screenModel.preferences.dualPageInvertPaged(),
onClick = {
screenModel.togglePreference(ReaderPreferences::dualPageInvertPaged)
},
) )
} }
val dualPageRotateToFit by screenModel.preferences.dualPageRotateToFit().collectAsState() val dualPageRotateToFit by screenModel.preferences.dualPageRotateToFit().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_page_rotate), label = stringResource(R.string.pref_page_rotate),
checked = dualPageRotateToFit, pref = screenModel.preferences.dualPageRotateToFit(),
onClick = {
screenModel.togglePreference(ReaderPreferences::dualPageRotateToFit)
},
) )
if (dualPageRotateToFit) { if (dualPageRotateToFit) {
val dualPageRotateToFitInvert by screenModel.preferences.dualPageRotateToFitInvert().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_page_rotate_invert), label = stringResource(R.string.pref_page_rotate_invert),
checked = dualPageRotateToFitInvert, pref = screenModel.preferences.dualPageRotateToFitInvert(),
onClick = {
screenModel.togglePreference(ReaderPreferences::dualPageRotateToFitInvert)
},
) )
} }
} }
@ -193,55 +167,34 @@ private fun ColumnScope.WebtoonViewerSettings(screenModel: ReaderSettingsScreenM
}, },
) )
val cropBordersWebtoon by screenModel.preferences.cropBordersWebtoon().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_crop_borders), label = stringResource(R.string.pref_crop_borders),
checked = cropBordersWebtoon, pref = screenModel.preferences.cropBordersWebtoon(),
onClick = {
screenModel.togglePreference(ReaderPreferences::cropBordersWebtoon)
},
) )
val dualPageSplitWebtoon by screenModel.preferences.dualPageSplitWebtoon().collectAsState() val dualPageSplitWebtoon by screenModel.preferences.dualPageSplitWebtoon().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_dual_page_split), label = stringResource(R.string.pref_dual_page_split),
checked = dualPageSplitWebtoon, pref = screenModel.preferences.dualPageSplitWebtoon(),
onClick = {
screenModel.togglePreference(ReaderPreferences::dualPageSplitWebtoon)
},
) )
if (dualPageSplitWebtoon) { if (dualPageSplitWebtoon) {
val dualPageInvertWebtoon by screenModel.preferences.dualPageInvertWebtoon()
.collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_dual_page_invert), label = stringResource(R.string.pref_dual_page_invert),
checked = dualPageInvertWebtoon, pref = screenModel.preferences.dualPageInvertWebtoon(),
onClick = {
screenModel.togglePreference(ReaderPreferences::dualPageInvertWebtoon)
},
) )
} }
if (!isReleaseBuildType) { if (!isReleaseBuildType) {
val longStripSplitWebtoon by screenModel.preferences.longStripSplitWebtoon()
.collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_long_strip_split), label = stringResource(R.string.pref_long_strip_split),
checked = longStripSplitWebtoon, pref = screenModel.preferences.longStripSplitWebtoon(),
onClick = {
screenModel.togglePreference(ReaderPreferences::longStripSplitWebtoon)
},
) )
} }
val webtoonDoubleTapZoomEnabled by screenModel.preferences.webtoonDoubleTapZoomEnabled().collectAsState()
CheckboxItem( CheckboxItem(
label = stringResource(R.string.pref_double_tap_zoom), label = stringResource(R.string.pref_double_tap_zoom),
checked = webtoonDoubleTapZoomEnabled, pref = screenModel.preferences.webtoonDoubleTapZoomEnabled(),
onClick = {
screenModel.togglePreference(ReaderPreferences::webtoonDoubleTapZoomEnabled)
},
) )
} }

View File

@ -14,8 +14,6 @@ import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences 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.DeviceUtil
import eu.kanade.tachiyomi.util.system.isReleaseBuildType import eu.kanade.tachiyomi.util.system.isReleaseBuildType
import eu.kanade.tachiyomi.util.system.toast 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.PreferenceStore
import tachiyomi.core.preference.TriState import tachiyomi.core.preference.TriState
import tachiyomi.core.preference.getEnum import tachiyomi.core.preference.getEnum
import tachiyomi.core.preference.minusAssign
import tachiyomi.core.preference.plusAssign
import tachiyomi.domain.backup.service.BackupPreferences import tachiyomi.domain.backup.service.BackupPreferences
import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED

View File

@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.extension.model.LoadResult
import eu.kanade.tachiyomi.extension.util.ExtensionInstallReceiver import eu.kanade.tachiyomi.extension.util.ExtensionInstallReceiver
import eu.kanade.tachiyomi.extension.util.ExtensionInstaller import eu.kanade.tachiyomi.extension.util.ExtensionInstaller
import eu.kanade.tachiyomi.extension.util.ExtensionLoader import eu.kanade.tachiyomi.extension.util.ExtensionLoader
import eu.kanade.tachiyomi.util.preference.plusAssign
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -19,6 +18,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.emptyFlow
import logcat.LogPriority import logcat.LogPriority
import tachiyomi.core.preference.plusAssign
import tachiyomi.core.util.lang.launchNow import tachiyomi.core.util.lang.launchNow
import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.lang.withUIContext
import tachiyomi.core.util.system.logcat import tachiyomi.core.util.system.logcat

View File

@ -4,7 +4,6 @@ import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.coroutineScope import cafe.adriel.voyager.core.model.coroutineScope
import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.util.preference.toggle
import tachiyomi.core.preference.Preference import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.TriState import tachiyomi.core.preference.TriState
import tachiyomi.core.preference.getAndSet import tachiyomi.core.preference.getAndSet
@ -29,10 +28,6 @@ class LibrarySettingsScreenModel(
val trackServices val trackServices
get() = trackManager.services.filter { it.isLogged } get() = trackManager.services.filter { it.isLogged }
fun togglePreference(preference: (LibraryPreferences) -> Preference<Boolean>) {
preference(libraryPreferences).toggle()
}
fun toggleFilter(preference: (LibraryPreferences) -> Preference<TriState>) { fun toggleFilter(preference: (LibraryPreferences) -> Preference<TriState>) {
preference(libraryPreferences).getAndSet { preference(libraryPreferences).getAndSet {
it.next() it.next()

View File

@ -59,7 +59,6 @@ import eu.kanade.presentation.components.IncognitoModeBannerBackgroundColor
import eu.kanade.presentation.components.IndexingBannerBackgroundColor import eu.kanade.presentation.components.IndexingBannerBackgroundColor
import eu.kanade.presentation.util.AssistContentScreen import eu.kanade.presentation.util.AssistContentScreen
import eu.kanade.presentation.util.DefaultNavigatorScreenTransition import eu.kanade.presentation.util.DefaultNavigatorScreenTransition
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.Migrations
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -93,6 +92,7 @@ import tachiyomi.core.util.system.logcat
import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.release.interactor.GetApplicationRelease import tachiyomi.domain.release.interactor.GetApplicationRelease
import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy

View File

@ -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.ReaderProgressIndicator
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
import eu.kanade.tachiyomi.ui.webview.WebViewActivity 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.applySystemAnimatorScale
import eu.kanade.tachiyomi.util.system.hasDisplayCutout import eu.kanade.tachiyomi.util.system.hasDisplayCutout
import eu.kanade.tachiyomi.util.system.isNightMode import eu.kanade.tachiyomi.util.system.isNightMode
@ -95,6 +94,7 @@ import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import logcat.LogPriority import logcat.LogPriority
import tachiyomi.core.Constants import tachiyomi.core.Constants
import tachiyomi.core.preference.toggle
import tachiyomi.core.util.lang.launchIO import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNonCancellable import tachiyomi.core.util.lang.launchNonCancellable
import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.lang.withUIContext

View File

@ -50,9 +50,7 @@ internal class HttpPageLoader(
} }
} }
.filter { it.status == Page.State.QUEUE } .filter { it.status == Page.State.QUEUE }
.collect { .collect(::internalLoadPage)
_loadPage(it)
}
} }
} }
@ -80,32 +78,30 @@ internal class HttpPageLoader(
/** /**
* Loads a page through the queue. Handles re-enqueueing pages if they were evicted from the cache. * Loads a page through the queue. Handles re-enqueueing pages if they were evicted from the cache.
*/ */
override suspend fun loadPage(page: ReaderPage) { override suspend fun loadPage(page: ReaderPage) = withIOContext {
withIOContext { val imageUrl = page.imageUrl
val imageUrl = page.imageUrl
// Check if the image has been deleted // Check if the image has been deleted
if (page.status == Page.State.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) { if (page.status == Page.State.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) {
page.status = Page.State.QUEUE page.status = Page.State.QUEUE
} }
// Automatically retry failed pages when subscribed to this page // Automatically retry failed pages when subscribed to this page
if (page.status == Page.State.ERROR) { if (page.status == Page.State.ERROR) {
page.status = Page.State.QUEUE page.status = Page.State.QUEUE
} }
val queuedPages = mutableListOf<PriorityPage>() val queuedPages = mutableListOf<PriorityPage>()
if (page.status == Page.State.QUEUE) { if (page.status == Page.State.QUEUE) {
queuedPages += PriorityPage(page, 1).also { queue.offer(it) } queuedPages += PriorityPage(page, 1).also { queue.offer(it) }
} }
queuedPages += preloadNextPages(page, preloadSize) queuedPages += preloadNextPages(page, preloadSize)
suspendCancellableCoroutine<Nothing> { continuation -> suspendCancellableCoroutine<Nothing> { continuation ->
continuation.invokeOnCancellation { continuation.invokeOnCancellation {
queuedPages.forEach { queuedPages.forEach {
if (it.page.status == Page.State.QUEUE) { if (it.page.status == Page.State.QUEUE) {
queue.remove(it) queue.remove(it)
}
} }
} }
} }
@ -128,8 +124,7 @@ internal class HttpPageLoader(
queue.clear() queue.clear()
// Cache current page list progress for online chapters to allow a faster reopen // Cache current page list progress for online chapters to allow a faster reopen
val pages = chapter.pages chapter.pages?.let { pages ->
if (pages != null) {
launchIO { launchIO {
try { try {
// Convert to pages without reader information // Convert to pages without reader information
@ -171,7 +166,7 @@ internal class HttpPageLoader(
* *
* @param page the page whose source image has to be downloaded. * @param page the page whose source image has to be downloaded.
*/ */
private suspend fun _loadPage(page: ReaderPage) { private suspend fun internalLoadPage(page: ReaderPage) {
try { try {
if (page.imageUrl.isNullOrEmpty()) { if (page.imageUrl.isNullOrEmpty()) {
page.status = Page.State.LOAD_PAGE page.status = Page.State.LOAD_PAGE

View File

@ -3,13 +3,11 @@ package eu.kanade.tachiyomi.ui.reader.setting
import cafe.adriel.voyager.core.model.ScreenModel import cafe.adriel.voyager.core.model.ScreenModel
import eu.kanade.presentation.util.ioCoroutineScope import eu.kanade.presentation.util.ioCoroutineScope
import eu.kanade.tachiyomi.ui.reader.ReaderViewModel import eu.kanade.tachiyomi.ui.reader.ReaderViewModel
import eu.kanade.tachiyomi.util.preference.toggle
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import tachiyomi.core.preference.Preference
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -29,8 +27,4 @@ class ReaderSettingsScreenModel(
.map { it.manga } .map { it.manga }
.distinctUntilChanged() .distinctUntilChanged()
.stateIn(ioCoroutineScope, SharingStarted.Lazily, null) .stateIn(ioCoroutineScope, SharingStarted.Lazily, null)
fun togglePreference(preference: (ReaderPreferences) -> Preference<Boolean>) {
preference(preferences).toggle()
}
} }

View File

@ -1,16 +0,0 @@
package eu.kanade.tachiyomi.util.preference
import tachiyomi.core.preference.Preference
operator fun <T> Preference<Set<T>>.plusAssign(item: T) {
set(get() + item)
}
operator fun <T> Preference<Set<T>>.minusAssign(item: T) {
set(get() - item)
}
fun Preference<Boolean>.toggle(): Boolean {
set(!get())
return get()
}

View File

@ -24,3 +24,16 @@ interface Preference<T> {
} }
inline fun <reified T, R : T> Preference<T>.getAndSet(crossinline block: (T) -> R) = set(block(get())) inline fun <reified T, R : T> Preference<T>.getAndSet(crossinline block: (T) -> R) = set(block(get()))
operator fun <T> Preference<Set<T>>.plusAssign(item: T) {
set(get() + item)
}
operator fun <T> Preference<Set<T>>.minusAssign(item: T) {
set(get() - item)
}
fun Preference<Boolean>.toggle(): Boolean {
set(!get())
return get()
}

View File

@ -39,8 +39,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.TriState import tachiyomi.core.preference.TriState
import tachiyomi.core.preference.toggle
import tachiyomi.presentation.core.theme.header import tachiyomi.presentation.core.theme.header
import tachiyomi.presentation.core.util.collectAsState
object SettingsItemsPaddings { object SettingsItemsPaddings {
val Horizontal = 24.dp val Horizontal = 24.dp
@ -118,6 +121,19 @@ fun SortItem(
) )
} }
@Composable
fun CheckboxItem(
label: String,
pref: Preference<Boolean>,
) {
val checked by pref.collectAsState()
CheckboxItem(
label = label,
checked = checked,
onClick = { pref.toggle() },
)
}
@Composable @Composable
fun CheckboxItem( fun CheckboxItem(
label: String, label: String,

View File

@ -1,4 +1,4 @@
package eu.kanade.presentation.util package tachiyomi.presentation.core.util
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.State import androidx.compose.runtime.State