mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +01:00
Refactor away some unnecessary lambda expressions
This commit is contained in:
parent
1a61130f0b
commit
be54b8862e
@ -12,10 +12,10 @@ fun <T : R, R : Any> List<T>.insertSeparators(
|
|||||||
val newList = mutableListOf<R>()
|
val newList = mutableListOf<R>()
|
||||||
for (i in -1..lastIndex) {
|
for (i in -1..lastIndex) {
|
||||||
val before = getOrNull(i)
|
val before = getOrNull(i)
|
||||||
before?.let { newList.add(it) }
|
before?.let(newList::add)
|
||||||
val after = getOrNull(i + 1)
|
val after = getOrNull(i + 1)
|
||||||
val separator = generator.invoke(before, after)
|
val separator = generator.invoke(before, after)
|
||||||
separator?.let { newList.add(it) }
|
separator?.let(newList::add)
|
||||||
}
|
}
|
||||||
return newList
|
return newList
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ inline fun <T, R> List<T>.fastMapNotNull(transform: (T) -> R?): List<R> {
|
|||||||
contract { callsInPlace(transform) }
|
contract { callsInPlace(transform) }
|
||||||
val destination = ArrayList<R>()
|
val destination = ArrayList<R>()
|
||||||
fastForEach { element ->
|
fastForEach { element ->
|
||||||
transform(element)?.let { destination.add(it) }
|
transform(element)?.let(destination::add)
|
||||||
}
|
}
|
||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ private fun GlobalSearchContent(
|
|||||||
|
|
||||||
GlobalSearchCardRow(
|
GlobalSearchCardRow(
|
||||||
titles = result.result,
|
titles = result.result,
|
||||||
getManga = { getManga(it) },
|
getManga = getManga,
|
||||||
onClick = onClickItem,
|
onClick = onClickItem,
|
||||||
onLongClick = onLongClickItem,
|
onLongClick = onLongClickItem,
|
||||||
)
|
)
|
||||||
|
@ -85,7 +85,7 @@ private fun MigrateSearchContent(
|
|||||||
|
|
||||||
GlobalSearchCardRow(
|
GlobalSearchCardRow(
|
||||||
titles = result.result,
|
titles = result.result,
|
||||||
getManga = { getManga(it) },
|
getManga = getManga,
|
||||||
onClick = onClickItem,
|
onClick = onClickItem,
|
||||||
onLongClick = onLongClickItem,
|
onLongClick = onLongClickItem,
|
||||||
)
|
)
|
||||||
|
@ -141,7 +141,7 @@ class BackupManager(
|
|||||||
.map(Manga::source)
|
.map(Manga::source)
|
||||||
.distinct()
|
.distinct()
|
||||||
.map(sourceManager::getOrStub)
|
.map(sourceManager::getOrStub)
|
||||||
.map { BackupSource.copyFrom(it) }
|
.map(BackupSource::copyFrom)
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser
|
|||||||
secureScreen == SecurityPreferences.SecureScreenMode.ALWAYS ||
|
secureScreen == SecurityPreferences.SecureScreenMode.ALWAYS ||
|
||||||
secureScreen == SecurityPreferences.SecureScreenMode.INCOGNITO && incognitoMode
|
secureScreen == SecurityPreferences.SecureScreenMode.INCOGNITO && incognitoMode
|
||||||
}
|
}
|
||||||
.onEach { activity.window.setSecureScreen(it) }
|
.onEach(activity.window::setSecureScreen)
|
||||||
.launchIn(activity.lifecycleScope)
|
.launchIn(activity.lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,6 @@ class ThemingDelegateImpl : ThemingDelegate {
|
|||||||
override fun applyAppTheme(activity: Activity) {
|
override fun applyAppTheme(activity: Activity) {
|
||||||
val uiPreferences = Injekt.get<UiPreferences>()
|
val uiPreferences = Injekt.get<UiPreferences>()
|
||||||
ThemingDelegate.getThemeResIds(uiPreferences.appTheme().get(), uiPreferences.themeDarkAmoled().get())
|
ThemingDelegate.getThemeResIds(uiPreferences.appTheme().get(), uiPreferences.themeDarkAmoled().get())
|
||||||
.forEach { activity.setTheme(it) }
|
.forEach(activity::setTheme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class ExtensionFilterScreen : Screen() {
|
|||||||
ExtensionFilterScreen(
|
ExtensionFilterScreen(
|
||||||
navigateUp = navigator::pop,
|
navigateUp = navigator::pop,
|
||||||
state = successState,
|
state = successState,
|
||||||
onClickToggle = { screenModel.toggle(it) },
|
onClickToggle = screenModel::toggle,
|
||||||
)
|
)
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
@ -141,7 +141,7 @@ class ExtensionsScreenModel(
|
|||||||
else -> it.extension
|
else -> it.extension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.forEach { updateExtension(it) }
|
.forEach(::updateExtension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ data class ExtensionDetailsScreen(
|
|||||||
onClickReadme = { uriHandler.openUri(screenModel.getReadmeUrl()) },
|
onClickReadme = { uriHandler.openUri(screenModel.getReadmeUrl()) },
|
||||||
onClickEnableAll = { screenModel.toggleSources(true) },
|
onClickEnableAll = { screenModel.toggleSources(true) },
|
||||||
onClickDisableAll = { screenModel.toggleSources(false) },
|
onClickDisableAll = { screenModel.toggleSources(false) },
|
||||||
onClickClearCookies = { screenModel.clearCookies() },
|
onClickClearCookies = screenModel::clearCookies,
|
||||||
onClickUninstall = { screenModel.uninstallExtension() },
|
onClickUninstall = screenModel::uninstallExtension,
|
||||||
onClickSource = { screenModel.toggleSource(it) },
|
onClickSource = screenModel::toggleSource,
|
||||||
)
|
)
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
@ -58,7 +58,7 @@ data class SourceSearchScreen(
|
|||||||
searchQuery = state.toolbarQuery ?: "",
|
searchQuery = state.toolbarQuery ?: "",
|
||||||
onChangeSearchQuery = screenModel::setToolbarQuery,
|
onChangeSearchQuery = screenModel::setToolbarQuery,
|
||||||
onClickCloseSearch = navigator::pop,
|
onClickCloseSearch = navigator::pop,
|
||||||
onSearch = { screenModel.search(it) },
|
onSearch = screenModel::search,
|
||||||
scrollBehavior = scrollBehavior,
|
scrollBehavior = scrollBehavior,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -126,7 +126,7 @@ data class BrowseSourceScreen(
|
|||||||
onWebViewClick = onWebViewClick,
|
onWebViewClick = onWebViewClick,
|
||||||
onHelpClick = onHelpClick,
|
onHelpClick = onHelpClick,
|
||||||
onSettingsClick = { navigator.push(SourcePreferencesScreen(sourceId)) },
|
onSettingsClick = { navigator.push(SourcePreferencesScreen(sourceId)) },
|
||||||
onSearch = { screenModel.search(it) },
|
onSearch = screenModel::search,
|
||||||
)
|
)
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
@ -235,15 +235,9 @@ data class BrowseSourceScreen(
|
|||||||
SourceFilterDialog(
|
SourceFilterDialog(
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
filters = state.filters,
|
filters = state.filters,
|
||||||
onReset = {
|
onReset = screenModel::resetFilters,
|
||||||
screenModel.resetFilters()
|
onFilter = { screenModel.search(filters = state.filters) },
|
||||||
},
|
onUpdate = screenModel::setFilters,
|
||||||
onFilter = {
|
|
||||||
screenModel.search(filters = state.filters)
|
|
||||||
},
|
|
||||||
onUpdate = {
|
|
||||||
screenModel.setFilters(it)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is BrowseSourceScreenModel.Dialog.AddDuplicateManga -> {
|
is BrowseSourceScreenModel.Dialog.AddDuplicateManga -> {
|
||||||
|
@ -117,7 +117,7 @@ object LibraryTab : Tab {
|
|||||||
onClickUnselectAll = screenModel::clearSelection,
|
onClickUnselectAll = screenModel::clearSelection,
|
||||||
onClickSelectAll = { screenModel.selectAll(screenModel.activeCategoryIndex) },
|
onClickSelectAll = { screenModel.selectAll(screenModel.activeCategoryIndex) },
|
||||||
onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategoryIndex) },
|
onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategoryIndex) },
|
||||||
onClickFilter = { screenModel.showSettingsDialog() },
|
onClickFilter = screenModel::showSettingsDialog,
|
||||||
onClickRefresh = { onClickRefresh(state.categories[screenModel.activeCategoryIndex]) },
|
onClickRefresh = { onClickRefresh(state.categories[screenModel.activeCategoryIndex]) },
|
||||||
onClickGlobalUpdate = { onClickRefresh(null) },
|
onClickGlobalUpdate = { onClickRefresh(null) },
|
||||||
onClickOpenRandomManga = {
|
onClickOpenRandomManga = {
|
||||||
@ -186,7 +186,7 @@ object LibraryTab : Tab {
|
|||||||
}
|
}
|
||||||
Unit
|
Unit
|
||||||
}.takeIf { state.showMangaContinueButton },
|
}.takeIf { state.showMangaContinueButton },
|
||||||
onToggleSelection = { screenModel.toggleSelection(it) },
|
onToggleSelection = screenModel::toggleSelection,
|
||||||
onToggleRangeSelection = {
|
onToggleRangeSelection = {
|
||||||
screenModel.toggleRangeSelection(it)
|
screenModel.toggleRangeSelection(it)
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
@ -1039,29 +1039,29 @@ class ReaderActivity : BaseActivity() {
|
|||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
readerPreferences.showPageNumber().changes()
|
readerPreferences.showPageNumber().changes()
|
||||||
.onEach { setPageNumberVisibility(it) }
|
.onEach(::setPageNumberVisibility)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
readerPreferences.trueColor().changes()
|
readerPreferences.trueColor().changes()
|
||||||
.onEach { setTrueColor(it) }
|
.onEach(::setTrueColor)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
readerPreferences.cutoutShort().changes()
|
readerPreferences.cutoutShort().changes()
|
||||||
.onEach { setCutoutShort(it) }
|
.onEach(::setCutoutShort)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
readerPreferences.keepScreenOn().changes()
|
readerPreferences.keepScreenOn().changes()
|
||||||
.onEach { setKeepScreenOn(it) }
|
.onEach(::setKeepScreenOn)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
readerPreferences.customBrightness().changes()
|
readerPreferences.customBrightness().changes()
|
||||||
.onEach { setCustomBrightness(it) }
|
.onEach(::setCustomBrightness)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
readerPreferences.colorFilter().changes()
|
readerPreferences.colorFilter().changes()
|
||||||
.onEach { setColorFilter(it) }
|
.onEach(::setColorFilter)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
readerPreferences.colorFilterMode().changes()
|
readerPreferences.colorFilterMode().changes()
|
||||||
@ -1138,7 +1138,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
readerPreferences.customBrightnessValue().changes()
|
readerPreferences.customBrightnessValue().changes()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setCustomBrightnessValue(it) }
|
.onEach(::setCustomBrightnessValue)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
} else {
|
} else {
|
||||||
setCustomBrightnessValue(0)
|
setCustomBrightnessValue(0)
|
||||||
@ -1152,7 +1152,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
readerPreferences.colorFilterValue().changes()
|
readerPreferences.colorFilterValue().changes()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setColorFilterValue(it) }
|
.onEach(::setColorFilterValue)
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
} else {
|
} else {
|
||||||
binding.colorOverlay.isVisible = false
|
binding.colorOverlay.isVisible = false
|
||||||
|
@ -33,7 +33,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
|||||||
addView(binding.root)
|
addView(binding.root)
|
||||||
|
|
||||||
readerPreferences.colorFilter().changes()
|
readerPreferences.colorFilter().changes()
|
||||||
.onEach { setColorFilter(it) }
|
.onEach(::setColorFilter)
|
||||||
.launchIn((context as ReaderActivity).lifecycleScope)
|
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||||
|
|
||||||
readerPreferences.colorFilterMode().changes()
|
readerPreferences.colorFilterMode().changes()
|
||||||
@ -41,7 +41,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
|||||||
.launchIn(context.lifecycleScope)
|
.launchIn(context.lifecycleScope)
|
||||||
|
|
||||||
readerPreferences.customBrightness().changes()
|
readerPreferences.customBrightness().changes()
|
||||||
.onEach { setCustomBrightness(it) }
|
.onEach(::setCustomBrightness)
|
||||||
.launchIn(context.lifecycleScope)
|
.launchIn(context.lifecycleScope)
|
||||||
|
|
||||||
// Get color and update values
|
// Get color and update values
|
||||||
@ -141,7 +141,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
readerPreferences.customBrightnessValue().changes()
|
readerPreferences.customBrightnessValue().changes()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setCustomBrightnessValue(it) }
|
.onEach(::setCustomBrightnessValue)
|
||||||
.launchIn((context as ReaderActivity).lifecycleScope)
|
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||||
} else {
|
} else {
|
||||||
setCustomBrightnessValue(0, true)
|
setCustomBrightnessValue(0, true)
|
||||||
@ -169,7 +169,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
readerPreferences.colorFilterValue().changes()
|
readerPreferences.colorFilterValue().changes()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setColorFilterValue(it) }
|
.onEach(::setColorFilterValue)
|
||||||
.launchIn((context as ReaderActivity).lifecycleScope)
|
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||||
}
|
}
|
||||||
setColorFilterSeekBar(enabled)
|
setColorFilterSeekBar(enabled)
|
||||||
|
@ -63,7 +63,7 @@ class PagerTransitionHolder(
|
|||||||
|
|
||||||
transitionView.bind(transition, viewer.downloadManager, viewer.activity.viewModel.manga)
|
transitionView.bind(transition, viewer.downloadManager, viewer.activity.viewModel.manga)
|
||||||
|
|
||||||
transition.to?.let { observeStatus(it) }
|
transition.to?.let(::observeStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,9 +74,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
setChaptersInternal(viewerChapters)
|
setChaptersInternal(viewerChapters)
|
||||||
awaitingIdleViewerChapters = null
|
awaitingIdleViewerChapters = null
|
||||||
if (viewerChapters.currChapter.pages?.size == 1) {
|
if (viewerChapters.currChapter.pages?.size == 1) {
|
||||||
adapter.nextTransition?.to?.let {
|
adapter.nextTransition?.to?.let(activity::requestPreloadChapter)
|
||||||
activity.requestPreloadChapter(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,9 +232,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
val inPreloadRange = pages.size - page.number < 5
|
val inPreloadRange = pages.size - page.number < 5
|
||||||
if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) {
|
if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) {
|
||||||
logcat { "Request preload next chapter because we're at page ${page.number} of ${pages.size}" }
|
logcat { "Request preload next chapter because we're at page ${page.number} of ${pages.size}" }
|
||||||
adapter.nextTransition?.to?.let {
|
adapter.nextTransition?.to?.let(activity::requestPreloadChapter)
|
||||||
activity.requestPreloadChapter(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +316,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
*/
|
*/
|
||||||
protected open fun moveRight() {
|
protected open fun moveRight() {
|
||||||
if (pager.currentItem != adapter.count - 1) {
|
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()) {
|
if (holder != null && config.navigateToPan && holder.canPanRight()) {
|
||||||
holder.panRight()
|
holder.panRight()
|
||||||
} else {
|
} else {
|
||||||
@ -334,7 +330,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
*/
|
*/
|
||||||
protected open fun moveLeft() {
|
protected open fun moveLeft() {
|
||||||
if (pager.currentItem != 0) {
|
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()) {
|
if (holder != null && config.navigateToPan && holder.canPanLeft()) {
|
||||||
holder.panLeft()
|
holder.panLeft()
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user