Refactor away some unnecessary lambda expressions

This commit is contained in:
arkon 2023-03-26 13:27:31 -04:00
parent 1a61130f0b
commit be54b8862e
16 changed files with 37 additions and 47 deletions

View file

@ -12,10 +12,10 @@ fun <T : R, R : Any> List<T>.insertSeparators(
val newList = mutableListOf<R>()
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 <T, R> List<T>.fastMapNotNull(transform: (T) -> R?): List<R> {
contract { callsInPlace(transform) }
val destination = ArrayList<R>()
fastForEach { element ->
transform(element)?.let { destination.add(it) }
transform(element)?.let(destination::add)
}
return destination
}

View file

@ -96,7 +96,7 @@ private fun GlobalSearchContent(
GlobalSearchCardRow(
titles = result.result,
getManga = { getManga(it) },
getManga = getManga,
onClick = onClickItem,
onLongClick = onLongClickItem,
)

View file

@ -85,7 +85,7 @@ private fun MigrateSearchContent(
GlobalSearchCardRow(
titles = result.result,
getManga = { getManga(it) },
getManga = getManga,
onClick = onClickItem,
onLongClick = onLongClickItem,
)

View file

@ -141,7 +141,7 @@ class BackupManager(
.map(Manga::source)
.distinct()
.map(sourceManager::getOrStub)
.map { BackupSource.copyFrom(it) }
.map(BackupSource::copyFrom)
.toList()
}

View file

@ -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)
}

View file

@ -62,6 +62,6 @@ class ThemingDelegateImpl : ThemingDelegate {
override fun applyAppTheme(activity: Activity) {
val uiPreferences = Injekt.get<UiPreferences>()
ThemingDelegate.getThemeResIds(uiPreferences.appTheme().get(), uiPreferences.themeDarkAmoled().get())
.forEach { activity.setTheme(it) }
.forEach(activity::setTheme)
}
}

View file

@ -34,7 +34,7 @@ class ExtensionFilterScreen : Screen() {
ExtensionFilterScreen(
navigateUp = navigator::pop,
state = successState,
onClickToggle = { screenModel.toggle(it) },
onClickToggle = screenModel::toggle,
)
LaunchedEffect(Unit) {

View file

@ -141,7 +141,7 @@ class ExtensionsScreenModel(
else -> it.extension
}
}
.forEach { updateExtension(it) }
.forEach(::updateExtension)
}
}
}

View file

@ -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) {

View file

@ -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,
)
},

View file

@ -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 -> {

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -63,7 +63,7 @@ class PagerTransitionHolder(
transitionView.bind(transition, viewer.downloadManager, viewer.activity.viewModel.manga)
transition.to?.let { observeStatus(it) }
transition.to?.let(::observeStatus)
}
/**

View file

@ -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 {