From be54b8862e53af94f08549cbfae0afb2cc4c2f3e Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 26 Mar 2023 13:27:31 -0400 Subject: [PATCH] Refactor away some unnecessary lambda expressions --- .../java/eu/kanade/core/util/CollectionUtils.kt | 6 +++--- .../presentation/browse/GlobalSearchScreen.kt | 2 +- .../presentation/browse/MigrateSearchScreen.kt | 2 +- .../tachiyomi/data/backup/BackupManager.kt | 2 +- .../ui/base/delegate/SecureActivityDelegate.kt | 2 +- .../ui/base/delegate/ThemingDelegate.kt | 2 +- .../ui/browse/extension/ExtensionFilterScreen.kt | 2 +- .../ui/browse/extension/ExtensionsScreenModel.kt | 2 +- .../extension/details/ExtensionDetailsScreen.kt | 6 +++--- .../migration/search/SourceSearchScreen.kt | 2 +- .../browse/source/browse/BrowseSourceScreen.kt | 14 ++++---------- .../eu/kanade/tachiyomi/ui/library/LibraryTab.kt | 4 ++-- .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 16 ++++++++-------- .../reader/setting/ReaderColorFilterSettings.kt | 8 ++++---- .../reader/viewer/pager/PagerTransitionHolder.kt | 2 +- .../ui/reader/viewer/pager/PagerViewer.kt | 12 ++++-------- 16 files changed, 37 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/eu/kanade/core/util/CollectionUtils.kt b/app/src/main/java/eu/kanade/core/util/CollectionUtils.kt index 07d5933ad0..5017631501 100644 --- a/app/src/main/java/eu/kanade/core/util/CollectionUtils.kt +++ b/app/src/main/java/eu/kanade/core/util/CollectionUtils.kt @@ -12,10 +12,10 @@ fun List.insertSeparators( val newList = mutableListOf() for (i in -1..lastIndex) { val before = getOrNull(i) - before?.let { newList.add(it) } + before?.let(newList::add) val after = getOrNull(i + 1) val separator = generator.invoke(before, after) - separator?.let { newList.add(it) } + separator?.let(newList::add) } return newList } @@ -80,7 +80,7 @@ inline fun List.fastMapNotNull(transform: (T) -> R?): List { contract { callsInPlace(transform) } val destination = ArrayList() fastForEach { element -> - transform(element)?.let { destination.add(it) } + transform(element)?.let(destination::add) } return destination } diff --git a/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt index 9735e75361..b9a8f636e6 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt @@ -96,7 +96,7 @@ private fun GlobalSearchContent( GlobalSearchCardRow( titles = result.result, - getManga = { getManga(it) }, + getManga = getManga, onClick = onClickItem, onLongClick = onLongClickItem, ) diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt index a424de8091..4b7b70c45a 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt @@ -85,7 +85,7 @@ private fun MigrateSearchContent( GlobalSearchCardRow( titles = result.result, - getManga = { getManga(it) }, + getManga = getManga, onClick = onClickItem, onLongClick = onLongClickItem, ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index 7631de36a7..c169db30c5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -141,7 +141,7 @@ class BackupManager( .map(Manga::source) .distinct() .map(sourceManager::getOrStub) - .map { BackupSource.copyFrom(it) } + .map(BackupSource::copyFrom) .toList() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt index 178a8704f4..02589cec98 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt @@ -97,7 +97,7 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser secureScreen == SecurityPreferences.SecureScreenMode.ALWAYS || secureScreen == SecurityPreferences.SecureScreenMode.INCOGNITO && incognitoMode } - .onEach { activity.window.setSecureScreen(it) } + .onEach(activity.window::setSecureScreen) .launchIn(activity.lifecycleScope) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt index 4ad7474fe3..c8846a34cf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt @@ -62,6 +62,6 @@ class ThemingDelegateImpl : ThemingDelegate { override fun applyAppTheme(activity: Activity) { val uiPreferences = Injekt.get() ThemingDelegate.getThemeResIds(uiPreferences.appTheme().get(), uiPreferences.themeDarkAmoled().get()) - .forEach { activity.setTheme(it) } + .forEach(activity::setTheme) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterScreen.kt index 5ef6120927..53e709528a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterScreen.kt @@ -34,7 +34,7 @@ class ExtensionFilterScreen : Screen() { ExtensionFilterScreen( navigateUp = navigator::pop, state = successState, - onClickToggle = { screenModel.toggle(it) }, + onClickToggle = screenModel::toggle, ) LaunchedEffect(Unit) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt index f701cb27df..10677639fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt @@ -141,7 +141,7 @@ class ExtensionsScreenModel( else -> it.extension } } - .forEach { updateExtension(it) } + .forEach(::updateExtension) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreen.kt index 7d071e90fe..1797dc89d8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreen.kt @@ -40,9 +40,9 @@ data class ExtensionDetailsScreen( onClickReadme = { uriHandler.openUri(screenModel.getReadmeUrl()) }, onClickEnableAll = { screenModel.toggleSources(true) }, onClickDisableAll = { screenModel.toggleSources(false) }, - onClickClearCookies = { screenModel.clearCookies() }, - onClickUninstall = { screenModel.uninstallExtension() }, - onClickSource = { screenModel.toggleSource(it) }, + onClickClearCookies = screenModel::clearCookies, + onClickUninstall = screenModel::uninstallExtension, + onClickSource = screenModel::toggleSource, ) LaunchedEffect(Unit) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchScreen.kt index 8c8b949c55..e512d90cf8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchScreen.kt @@ -58,7 +58,7 @@ data class SourceSearchScreen( searchQuery = state.toolbarQuery ?: "", onChangeSearchQuery = screenModel::setToolbarQuery, onClickCloseSearch = navigator::pop, - onSearch = { screenModel.search(it) }, + onSearch = screenModel::search, scrollBehavior = scrollBehavior, ) }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt index b3da4642f8..b5f461f5e8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt @@ -126,7 +126,7 @@ data class BrowseSourceScreen( onWebViewClick = onWebViewClick, onHelpClick = onHelpClick, onSettingsClick = { navigator.push(SourcePreferencesScreen(sourceId)) }, - onSearch = { screenModel.search(it) }, + onSearch = screenModel::search, ) Row( @@ -235,15 +235,9 @@ data class BrowseSourceScreen( SourceFilterDialog( onDismissRequest = onDismissRequest, filters = state.filters, - onReset = { - screenModel.resetFilters() - }, - onFilter = { - screenModel.search(filters = state.filters) - }, - onUpdate = { - screenModel.setFilters(it) - }, + onReset = screenModel::resetFilters, + onFilter = { screenModel.search(filters = state.filters) }, + onUpdate = screenModel::setFilters, ) } is BrowseSourceScreenModel.Dialog.AddDuplicateManga -> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt index 52c85e72a6..0f62a6eb9b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt @@ -117,7 +117,7 @@ object LibraryTab : Tab { onClickUnselectAll = screenModel::clearSelection, onClickSelectAll = { screenModel.selectAll(screenModel.activeCategoryIndex) }, onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategoryIndex) }, - onClickFilter = { screenModel.showSettingsDialog() }, + onClickFilter = screenModel::showSettingsDialog, onClickRefresh = { onClickRefresh(state.categories[screenModel.activeCategoryIndex]) }, onClickGlobalUpdate = { onClickRefresh(null) }, onClickOpenRandomManga = { @@ -186,7 +186,7 @@ object LibraryTab : Tab { } Unit }.takeIf { state.showMangaContinueButton }, - onToggleSelection = { screenModel.toggleSelection(it) }, + onToggleSelection = screenModel::toggleSelection, onToggleRangeSelection = { screenModel.toggleRangeSelection(it) haptic.performHapticFeedback(HapticFeedbackType.LongPress) 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 06cbf8663b..ee6f3c2d3f 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 @@ -1039,29 +1039,29 @@ class ReaderActivity : BaseActivity() { .launchIn(lifecycleScope) readerPreferences.showPageNumber().changes() - .onEach { setPageNumberVisibility(it) } + .onEach(::setPageNumberVisibility) .launchIn(lifecycleScope) readerPreferences.trueColor().changes() - .onEach { setTrueColor(it) } + .onEach(::setTrueColor) .launchIn(lifecycleScope) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { readerPreferences.cutoutShort().changes() - .onEach { setCutoutShort(it) } + .onEach(::setCutoutShort) .launchIn(lifecycleScope) } readerPreferences.keepScreenOn().changes() - .onEach { setKeepScreenOn(it) } + .onEach(::setKeepScreenOn) .launchIn(lifecycleScope) readerPreferences.customBrightness().changes() - .onEach { setCustomBrightness(it) } + .onEach(::setCustomBrightness) .launchIn(lifecycleScope) readerPreferences.colorFilter().changes() - .onEach { setColorFilter(it) } + .onEach(::setColorFilter) .launchIn(lifecycleScope) readerPreferences.colorFilterMode().changes() @@ -1138,7 +1138,7 @@ class ReaderActivity : BaseActivity() { if (enabled) { readerPreferences.customBrightnessValue().changes() .sample(100) - .onEach { setCustomBrightnessValue(it) } + .onEach(::setCustomBrightnessValue) .launchIn(lifecycleScope) } else { setCustomBrightnessValue(0) @@ -1152,7 +1152,7 @@ class ReaderActivity : BaseActivity() { if (enabled) { readerPreferences.colorFilterValue().changes() .sample(100) - .onEach { setColorFilterValue(it) } + .onEach(::setColorFilterValue) .launchIn(lifecycleScope) } else { binding.colorOverlay.isVisible = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt index 2695ce198b..7f76dbb764 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt @@ -33,7 +33,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr addView(binding.root) readerPreferences.colorFilter().changes() - .onEach { setColorFilter(it) } + .onEach(::setColorFilter) .launchIn((context as ReaderActivity).lifecycleScope) readerPreferences.colorFilterMode().changes() @@ -41,7 +41,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr .launchIn(context.lifecycleScope) readerPreferences.customBrightness().changes() - .onEach { setCustomBrightness(it) } + .onEach(::setCustomBrightness) .launchIn(context.lifecycleScope) // Get color and update values @@ -141,7 +141,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr if (enabled) { readerPreferences.customBrightnessValue().changes() .sample(100) - .onEach { setCustomBrightnessValue(it) } + .onEach(::setCustomBrightnessValue) .launchIn((context as ReaderActivity).lifecycleScope) } else { setCustomBrightnessValue(0, true) @@ -169,7 +169,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr if (enabled) { readerPreferences.colorFilterValue().changes() .sample(100) - .onEach { setColorFilterValue(it) } + .onEach(::setColorFilterValue) .launchIn((context as ReaderActivity).lifecycleScope) } setColorFilterSeekBar(enabled) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt index d11ef8e4d6..7ba46f5e00 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt @@ -63,7 +63,7 @@ class PagerTransitionHolder( transitionView.bind(transition, viewer.downloadManager, viewer.activity.viewModel.manga) - transition.to?.let { observeStatus(it) } + transition.to?.let(::observeStatus) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index 94e8de16f4..2bbc88913d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -74,9 +74,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { setChaptersInternal(viewerChapters) awaitingIdleViewerChapters = null if (viewerChapters.currChapter.pages?.size == 1) { - adapter.nextTransition?.to?.let { - activity.requestPreloadChapter(it) - } + adapter.nextTransition?.to?.let(activity::requestPreloadChapter) } } } @@ -234,9 +232,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { val inPreloadRange = pages.size - page.number < 5 if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) { logcat { "Request preload next chapter because we're at page ${page.number} of ${pages.size}" } - adapter.nextTransition?.to?.let { - activity.requestPreloadChapter(it) - } + adapter.nextTransition?.to?.let(activity::requestPreloadChapter) } } @@ -320,7 +316,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { */ protected open fun moveRight() { if (pager.currentItem != adapter.count - 1) { - val holder = (currentPage as? ReaderPage)?.let { getPageHolder(it) } + val holder = (currentPage as? ReaderPage)?.let(::getPageHolder) if (holder != null && config.navigateToPan && holder.canPanRight()) { holder.panRight() } else { @@ -334,7 +330,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { */ protected open fun moveLeft() { if (pager.currentItem != 0) { - val holder = (currentPage as? ReaderPage)?.let { getPageHolder(it) } + val holder = (currentPage as? ReaderPage)?.let(::getPageHolder) if (holder != null && config.navigateToPan && holder.canPanLeft()) { holder.panLeft() } else {