From d29b7c4e5735dc137d578d3bcb3da1f0a02573e8 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 1 Sep 2023 23:02:18 -0400 Subject: [PATCH] Switch to different ktlint plugin Should be better at incremental builds. To format, run `./gradlew ktlintFormat`. --- .editorconfig | 4 +- app/build.gradle.kts | 33 +++-- .../category/components/CategoryDialogs.kt | 4 +- .../history/components/HistoryDialogs.kt | 4 +- .../manga/components/MangaDialogs.kt | 2 +- .../eu/kanade/presentation/more/MoreScreen.kt | 10 +- .../{PreferenceModel.kt => Preference.kt} | 1 - .../presentation/updates/UpdatesDialog.kt | 2 +- .../source/browse/SourceFilterDialog.kt | 2 +- .../ui/manga/track/TrackInfoDialog.kt | 30 ++++- buildSrc/build.gradle.kts | 2 +- .../src/main/kotlin/tachiyomi.lint.gradle.kts | 24 ++-- core-metadata/build.gradle.kts | 1 - .../kanade/tachiyomi/network/NetworkHelper.kt | 4 +- .../tachiyomi/network/NetworkPreferences.kt | 5 +- .../tachiyomi/network/ProgressResponseBody.kt | 11 +- .../interceptor/CloudflareInterceptor.kt | 6 +- .../SpecificHostRateLimitInterceptor.kt | 11 +- .../tachiyomi/util/system/ToastExtensions.kt | 12 +- .../util/system/WebViewClientCompat.kt | 5 +- .../core/preference/AndroidPreference.kt | 18 ++- .../core/preference/AndroidPreferenceStore.kt | 6 +- .../tachiyomi/core/preference/Preference.kt | 4 +- .../core/util/lang/CoroutinesExtensions.kt | 10 +- .../java/tachiyomi/data/DatabaseAdapter.kt | 15 +-- .../tachiyomi/data/chapter/ChapterMapper.kt | 16 ++- .../data/chapter/ChapterRepositoryImpl.kt | 22 +++- .../tachiyomi/data/history/HistoryMapper.kt | 14 ++- .../java/tachiyomi/data/manga/MangaMapper.kt | 57 ++++++++- .../data/manga/MangaRepositoryImpl.kt | 16 ++- .../tachiyomi/data/release/GithubRelease.kt | 4 +- .../data/source/SourcePagingSource.kt | 4 +- .../java/tachiyomi/data/track/TrackMapper.kt | 16 ++- .../tachiyomi/data/updates/UpdatesMapper.kt | 17 ++- .../data/updates/UpdatesRepositoryImpl.kt | 12 +- .../category/interactor/ReorderCategory.kt | 6 +- .../interactor/SetSortModeForCategory.kt | 6 +- ...ings.kt => SetMangaDefaultChapterFlags.kt} | 0 .../chapter/service/ChapterRecognition.kt | 6 +- .../domain/chapter/service/ChapterSort.kt | 8 +- .../download/service/DownloadPreferences.kt | 30 ++++- .../history/interactor/GetNextChapters.kt | 6 +- .../domain/library/model/LibrarySortMode.kt | 13 +- .../library/service/LibraryPreferences.kt | 118 ++++++++++++++---- .../manga/interactor/SetFetchInterval.kt | 14 ++- .../interactor/GetApplicationRelease.kt | 19 ++- .../domain/library/model/LibraryFlagsTest.kt | 5 +- .../interactor/GetApplicationReleaseTest.kt | 8 +- gradle/libs.versions.toml | 2 +- .../macrobenchmark/StartupBenchmark.kt | 9 +- .../core/components/AdaptiveSheet.kt | 86 +++++++------ .../components/CircularProgressIndicator.kt | 4 +- .../core/components/CollapsibleBox.kt | 5 +- .../presentation/core/components/LinkIcon.kt | 7 +- .../core/components/ListGroupHeader.kt | 5 +- .../core/components/SettingsItems.kt | 48 ++----- .../core/components/VerticalFastScroller.kt | 3 +- .../core/components/material/AlertDialog.kt | 16 ++- .../core/components/material/Button.kt | 27 ++-- .../{IconButton.kt => IconButtonTokens.kt} | 0 .../components/material/NavigationRail.kt | 5 +- .../core/components/material/Scaffold.kt | 15 ++- .../core/components/material/Surface.kt | 4 +- .../core/components/material/Tabs.kt | 10 +- .../util/{Preview.kt => ThemePreviews.kt} | 0 .../widget/components/UpdatesMangaCover.kt | 5 +- .../eu/kanade/tachiyomi/source/Source.kt | 8 +- .../kanade/tachiyomi/source/model/Filter.kt | 5 +- .../tachiyomi/source/online/HttpSource.kt | 12 +- 69 files changed, 628 insertions(+), 291 deletions(-) rename app/src/main/java/eu/kanade/presentation/more/settings/{PreferenceModel.kt => Preference.kt} (99%) rename domain/src/main/java/tachiyomi/domain/chapter/interactor/{SetDefaultChapterSettings.kt => SetMangaDefaultChapterFlags.kt} (100%) rename presentation-core/src/main/java/tachiyomi/presentation/core/components/material/{IconButton.kt => IconButtonTokens.kt} (100%) rename presentation-core/src/main/java/tachiyomi/presentation/core/util/{Preview.kt => ThemePreviews.kt} (100%) diff --git a/.editorconfig b/.editorconfig index bbef1d7522..d1f1957280 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,5 +3,5 @@ indent_size=4 insert_final_newline=true ij_kotlin_allow_trailing_comma=true ij_kotlin_allow_trailing_comma_on_call_site=true -ij_kotlin_name_count_to_use_star_import = 2147483647 -ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 \ No newline at end of file +ij_kotlin_name_count_to_use_star_import=2147483647 +ij_kotlin_name_count_to_use_star_import_for_members=2147483647 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8ccc2db652..e0658c1d8c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,4 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.jmailen.gradle.kotlinter.tasks.LintTask plugins { id("com.android.application") @@ -104,15 +103,17 @@ android { } packaging { - resources.excludes.addAll(listOf( - "META-INF/DEPENDENCIES", - "LICENSE.txt", - "META-INF/LICENSE", - "META-INF/LICENSE.txt", - "META-INF/README.md", - "META-INF/NOTICE", - "META-INF/*.kotlin_module", - )) + resources.excludes.addAll( + listOf( + "META-INF/DEPENDENCIES", + "LICENSE.txt", + "META-INF/LICENSE", + "META-INF/LICENSE.txt", + "META-INF/README.md", + "META-INF/NOTICE", + "META-INF/*.kotlin_module", + ), + ) } dependenciesInfo { @@ -264,7 +265,9 @@ androidComponents { beforeVariants { variantBuilder -> // Disables standardBenchmark if (variantBuilder.buildType == "benchmark") { - variantBuilder.enable = variantBuilder.productFlavors.containsAll(listOf("default" to "dev")) + variantBuilder.enable = variantBuilder.productFlavors.containsAll( + listOf("default" to "dev"), + ) } } onVariants(selector().withFlavor("default" to "standard")) { @@ -275,10 +278,6 @@ androidComponents { } tasks { - withType().configureEach { - exclude { it.file.path.contains("generated[\\\\/]".toRegex()) } - } - // See https://kotlinlang.org/docs/reference/experimental.html#experimental-status-of-experimental-api(-markers) withType { kotlinOptions.freeCompilerArgs += listOf( @@ -303,12 +302,12 @@ tasks { kotlinOptions.freeCompilerArgs += listOf( "-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + - project.buildDir.absolutePath + "/compose_metrics" + project.buildDir.absolutePath + "/compose_metrics", ) kotlinOptions.freeCompilerArgs += listOf( "-P", "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + - project.buildDir.absolutePath + "/compose_metrics" + project.buildDir.absolutePath + "/compose_metrics", ) } } diff --git a/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt b/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt index ce0f59a7e1..0e99d26c16 100644 --- a/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt +++ b/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt @@ -162,7 +162,7 @@ fun CategoryDeleteDialog( TextButton(onClick = { onDelete() onDismissRequest() - },) { + }) { Text(text = stringResource(R.string.action_ok)) } }, @@ -217,7 +217,7 @@ fun ChangeCategoryDialog( tachiyomi.presentation.core.components.material.TextButton(onClick = { onDismissRequest() onEditCategories() - },) { + }) { Text(text = stringResource(R.string.action_edit)) } Spacer(modifier = Modifier.weight(1f)) diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt index 55cd0aac4d..12db68602b 100644 --- a/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt +++ b/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt @@ -61,7 +61,7 @@ fun HistoryDeleteDialog( TextButton(onClick = { onDelete(removeEverything) onDismissRequest() - },) { + }) { Text(text = stringResource(R.string.action_remove)) } }, @@ -90,7 +90,7 @@ fun HistoryDeleteAllDialog( TextButton(onClick = { onDelete() onDismissRequest() - },) { + }) { Text(text = stringResource(R.string.action_ok)) } }, diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt index 84d9692472..1322adb26b 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt @@ -91,7 +91,7 @@ fun SetIntervalDialog( TextButton(onClick = { onValueChanged(selectedInterval) onDismissRequest() - },) { + }) { Text(text = stringResource(R.string.action_ok)) } }, diff --git a/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt b/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt index b857ace3b4..076ef940d8 100644 --- a/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt @@ -108,11 +108,11 @@ fun MoreScreen( stringResource(R.string.paused) } else { "${stringResource(R.string.paused)} • ${ - pluralStringResource( - id = R.plurals.download_queue_summary, - count = pending, - pending, - ) + pluralStringResource( + id = R.plurals.download_queue_summary, + count = pending, + pending, + ) }" } } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceModel.kt b/app/src/main/java/eu/kanade/presentation/more/settings/Preference.kt similarity index 99% rename from app/src/main/java/eu/kanade/presentation/more/settings/PreferenceModel.kt rename to app/src/main/java/eu/kanade/presentation/more/settings/Preference.kt index 5e8973626b..fa25ff1844 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/PreferenceModel.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/Preference.kt @@ -4,7 +4,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource -import eu.kanade.presentation.more.settings.Preference.PreferenceItem import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.TrackService import tachiyomi.core.preference.Preference as PreferenceData diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesDialog.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesDialog.kt index 45e28127e4..b5210916ec 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesDialog.kt @@ -21,7 +21,7 @@ fun UpdatesDeleteConfirmationDialog( TextButton(onClick = { onConfirm() onDismissRequest() - },) { + }) { Text(text = stringResource(R.string.action_ok)) } }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt index f82f800ae9..5ec0769dca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt @@ -64,7 +64,7 @@ fun SourceFilterDialog( Button(onClick = { onFilter() onDismissRequest() - },) { + }) { Text(stringResource(R.string.action_filter)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt index 47d7c51326..f92374b2ab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt @@ -271,7 +271,10 @@ private data class TrackStatusSelectorScreen( selection = state.selection, onSelectionChange = sm::setSelection, selections = remember { sm.getSelections() }, - onConfirm = { sm.setStatus(); navigator.pop() }, + onConfirm = { + sm.setStatus() + navigator.pop() + }, onDismissRequest = navigator::pop, ) } @@ -322,7 +325,10 @@ private data class TrackChapterSelectorScreen( selection = state.selection, onSelectionChange = sm::setSelection, range = remember { sm.getRange() }, - onConfirm = { sm.setChapter(); navigator.pop() }, + onConfirm = { + sm.setChapter() + navigator.pop() + }, onDismissRequest = navigator::pop, ) } @@ -378,7 +384,10 @@ private data class TrackScoreSelectorScreen( selection = state.selection, onSelectionChange = sm::setSelection, selections = remember { sm.getSelections() }, - onConfirm = { sm.setScore(); navigator.pop() }, + onConfirm = { + sm.setScore() + navigator.pop() + }, onDismissRequest = navigator::pop, ) } @@ -495,7 +504,10 @@ private data class TrackDateSelectorScreen( }, initialSelectedDateMillis = sm.initialSelection, selectableDates = selectableDates, - onConfirm = { sm.setDate(it); navigator.pop() }, + onConfirm = { + sm.setDate(it) + navigator.pop() + }, onRemove = { sm.confirmRemoveDate(navigator) }.takeIf { canRemove }, onDismissRequest = navigator::pop, ) @@ -584,7 +596,10 @@ private data class TrackDateRemoverScreen( Text(text = stringResource(android.R.string.cancel)) } FilledTonalButton( - onClick = { sm.removeDate(); navigator.popUntil { it is TrackInfoDialogHomeScreen } }, + onClick = { + sm.removeDate() + navigator.popUntil { it is TrackInfoDialogHomeScreen } + }, colors = ButtonDefaults.filledTonalButtonColors( containerColor = MaterialTheme.colorScheme.errorContainer, contentColor = MaterialTheme.colorScheme.onErrorContainer, @@ -646,7 +661,10 @@ data class TrackServiceSearchScreen( queryResult = state.queryResult, selected = state.selected, onSelectedChange = sm::updateSelection, - onConfirmSelection = { sm.registerTracking(state.selected!!); navigator.pop() }, + onConfirmSelection = { + sm.registerTracking(state.selected!!) + navigator.pop() + }, onDismissRequest = navigator::pop, ) } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index b5854fcb55..2c76035b72 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { implementation(androidxLibs.gradle) implementation(kotlinLibs.gradle) - implementation(libs.kotlinter) + implementation(libs.ktlint) implementation(gradleApi()) } diff --git a/buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts b/buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts index 12b7b2295b..a89d885924 100644 --- a/buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts +++ b/buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts @@ -1,20 +1,14 @@ -import org.jmailen.gradle.kotlinter.KotlinterExtension -import org.jmailen.gradle.kotlinter.KotlinterPlugin +import org.jlleitschuh.gradle.ktlint.KtlintExtension +import org.jlleitschuh.gradle.ktlint.KtlintPlugin -apply() +apply() -extensions.configure("kotlinter") { - experimentalRules = true +extensions.configure("ktlint") { + version.set("0.50.0") + android.set(true) + enableExperimentalRules.set(true) - disabledRules = arrayOf( - "experimental:argument-list-wrapping", // Doesn't play well with Android Studio - "filename", // Often broken to give a more general name - ) -} - -tasks { - named("preBuild").configure { - if (!System.getenv("CI").toBoolean()) - dependsOn("formatKotlin") + filter { + exclude("**/generated/**") } } diff --git a/core-metadata/build.gradle.kts b/core-metadata/build.gradle.kts index 51db46b912..43b8846ab5 100644 --- a/core-metadata/build.gradle.kts +++ b/core-metadata/build.gradle.kts @@ -11,7 +11,6 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") } - } dependencies { diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt index 38ba749d29..6893a0495d 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt @@ -39,7 +39,9 @@ class NetworkHelper( builder.addNetworkInterceptor(httpLoggingInterceptor) } - builder.addInterceptor(CloudflareInterceptor(context, cookieJar, ::defaultUserAgentProvider)) + builder.addInterceptor( + CloudflareInterceptor(context, cookieJar, ::defaultUserAgentProvider), + ) when (preferences.dohProvider().get()) { PREF_DOH_CLOUDFLARE -> builder.dohCloudflare() diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt index 5e14d03423..cba50e99c1 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/NetworkPreferences.kt @@ -17,6 +17,9 @@ class NetworkPreferences( } fun defaultUserAgent(): Preference { - return preferenceStore.getString("default_user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0") + return preferenceStore.getString( + "default_user_agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0", + ) } } diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/ProgressResponseBody.kt b/core/src/main/java/eu/kanade/tachiyomi/network/ProgressResponseBody.kt index 72248f17b7..6ba53b1977 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/ProgressResponseBody.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/ProgressResponseBody.kt @@ -9,7 +9,10 @@ import okio.Source import okio.buffer import java.io.IOException -class ProgressResponseBody(private val responseBody: ResponseBody, private val progressListener: ProgressListener) : ResponseBody() { +class ProgressResponseBody( + private val responseBody: ResponseBody, + private val progressListener: ProgressListener, +) : ResponseBody() { private val bufferedSource: BufferedSource by lazy { source(responseBody.source()).buffer() @@ -36,7 +39,11 @@ class ProgressResponseBody(private val responseBody: ResponseBody, private val p val bytesRead = super.read(sink, byteCount) // read() returns the number of bytes read, or -1 if this source is exhausted. totalBytesRead += if (bytesRead != -1L) bytesRead else 0 - progressListener.update(totalBytesRead, responseBody.contentLength(), bytesRead == -1L) + progressListener.update( + totalBytesRead, + responseBody.contentLength(), + bytesRead == -1L, + ) return bytesRead } } diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index 25b5a140a6..d5893bb058 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -31,7 +31,11 @@ class CloudflareInterceptor( return response.code in ERROR_CODES && response.header("Server") in SERVER_CHECK } - override fun intercept(chain: Interceptor.Chain, request: Request, response: Response): Response { + override fun intercept( + chain: Interceptor.Chain, + request: Request, + response: Response, + ): Response { try { response.close() cookieManager.remove(request.url, COOKIE_NAMES, 0) diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/SpecificHostRateLimitInterceptor.kt b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/SpecificHostRateLimitInterceptor.kt index b364db7438..c86f780d94 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/SpecificHostRateLimitInterceptor.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/interceptor/SpecificHostRateLimitInterceptor.kt @@ -33,7 +33,9 @@ fun OkHttpClient.Builder.rateLimitHost( permits: Int, period: Long = 1, unit: TimeUnit = TimeUnit.SECONDS, -) = addInterceptor(RateLimitInterceptor(httpUrl.host, permits, period.toDuration(unit.toDurationUnit()))) +) = addInterceptor( + RateLimitInterceptor(httpUrl.host, permits, period.toDuration(unit.toDurationUnit())), +) /** * An OkHttp interceptor that handles given url host's rate limiting. @@ -69,8 +71,5 @@ fun OkHttpClient.Builder.rateLimitHost( * @param permits [Int] Number of requests allowed within a period of units. * @param period [Duration] The limiting duration. Defaults to 1.seconds. */ -fun OkHttpClient.Builder.rateLimitHost( - url: String, - permits: Int, - period: Duration = 1.seconds, -) = addInterceptor(RateLimitInterceptor(url.toHttpUrlOrNull()?.host, permits, period)) +fun OkHttpClient.Builder.rateLimitHost(url: String, permits: Int, period: Duration = 1.seconds) = + addInterceptor(RateLimitInterceptor(url.toHttpUrlOrNull()?.host, permits, period)) diff --git a/core/src/main/java/eu/kanade/tachiyomi/util/system/ToastExtensions.kt b/core/src/main/java/eu/kanade/tachiyomi/util/system/ToastExtensions.kt index 4901e7463a..9e4554cb4a 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/util/system/ToastExtensions.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/util/system/ToastExtensions.kt @@ -10,7 +10,11 @@ import androidx.annotation.StringRes * @param resource the text resource. * @param duration the duration of the toast. Defaults to short. */ -fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast { +fun Context.toast( + @StringRes resource: Int, + duration: Int = Toast.LENGTH_SHORT, + block: (Toast) -> Unit = {}, +): Toast { return toast(getString(resource), duration, block) } @@ -20,7 +24,11 @@ fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT, * @param text the text to display. * @param duration the duration of the toast. Defaults to short. */ -fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast { +fun Context.toast( + text: String?, + duration: Int = Toast.LENGTH_SHORT, + block: (Toast) -> Unit = {}, +): Toast { return Toast.makeText(applicationContext, text.orEmpty(), duration).also { block(it) it.show() diff --git a/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt b/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt index 6c6fba4ff6..93ce0337d7 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt @@ -47,10 +47,7 @@ abstract class WebViewClientCompat : WebViewClient() { return shouldInterceptRequestCompat(view, request.url.toString()) } - final override fun shouldInterceptRequest( - view: WebView, - url: String, - ): WebResourceResponse? { + final override fun shouldInterceptRequest(view: WebView, url: String): WebResourceResponse? { return shouldInterceptRequestCompat(view, url) } diff --git a/core/src/main/java/tachiyomi/core/preference/AndroidPreference.kt b/core/src/main/java/tachiyomi/core/preference/AndroidPreference.kt index 00f3701d06..a0f2f335c6 100644 --- a/core/src/main/java/tachiyomi/core/preference/AndroidPreference.kt +++ b/core/src/main/java/tachiyomi/core/preference/AndroidPreference.kt @@ -68,7 +68,11 @@ sealed class AndroidPreference( key: String, defaultValue: String, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { - override fun read(preferences: SharedPreferences, key: String, defaultValue: String): String { + override fun read( + preferences: SharedPreferences, + key: String, + defaultValue: String, + ): String { return preferences.getString(key, defaultValue) ?: defaultValue } @@ -128,7 +132,11 @@ sealed class AndroidPreference( key: String, defaultValue: Boolean, ) : AndroidPreference(preferences, keyFlow, key, defaultValue) { - override fun read(preferences: SharedPreferences, key: String, defaultValue: Boolean): Boolean { + override fun read( + preferences: SharedPreferences, + key: String, + defaultValue: Boolean, + ): Boolean { return preferences.getBoolean(key, defaultValue) } @@ -143,7 +151,11 @@ sealed class AndroidPreference( key: String, defaultValue: Set, ) : AndroidPreference>(preferences, keyFlow, key, defaultValue) { - override fun read(preferences: SharedPreferences, key: String, defaultValue: Set): Set { + override fun read( + preferences: SharedPreferences, + key: String, + defaultValue: Set, + ): Set { return preferences.getStringSet(key, defaultValue) ?: defaultValue } diff --git a/core/src/main/java/tachiyomi/core/preference/AndroidPreferenceStore.kt b/core/src/main/java/tachiyomi/core/preference/AndroidPreferenceStore.kt index 74c2872d89..c59652da5f 100644 --- a/core/src/main/java/tachiyomi/core/preference/AndroidPreferenceStore.kt +++ b/core/src/main/java/tachiyomi/core/preference/AndroidPreferenceStore.kt @@ -64,7 +64,11 @@ class AndroidPreferenceStore( private val SharedPreferences.keyFlow get() = callbackFlow { - val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key: String? -> trySend(key) } + val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key: String? -> + trySend( + key, + ) + } registerOnSharedPreferenceChangeListener(listener) awaitClose { unregisterOnSharedPreferenceChangeListener(listener) diff --git a/core/src/main/java/tachiyomi/core/preference/Preference.kt b/core/src/main/java/tachiyomi/core/preference/Preference.kt index 67b7a44f4d..e76ea23d43 100644 --- a/core/src/main/java/tachiyomi/core/preference/Preference.kt +++ b/core/src/main/java/tachiyomi/core/preference/Preference.kt @@ -23,7 +23,9 @@ interface Preference { fun stateIn(scope: CoroutineScope): StateFlow } -inline fun Preference.getAndSet(crossinline block: (T) -> R) = set(block(get())) +inline fun Preference.getAndSet(crossinline block: (T) -> R) = set( + block(get()), +) operator fun Preference>.plusAssign(item: T) { set(get() + item) diff --git a/core/src/main/java/tachiyomi/core/util/lang/CoroutinesExtensions.kt b/core/src/main/java/tachiyomi/core/util/lang/CoroutinesExtensions.kt index 4573b2d858..829207a9b0 100644 --- a/core/src/main/java/tachiyomi/core/util/lang/CoroutinesExtensions.kt +++ b/core/src/main/java/tachiyomi/core/util/lang/CoroutinesExtensions.kt @@ -52,9 +52,15 @@ fun CoroutineScope.launchIO(block: suspend CoroutineScope.() -> Unit): Job = fun CoroutineScope.launchNonCancellable(block: suspend CoroutineScope.() -> Unit): Job = launchIO { withContext(NonCancellable, block) } -suspend fun withUIContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.Main, block) +suspend fun withUIContext(block: suspend CoroutineScope.() -> T) = withContext( + Dispatchers.Main, + block, +) -suspend fun withIOContext(block: suspend CoroutineScope.() -> T) = withContext(Dispatchers.IO, block) +suspend fun withIOContext(block: suspend CoroutineScope.() -> T) = withContext( + Dispatchers.IO, + block, +) suspend fun withNonCancellableContext(block: suspend CoroutineScope.() -> T) = withContext(NonCancellable, block) diff --git a/data/src/main/java/tachiyomi/data/DatabaseAdapter.kt b/data/src/main/java/tachiyomi/data/DatabaseAdapter.kt index 4a3475b4ff..596a31286d 100644 --- a/data/src/main/java/tachiyomi/data/DatabaseAdapter.kt +++ b/data/src/main/java/tachiyomi/data/DatabaseAdapter.kt @@ -11,13 +11,14 @@ object DateColumnAdapter : ColumnAdapter { private const val LIST_OF_STRINGS_SEPARATOR = ", " object StringListColumnAdapter : ColumnAdapter, String> { - override fun decode(databaseValue: String) = - if (databaseValue.isEmpty()) { - emptyList() - } else { - databaseValue.split(LIST_OF_STRINGS_SEPARATOR) - } - override fun encode(value: List) = value.joinToString(separator = LIST_OF_STRINGS_SEPARATOR) + override fun decode(databaseValue: String) = if (databaseValue.isEmpty()) { + emptyList() + } else { + databaseValue.split(LIST_OF_STRINGS_SEPARATOR) + } + override fun encode(value: List) = value.joinToString( + separator = LIST_OF_STRINGS_SEPARATOR, + ) } object UpdateStrategyColumnAdapter : ColumnAdapter { diff --git a/data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt b/data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt index 71ae1720ee..c8243682fa 100644 --- a/data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt +++ b/data/src/main/java/tachiyomi/data/chapter/ChapterMapper.kt @@ -2,7 +2,21 @@ package tachiyomi.data.chapter import tachiyomi.domain.chapter.model.Chapter -val chapterMapper: (Long, Long, String, String, String?, Boolean, Boolean, Long, Double, Long, Long, Long, Long) -> Chapter = +val chapterMapper: ( + Long, + Long, + String, + String, + String?, + Boolean, + Boolean, + Long, + Double, + Long, + Long, + Long, + Long, +) -> Chapter = { id, mangaId, url, name, scanlator, read, bookmark, lastPageRead, chapterNumber, sourceOrder, dateFetch, dateUpload, lastModifiedAt -> Chapter( id = id, diff --git a/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt index 45a61e3633..594a592ac4 100644 --- a/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/chapter/ChapterRepositoryImpl.kt @@ -81,7 +81,12 @@ class ChapterRepositoryImpl( } override suspend fun getBookmarkedChaptersByMangaId(mangaId: Long): List { - return handler.awaitList { chaptersQueries.getBookmarkedChaptersByMangaId(mangaId, chapterMapper) } + return handler.awaitList { + chaptersQueries.getBookmarkedChaptersByMangaId( + mangaId, + chapterMapper, + ) + } } override suspend fun getChapterById(id: Long): Chapter? { @@ -89,10 +94,21 @@ class ChapterRepositoryImpl( } override suspend fun getChapterByMangaIdAsFlow(mangaId: Long): Flow> { - return handler.subscribeToList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) } + return handler.subscribeToList { + chaptersQueries.getChaptersByMangaId( + mangaId, + chapterMapper, + ) + } } override suspend fun getChapterByUrlAndMangaId(url: String, mangaId: Long): Chapter? { - return handler.awaitOneOrNull { chaptersQueries.getChapterByUrlAndMangaId(url, mangaId, chapterMapper) } + return handler.awaitOneOrNull { + chaptersQueries.getChapterByUrlAndMangaId( + url, + mangaId, + chapterMapper, + ) + } } } diff --git a/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt b/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt index c2d110f747..134a1c91cb 100644 --- a/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt +++ b/data/src/main/java/tachiyomi/data/history/HistoryMapper.kt @@ -14,7 +14,19 @@ val historyMapper: (Long, Long, Date?, Long) -> History = { id, chapterId, readA ) } -val historyWithRelationsMapper: (Long, Long, Long, String, String?, Long, Boolean, Long, Double, Date?, Long) -> HistoryWithRelations = { +val historyWithRelationsMapper: ( + Long, + Long, + Long, + String, + String?, + Long, + Boolean, + Long, + Double, + Date?, + Long, +) -> HistoryWithRelations = { historyId, mangaId, chapterId, title, thumbnailUrl, sourceId, isFavorite, coverLastModified, chapterNumber, readAt, readDuration -> HistoryWithRelations( id = historyId, diff --git a/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt b/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt index 3cc46aa5cb..43bb1ed0c5 100644 --- a/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt +++ b/data/src/main/java/tachiyomi/data/manga/MangaMapper.kt @@ -4,7 +4,30 @@ import eu.kanade.tachiyomi.source.model.UpdateStrategy import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.manga.model.Manga -val mangaMapper: (Long, Long, String, String?, String?, String?, List?, String, Long, String?, Boolean, Long?, Long?, Boolean, Long, Long, Long, Long, UpdateStrategy, Long, Long, Long?) -> Manga = +val mangaMapper: ( + Long, + Long, + String, + String?, + String?, + String?, + List?, + String, + Long, + String?, + Boolean, + Long?, + Long?, + Boolean, + Long, + Long, + Long, + Long, + UpdateStrategy, + Long, + Long, + Long?, +) -> Manga = { id, source, url, artist, author, description, genre, title, status, thumbnailUrl, favorite, lastUpdate, nextUpdate, initialized, viewerFlags, chapterFlags, coverLastModified, dateAdded, updateStrategy, calculateInterval, lastModifiedAt, favoriteModifiedAt -> Manga( id = id, @@ -32,7 +55,37 @@ val mangaMapper: (Long, Long, String, String?, String?, String?, List?, ) } -val libraryManga: (Long, Long, String, String?, String?, String?, List?, String, Long, String?, Boolean, Long?, Long?, Boolean, Long, Long, Long, Long, UpdateStrategy, Long, Long, Long?, Long, Double, Long, Long, Long, Double, Long) -> LibraryManga = +val libraryManga: ( + Long, + Long, + String, + String?, + String?, + String?, + List?, + String, + Long, + String?, + Boolean, + Long?, + Long?, + Boolean, + Long, + Long, + Long, + Long, + UpdateStrategy, + Long, + Long, + Long?, + Long, + Double, + Long, + Long, + Long, + Double, + Long, +) -> LibraryManga = { id, source, url, artist, author, description, genre, title, status, thumbnailUrl, favorite, lastUpdate, nextUpdate, initialized, viewerFlags, chapterFlags, coverLastModified, dateAdded, updateStrategy, calculateInterval, lastModifiedAt, favoriteModifiedAt, totalCount, readCount, latestUpload, chapterFetchedAt, lastRead, bookmarkCount, category -> LibraryManga( manga = mangaMapper( diff --git a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt index 49f3160a6d..39bbcb99f7 100644 --- a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt @@ -24,11 +24,23 @@ class MangaRepositoryImpl( } override suspend fun getMangaByUrlAndSourceId(url: String, sourceId: Long): Manga? { - return handler.awaitOneOrNull(inTransaction = true) { mangasQueries.getMangaByUrlAndSource(url, sourceId, mangaMapper) } + return handler.awaitOneOrNull(inTransaction = true) { + mangasQueries.getMangaByUrlAndSource( + url, + sourceId, + mangaMapper, + ) + } } override fun getMangaByUrlAndSourceIdAsFlow(url: String, sourceId: Long): Flow { - return handler.subscribeToOneOrNull { mangasQueries.getMangaByUrlAndSource(url, sourceId, mangaMapper) } + return handler.subscribeToOneOrNull { + mangasQueries.getMangaByUrlAndSource( + url, + sourceId, + mangaMapper, + ) + } } override suspend fun getFavorites(): List { diff --git a/data/src/main/java/tachiyomi/data/release/GithubRelease.kt b/data/src/main/java/tachiyomi/data/release/GithubRelease.kt index 94394cef05..f7fa169236 100644 --- a/data/src/main/java/tachiyomi/data/release/GithubRelease.kt +++ b/data/src/main/java/tachiyomi/data/release/GithubRelease.kt @@ -32,7 +32,9 @@ data class GitHubAssets(@SerialName("browser_download_url") val downloadLink: St * Reference: https://stackoverflow.com/a/30281147 */ val gitHubUsernameMentionRegex = - """\B@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?<=[a-z0-9]))""".toRegex(RegexOption.IGNORE_CASE) + """\B@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?<=[a-z0-9]))""".toRegex( + RegexOption.IGNORE_CASE, + ) val releaseMapper: (GithubRelease) -> Release = { Release( diff --git a/data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt b/data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt index 032ae0ab5b..e8295a2583 100644 --- a/data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt +++ b/data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt @@ -9,7 +9,9 @@ import tachiyomi.core.util.lang.awaitSingle import tachiyomi.core.util.lang.withIOContext import tachiyomi.domain.source.repository.SourcePagingSourceType -class SourceSearchPagingSource(source: CatalogueSource, val query: String, val filters: FilterList) : SourcePagingSource(source) { +class SourceSearchPagingSource(source: CatalogueSource, val query: String, val filters: FilterList) : SourcePagingSource( + source, +) { override suspend fun requestNextPage(currentPage: Int): MangasPage { return source.fetchSearchManga(currentPage, query, filters).awaitSingle() } diff --git a/data/src/main/java/tachiyomi/data/track/TrackMapper.kt b/data/src/main/java/tachiyomi/data/track/TrackMapper.kt index e8978e25b7..a4a9714f6a 100644 --- a/data/src/main/java/tachiyomi/data/track/TrackMapper.kt +++ b/data/src/main/java/tachiyomi/data/track/TrackMapper.kt @@ -2,7 +2,21 @@ package tachiyomi.data.track import tachiyomi.domain.track.model.Track -val trackMapper: (Long, Long, Long, Long, Long?, String, Double, Long, Long, Double, String, Long, Long) -> Track = +val trackMapper: ( + Long, + Long, + Long, + Long, + Long?, + String, + Double, + Long, + Long, + Double, + String, + Long, + Long, +) -> Track = { id, mangaId, syncId, remoteId, libraryId, title, lastChapterRead, totalChapters, status, score, remoteUrl, startDate, finishDate -> Track( id = id, diff --git a/data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt b/data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt index efbc554101..56e9743a9f 100644 --- a/data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt +++ b/data/src/main/java/tachiyomi/data/updates/UpdatesMapper.kt @@ -3,7 +3,22 @@ package tachiyomi.data.updates import tachiyomi.domain.manga.model.MangaCover import tachiyomi.domain.updates.model.UpdatesWithRelations -val updateWithRelationMapper: (Long, String, Long, String, String?, Boolean, Boolean, Long, Long, Boolean, String?, Long, Long, Long) -> UpdatesWithRelations = { +val updateWithRelationMapper: ( + Long, + String, + Long, + String, + String?, + Boolean, + Boolean, + Long, + Long, + Boolean, + String?, + Long, + Long, + Long, +) -> UpdatesWithRelations = { mangaId, mangaTitle, chapterId, chapterName, scanlator, read, bookmark, lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, _, dateFetch -> UpdatesWithRelations( mangaId = mangaId, diff --git a/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt index 99ec744156..b50aee4be9 100644 --- a/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/updates/UpdatesRepositoryImpl.kt @@ -9,7 +9,11 @@ class UpdatesRepositoryImpl( private val databaseHandler: DatabaseHandler, ) : UpdatesRepository { - override suspend fun awaitWithRead(read: Boolean, after: Long, limit: Long): List { + override suspend fun awaitWithRead( + read: Boolean, + after: Long, + limit: Long, + ): List { return databaseHandler.awaitList { updatesViewQueries.getUpdatesByReadStatus( read = read, @@ -26,7 +30,11 @@ class UpdatesRepositoryImpl( } } - override fun subscribeWithRead(read: Boolean, after: Long, limit: Long): Flow> { + override fun subscribeWithRead( + read: Boolean, + after: Long, + limit: Long, + ): Flow> { return databaseHandler.subscribeToList { updatesViewQueries.getUpdatesByReadStatus( read = read, diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt index af61400abd..b29cfd0934 100644 --- a/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt +++ b/domain/src/main/java/tachiyomi/domain/category/interactor/ReorderCategory.kt @@ -16,11 +16,9 @@ class ReorderCategory( private val mutex = Mutex() - suspend fun moveUp(category: Category): Result = - await(category, MoveTo.UP) + suspend fun moveUp(category: Category): Result = await(category, MoveTo.UP) - suspend fun moveDown(category: Category): Result = - await(category, MoveTo.DOWN) + suspend fun moveDown(category: Category): Result = await(category, MoveTo.DOWN) private suspend fun await(category: Category, moveTo: MoveTo) = withNonCancellableContext { mutex.withLock { diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt index 28c999e9f7..e514e08988 100644 --- a/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt +++ b/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt @@ -28,7 +28,11 @@ class SetSortModeForCategory( } } - suspend fun await(category: Category?, type: LibrarySort.Type, direction: LibrarySort.Direction) { + suspend fun await( + category: Category?, + type: LibrarySort.Type, + direction: LibrarySort.Direction, + ) { await(category?.id, type, direction) } } diff --git a/domain/src/main/java/tachiyomi/domain/chapter/interactor/SetDefaultChapterSettings.kt b/domain/src/main/java/tachiyomi/domain/chapter/interactor/SetMangaDefaultChapterFlags.kt similarity index 100% rename from domain/src/main/java/tachiyomi/domain/chapter/interactor/SetDefaultChapterSettings.kt rename to domain/src/main/java/tachiyomi/domain/chapter/interactor/SetMangaDefaultChapterFlags.kt diff --git a/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterRecognition.kt b/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterRecognition.kt index d41eb14846..b2c3f6b44b 100644 --- a/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterRecognition.kt +++ b/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterRecognition.kt @@ -30,7 +30,11 @@ object ChapterRecognition { */ private val unwantedWhiteSpace = Regex("""\s(?=extra|special|omake)""") - fun parseChapterNumber(mangaTitle: String, chapterName: String, chapterNumber: Double? = null): Double { + fun parseChapterNumber( + mangaTitle: String, + chapterName: String, + chapterNumber: Double? = null, + ): Double { // If chapter number is known return. if (chapterNumber != null && (chapterNumber == -2.0 || chapterNumber > -1.0)) { return chapterNumber diff --git a/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterSort.kt b/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterSort.kt index e7f5648cba..45f3024554 100644 --- a/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterSort.kt +++ b/domain/src/main/java/tachiyomi/domain/chapter/service/ChapterSort.kt @@ -3,7 +3,13 @@ package tachiyomi.domain.chapter.service import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.manga.model.Manga -fun getChapterSort(manga: Manga, sortDescending: Boolean = manga.sortDescending()): (Chapter, Chapter) -> Int { +fun getChapterSort( + manga: Manga, + sortDescending: Boolean = manga.sortDescending(), +): ( + Chapter, + Chapter, +) -> Int { return when (manga.sorting) { Manga.CHAPTER_SORTING_SOURCE -> when (sortDescending) { true -> { c1, c2 -> c1.sourceOrder.compareTo(c2.sourceOrder) } diff --git a/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt b/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt index cc930cf513..51a07dc8e5 100644 --- a/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt +++ b/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt @@ -8,9 +8,15 @@ class DownloadPreferences( private val preferenceStore: PreferenceStore, ) { - fun downloadsDirectory() = preferenceStore.getString("download_directory", folderProvider.path()) + fun downloadsDirectory() = preferenceStore.getString( + "download_directory", + folderProvider.path(), + ) - fun downloadOnlyOverWifi() = preferenceStore.getBoolean("pref_download_only_over_wifi_key", true) + fun downloadOnlyOverWifi() = preferenceStore.getBoolean( + "pref_download_only_over_wifi_key", + true, + ) fun saveChaptersAsCBZ() = preferenceStore.getBoolean("save_chapter_as_cbz", true) @@ -20,15 +26,27 @@ class DownloadPreferences( fun removeAfterReadSlots() = preferenceStore.getInt("remove_after_read_slots", -1) - fun removeAfterMarkedAsRead() = preferenceStore.getBoolean("pref_remove_after_marked_as_read_key", false) + fun removeAfterMarkedAsRead() = preferenceStore.getBoolean( + "pref_remove_after_marked_as_read_key", + false, + ) fun removeBookmarkedChapters() = preferenceStore.getBoolean("pref_remove_bookmarked", false) - fun removeExcludeCategories() = preferenceStore.getStringSet("remove_exclude_categories", emptySet()) + fun removeExcludeCategories() = preferenceStore.getStringSet( + "remove_exclude_categories", + emptySet(), + ) fun downloadNewChapters() = preferenceStore.getBoolean("download_new", false) - fun downloadNewChapterCategories() = preferenceStore.getStringSet("download_new_categories", emptySet()) + fun downloadNewChapterCategories() = preferenceStore.getStringSet( + "download_new_categories", + emptySet(), + ) - fun downloadNewChapterCategoriesExclude() = preferenceStore.getStringSet("download_new_categories_exclude", emptySet()) + fun downloadNewChapterCategoriesExclude() = preferenceStore.getStringSet( + "download_new_categories_exclude", + emptySet(), + ) } diff --git a/domain/src/main/java/tachiyomi/domain/history/interactor/GetNextChapters.kt b/domain/src/main/java/tachiyomi/domain/history/interactor/GetNextChapters.kt index ebe6fa83ec..6e9526158c 100644 --- a/domain/src/main/java/tachiyomi/domain/history/interactor/GetNextChapters.kt +++ b/domain/src/main/java/tachiyomi/domain/history/interactor/GetNextChapters.kt @@ -30,7 +30,11 @@ class GetNextChapters( } } - suspend fun await(mangaId: Long, fromChapterId: Long, onlyUnread: Boolean = true): List { + suspend fun await( + mangaId: Long, + fromChapterId: Long, + onlyUnread: Boolean = true, + ): List { val chapters = await(mangaId, onlyUnread) val currChapterIndex = chapters.indexOfFirst { it.id == fromChapterId } val nextChapters = chapters.subList(max(0, currChapterIndex), chapters.size) diff --git a/domain/src/main/java/tachiyomi/domain/library/model/LibrarySortMode.kt b/domain/src/main/java/tachiyomi/domain/library/model/LibrarySortMode.kt index 40acc5b5a2..7f525eb578 100644 --- a/domain/src/main/java/tachiyomi/domain/library/model/LibrarySortMode.kt +++ b/domain/src/main/java/tachiyomi/domain/library/model/LibrarySortMode.kt @@ -65,7 +65,18 @@ data class LibrarySort( } companion object { - val types by lazy { setOf(Type.Alphabetical, Type.LastRead, Type.LastUpdate, Type.UnreadCount, Type.TotalChapters, Type.LatestChapter, Type.ChapterFetchDate, Type.DateAdded) } + val types by lazy { + setOf( + Type.Alphabetical, + Type.LastRead, + Type.LastUpdate, + Type.UnreadCount, + Type.TotalChapters, + Type.LatestChapter, + Type.ChapterFetchDate, + Type.DateAdded, + ) + } val directions by lazy { setOf(Direction.Ascending, Direction.Descending) } val default = LibrarySort(Type.Alphabetical, Direction.Ascending) diff --git a/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt b/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt index e66c705d9c..8c853c759a 100644 --- a/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt +++ b/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt @@ -11,9 +11,19 @@ class LibraryPreferences( private val preferenceStore: PreferenceStore, ) { - fun displayMode() = preferenceStore.getObject("pref_display_mode_library", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize) + fun displayMode() = preferenceStore.getObject( + "pref_display_mode_library", + LibraryDisplayMode.default, + LibraryDisplayMode.Serializer::serialize, + LibraryDisplayMode.Serializer::deserialize, + ) - fun sortingMode() = preferenceStore.getObject("library_sorting_mode", LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize) + fun sortingMode() = preferenceStore.getObject( + "library_sorting_mode", + LibrarySort.default, + LibrarySort.Serializer::serialize, + LibrarySort.Serializer::deserialize, + ) fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0) @@ -42,31 +52,64 @@ class LibraryPreferences( fun autoUpdateTrackers() = preferenceStore.getBoolean("auto_update_trackers", false) - fun showContinueReadingButton() = preferenceStore.getBoolean("display_continue_reading_button", false) + fun showContinueReadingButton() = preferenceStore.getBoolean( + "display_continue_reading_button", + false, + ) // region Filter - fun filterDownloaded() = preferenceStore.getEnum("pref_filter_library_downloaded_v2", TriState.DISABLED) + fun filterDownloaded() = preferenceStore.getEnum( + "pref_filter_library_downloaded_v2", + TriState.DISABLED, + ) fun filterUnread() = preferenceStore.getEnum("pref_filter_library_unread_v2", TriState.DISABLED) - fun filterStarted() = preferenceStore.getEnum("pref_filter_library_started_v2", TriState.DISABLED) + fun filterStarted() = preferenceStore.getEnum( + "pref_filter_library_started_v2", + TriState.DISABLED, + ) - fun filterBookmarked() = preferenceStore.getEnum("pref_filter_library_bookmarked_v2", TriState.DISABLED) + fun filterBookmarked() = preferenceStore.getEnum( + "pref_filter_library_bookmarked_v2", + TriState.DISABLED, + ) - fun filterCompleted() = preferenceStore.getEnum("pref_filter_library_completed_v2", TriState.DISABLED) + fun filterCompleted() = preferenceStore.getEnum( + "pref_filter_library_completed_v2", + TriState.DISABLED, + ) - fun filterIntervalCustom() = preferenceStore.getEnum("pref_filter_library_interval_custom", TriState.DISABLED) + fun filterIntervalCustom() = preferenceStore.getEnum( + "pref_filter_library_interval_custom", + TriState.DISABLED, + ) - fun filterIntervalLong() = preferenceStore.getEnum("pref_filter_library_interval_long", TriState.DISABLED) + fun filterIntervalLong() = preferenceStore.getEnum( + "pref_filter_library_interval_long", + TriState.DISABLED, + ) - fun filterIntervalLate() = preferenceStore.getEnum("pref_filter_library_interval_late", TriState.DISABLED) + fun filterIntervalLate() = preferenceStore.getEnum( + "pref_filter_library_interval_late", + TriState.DISABLED, + ) - fun filterIntervalDropped() = preferenceStore.getEnum("pref_filter_library_interval_dropped", TriState.DISABLED) + fun filterIntervalDropped() = preferenceStore.getEnum( + "pref_filter_library_interval_dropped", + TriState.DISABLED, + ) - fun filterIntervalPassed() = preferenceStore.getEnum("pref_filter_library_interval_passed", TriState.DISABLED) + fun filterIntervalPassed() = preferenceStore.getEnum( + "pref_filter_library_interval_passed", + TriState.DISABLED, + ) - fun filterTracking(id: Int) = preferenceStore.getEnum("pref_filter_library_tracked_${id}_v2", TriState.DISABLED) + fun filterTracking(id: Int) = preferenceStore.getEnum( + "pref_filter_library_tracked_${id}_v2", + TriState.DISABLED, + ) // endregion @@ -97,24 +140,45 @@ class LibraryPreferences( fun updateCategories() = preferenceStore.getStringSet("library_update_categories", emptySet()) - fun updateCategoriesExclude() = preferenceStore.getStringSet("library_update_categories_exclude", emptySet()) + fun updateCategoriesExclude() = preferenceStore.getStringSet( + "library_update_categories_exclude", + emptySet(), + ) // endregion // region Chapter - fun filterChapterByRead() = preferenceStore.getLong("default_chapter_filter_by_read", Manga.SHOW_ALL) + fun filterChapterByRead() = preferenceStore.getLong( + "default_chapter_filter_by_read", + Manga.SHOW_ALL, + ) - fun filterChapterByDownloaded() = preferenceStore.getLong("default_chapter_filter_by_downloaded", Manga.SHOW_ALL) + fun filterChapterByDownloaded() = preferenceStore.getLong( + "default_chapter_filter_by_downloaded", + Manga.SHOW_ALL, + ) - fun filterChapterByBookmarked() = preferenceStore.getLong("default_chapter_filter_by_bookmarked", Manga.SHOW_ALL) + fun filterChapterByBookmarked() = preferenceStore.getLong( + "default_chapter_filter_by_bookmarked", + Manga.SHOW_ALL, + ) // and upload date - fun sortChapterBySourceOrNumber() = preferenceStore.getLong("default_chapter_sort_by_source_or_number", Manga.CHAPTER_SORTING_SOURCE) + fun sortChapterBySourceOrNumber() = preferenceStore.getLong( + "default_chapter_sort_by_source_or_number", + Manga.CHAPTER_SORTING_SOURCE, + ) - fun displayChapterByNameOrNumber() = preferenceStore.getLong("default_chapter_display_by_name_or_number", Manga.CHAPTER_DISPLAY_NAME) + fun displayChapterByNameOrNumber() = preferenceStore.getLong( + "default_chapter_display_by_name_or_number", + Manga.CHAPTER_DISPLAY_NAME, + ) - fun sortChapterByAscendingOrDescending() = preferenceStore.getLong("default_chapter_sort_by_ascending_or_descending", Manga.CHAPTER_SORT_DESC) + fun sortChapterByAscendingOrDescending() = preferenceStore.getLong( + "default_chapter_sort_by_ascending_or_descending", + Manga.CHAPTER_SORT_DESC, + ) fun setChapterSettingsDefault(manga: Manga) { filterChapterByRead().set(manga.unreadFilterRaw) @@ -122,7 +186,9 @@ class LibraryPreferences( filterChapterByBookmarked().set(manga.bookmarkedFilterRaw) sortChapterBySourceOrNumber().set(manga.sorting) displayChapterByNameOrNumber().set(manga.displayMode) - sortChapterByAscendingOrDescending().set(if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC) + sortChapterByAscendingOrDescending().set( + if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC, + ) } fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false) @@ -131,9 +197,15 @@ class LibraryPreferences( // region Swipe Actions - fun swipeToStartAction() = preferenceStore.getEnum("pref_chapter_swipe_end_action", ChapterSwipeAction.ToggleBookmark) + fun swipeToStartAction() = preferenceStore.getEnum( + "pref_chapter_swipe_end_action", + ChapterSwipeAction.ToggleBookmark, + ) - fun swipeToEndAction() = preferenceStore.getEnum("pref_chapter_swipe_start_action", ChapterSwipeAction.ToggleRead) + fun swipeToEndAction() = preferenceStore.getEnum( + "pref_chapter_swipe_start_action", + ChapterSwipeAction.ToggleRead, + ) // endregion diff --git a/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt b/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt index 6dc77819eb..8be4350478 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt @@ -27,7 +27,10 @@ class SetFetchInterval( window } val chapters = getChapterByMangaId.await(manga.id) - val interval = manga.fetchInterval.takeIf { it < 0 } ?: calculateInterval(chapters, dateTime) + val interval = manga.fetchInterval.takeIf { it < 0 } ?: calculateInterval( + chapters, + dateTime, + ) val nextUpdate = calculateNextUpdate(manga, interval, dateTime, currentWindow) return if (manga.nextUpdate == nextUpdate && manga.fetchInterval == interval) { @@ -46,7 +49,9 @@ class SetFetchInterval( internal fun calculateInterval(chapters: List, zonedDateTime: ZonedDateTime): Int { val sortedChapters = chapters - .sortedWith(compareByDescending { it.dateUpload }.thenByDescending { it.dateFetch }) + .sortedWith( + compareByDescending { it.dateUpload }.thenByDescending { it.dateFetch }, + ) .take(50) val uploadDates = sortedChapters @@ -95,7 +100,10 @@ class SetFetchInterval( manga.nextUpdate !in window.first.rangeTo(window.second + 1) || manga.fetchInterval == 0 ) { - val latestDate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(manga.lastUpdate), dateTime.zone) + val latestDate = ZonedDateTime.ofInstant( + Instant.ofEpochMilli(manga.lastUpdate), + dateTime.zone, + ) .toLocalDate() .atStartOfDay() val timeSinceLatest = ChronoUnit.DAYS.between(latestDate, dateTime).toInt() diff --git a/domain/src/main/java/tachiyomi/domain/release/interactor/GetApplicationRelease.kt b/domain/src/main/java/tachiyomi/domain/release/interactor/GetApplicationRelease.kt index 735782fd23..1a0ff4e4be 100644 --- a/domain/src/main/java/tachiyomi/domain/release/interactor/GetApplicationRelease.kt +++ b/domain/src/main/java/tachiyomi/domain/release/interactor/GetApplicationRelease.kt @@ -20,7 +20,10 @@ class GetApplicationRelease( val now = Instant.now() // Limit checks to once every 3 days at most - if (arguments.forceCheck.not() && now.isBefore(Instant.ofEpochMilli(lastChecked.get()).plus(3, ChronoUnit.DAYS))) { + if (arguments.forceCheck.not() && now.isBefore( + Instant.ofEpochMilli(lastChecked.get()).plus(3, ChronoUnit.DAYS), + ) + ) { return Result.NoNewUpdate } @@ -29,7 +32,12 @@ class GetApplicationRelease( lastChecked.set(now.toEpochMilli()) // Check if latest version is different from current version - val isNewVersion = isNewVersion(arguments.isPreview, arguments.commitCount, arguments.versionName, release.version) + val isNewVersion = isNewVersion( + arguments.isPreview, + arguments.commitCount, + arguments.versionName, + release.version, + ) return when { isNewVersion && arguments.isThirdParty -> Result.ThirdPartyInstallation isNewVersion -> Result.NewUpdate(release) @@ -37,7 +45,12 @@ class GetApplicationRelease( } } - private fun isNewVersion(isPreview: Boolean, commitCount: Int, versionName: String, versionTag: String): Boolean { + private fun isNewVersion( + isPreview: Boolean, + commitCount: Int, + versionName: String, + versionTag: String, + ): Boolean { // Removes prefixes like "r" or "v" val newVersion = versionTag.replace("[^\\d.]".toRegex(), "") return if (isPreview) { diff --git a/domain/src/test/java/tachiyomi/domain/library/model/LibraryFlagsTest.kt b/domain/src/test/java/tachiyomi/domain/library/model/LibraryFlagsTest.kt index 633ba250e0..408dee18a9 100644 --- a/domain/src/test/java/tachiyomi/domain/library/model/LibraryFlagsTest.kt +++ b/domain/src/test/java/tachiyomi/domain/library/model/LibraryFlagsTest.kt @@ -34,7 +34,10 @@ class LibraryFlagsTest { @Test fun `Test Flag plus operator with old flag as base`() { - val currentSort = LibrarySort(LibrarySort.Type.UnreadCount, LibrarySort.Direction.Descending) + val currentSort = LibrarySort( + LibrarySort.Type.UnreadCount, + LibrarySort.Direction.Descending, + ) currentSort.flag shouldBe 0b00001100 val sort = LibrarySort(LibrarySort.Type.DateAdded, LibrarySort.Direction.Ascending) diff --git a/domain/src/test/java/tachiyomi/domain/release/interactor/GetApplicationReleaseTest.kt b/domain/src/test/java/tachiyomi/domain/release/interactor/GetApplicationReleaseTest.kt index 41df15221d..f813094fe2 100644 --- a/domain/src/test/java/tachiyomi/domain/release/interactor/GetApplicationReleaseTest.kt +++ b/domain/src/test/java/tachiyomi/domain/release/interactor/GetApplicationReleaseTest.kt @@ -79,7 +79,9 @@ class GetApplicationReleaseTest { ), ) - (result as GetApplicationRelease.Result.NewUpdate).release shouldBe GetApplicationRelease.Result.NewUpdate(release).release + (result as GetApplicationRelease.Result.NewUpdate).release shouldBe GetApplicationRelease.Result.NewUpdate( + release, + ).release } @Test @@ -106,7 +108,9 @@ class GetApplicationReleaseTest { ), ) - (result as GetApplicationRelease.Result.NewUpdate).release shouldBe GetApplicationRelease.Result.NewUpdate(release).release + (result as GetApplicationRelease.Result.NewUpdate).release shouldBe GetApplicationRelease.Result.NewUpdate( + release, + ).release } @Test diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d9341f8be0..8d02a4931f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -90,7 +90,7 @@ voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version. voyager-tab-navigator = { module = "cafe.adriel.voyager:voyager-tab-navigator", version.ref = "voyager" } voyager-transitions = { module = "cafe.adriel.voyager:voyager-transitions", version.ref = "voyager" } -kotlinter = "org.jmailen.gradle:kotlinter-gradle:3.13.0" +ktlint = "org.jlleitschuh.gradle:ktlint-gradle:11.5.1" [bundles] okhttp = ["okhttp-core", "okhttp-logging", "okhttp-dnsoverhttps"] diff --git a/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt b/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt index cd10027707..87c1d33c1c 100644 --- a/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt +++ b/macrobenchmark/src/main/java/tachiyomi/macrobenchmark/StartupBenchmark.kt @@ -60,11 +60,16 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { @Test fun startupBaselineProfileDisabled() = startup( - CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Disable, warmupIterations = 1), + CompilationMode.Partial( + baselineProfileMode = BaselineProfileMode.Disable, + warmupIterations = 1, + ), ) @Test - fun startupBaselineProfile() = startup(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require)) + fun startupBaselineProfile() = startup( + CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require), + ) @Test fun startupFullCompilation() = startup(CompilationMode.Full()) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt index 87e17416ac..eea05b4cab 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt @@ -182,7 +182,10 @@ fun AdaptiveSheet( shape = MaterialTheme.shapes.extraLarge, tonalElevation = tonalElevation, content = { - BackHandler(enabled = anchoredDraggableState.targetValue == 0, onBack = internalOnDismissRequest) + BackHandler( + enabled = anchoredDraggableState.targetValue == 0, + onBack = internalOnDismissRequest, + ) content() }, ) @@ -200,49 +203,50 @@ fun AdaptiveSheet( } } -private fun AnchoredDraggableState.preUpPostDownNestedScrollConnection() = object : NestedScrollConnection { - override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset { - val delta = available.toFloat() - return if (delta < 0 && source == NestedScrollSource.Drag) { - dispatchRawDelta(delta).toOffset() - } else { - Offset.Zero +private fun AnchoredDraggableState.preUpPostDownNestedScrollConnection() = + object : NestedScrollConnection { + override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset { + val delta = available.toFloat() + return if (delta < 0 && source == NestedScrollSource.Drag) { + dispatchRawDelta(delta).toOffset() + } else { + Offset.Zero + } } - } - override fun onPostScroll( - consumed: Offset, - available: Offset, - source: NestedScrollSource, - ): Offset { - return if (source == NestedScrollSource.Drag) { - dispatchRawDelta(available.toFloat()).toOffset() - } else { - Offset.Zero + override fun onPostScroll( + consumed: Offset, + available: Offset, + source: NestedScrollSource, + ): Offset { + return if (source == NestedScrollSource.Drag) { + dispatchRawDelta(available.toFloat()).toOffset() + } else { + Offset.Zero + } } - } - override suspend fun onPreFling(available: Velocity): Velocity { - val toFling = available.toFloat() - return if (toFling < 0 && offset > anchors.minAnchor()) { - settle(toFling) - // since we go to the anchor with tween settling, consume all for the best UX - available - } else { - Velocity.Zero + override suspend fun onPreFling(available: Velocity): Velocity { + val toFling = available.toFloat() + return if (toFling < 0 && offset > anchors.minAnchor()) { + settle(toFling) + // since we go to the anchor with tween settling, consume all for the best UX + available + } else { + Velocity.Zero + } } + + override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity { + settle(velocity = available.toFloat()) + return available + } + + private fun Float.toOffset(): Offset = Offset(0f, this) + + @JvmName("velocityToFloat") + private fun Velocity.toFloat() = this.y + + @JvmName("offsetToFloat") + private fun Offset.toFloat(): Float = this.y } - - override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity { - settle(velocity = available.toFloat()) - return available - } - - private fun Float.toOffset(): Offset = Offset(0f, this) - - @JvmName("velocityToFloat") - private fun Velocity.toFloat() = this.y - - @JvmName("offsetToFloat") - private fun Offset.toFloat(): Float = this.y -} diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt index dafe3237d2..bda305890f 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt @@ -37,9 +37,7 @@ import androidx.compose.ui.tooling.preview.Preview * By always rotating we give the feedback to the user that the application isn't 'stuck'. */ @Composable -fun CombinedCircularProgressIndicator( - progress: Float, -) { +fun CombinedCircularProgressIndicator(progress: Float) { val animatedProgress by animateFloatAsState( targetValue = progress, animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt index b70cb27050..ffd4b84e93 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt @@ -23,10 +23,7 @@ import androidx.compose.ui.unit.dp import tachiyomi.presentation.core.theme.header @Composable -fun CollapsibleBox( - heading: String, - content: @Composable () -> Unit, -) { +fun CollapsibleBox(heading: String, content: @Composable () -> Unit) { var expanded by remember { mutableStateOf(false) } Column { diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt index 17dc818cae..86d1225b5a 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt @@ -11,12 +11,7 @@ import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.unit.dp @Composable -fun LinkIcon( - modifier: Modifier = Modifier, - label: String, - icon: ImageVector, - url: String, -) { +fun LinkIcon(modifier: Modifier = Modifier, label: String, icon: ImageVector, url: String) { val uriHandler = LocalUriHandler.current IconButton( modifier = modifier.padding(4.dp), diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt index c0ffb35d42..2fe1287463 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt @@ -9,10 +9,7 @@ import androidx.compose.ui.text.font.FontWeight import tachiyomi.presentation.core.components.material.padding @Composable -fun ListGroupHeader( - modifier: Modifier = Modifier, - text: String, -) { +fun ListGroupHeader(modifier: Modifier = Modifier, text: String) { Text( text = text, modifier = modifier 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 f1d544db7b..bc7cf7ae30 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 @@ -51,16 +51,12 @@ object SettingsItemsPaddings { } @Composable -fun HeadingItem( - @StringRes labelRes: Int, -) { +fun HeadingItem(@StringRes labelRes: Int) { HeadingItem(stringResource(labelRes)) } @Composable -fun HeadingItem( - text: String, -) { +fun HeadingItem(text: String) { Text( text = text, style = MaterialTheme.typography.header, @@ -74,11 +70,7 @@ fun HeadingItem( } @Composable -fun IconItem( - label: String, - icon: ImageVector, - onClick: () -> Unit, -) { +fun IconItem(label: String, icon: ImageVector, onClick: () -> Unit) { BaseSettingsItem( label = label, widget = { @@ -93,11 +85,7 @@ fun IconItem( } @Composable -fun SortItem( - label: String, - sortDescending: Boolean?, - onClick: () -> Unit, -) { +fun SortItem(label: String, sortDescending: Boolean?, onClick: () -> Unit) { val arrowIcon = when (sortDescending) { true -> Icons.Default.ArrowDownward false -> Icons.Default.ArrowUpward @@ -122,10 +110,7 @@ fun SortItem( } @Composable -fun CheckboxItem( - label: String, - pref: Preference, -) { +fun CheckboxItem(label: String, pref: Preference) { val checked by pref.collectAsState() CheckboxItem( label = label, @@ -135,11 +120,7 @@ fun CheckboxItem( } @Composable -fun CheckboxItem( - label: String, - checked: Boolean, - onClick: () -> Unit, -) { +fun CheckboxItem(label: String, checked: Boolean, onClick: () -> Unit) { BaseSettingsItem( label = label, widget = { @@ -153,11 +134,7 @@ fun CheckboxItem( } @Composable -fun RadioItem( - label: String, - selected: Boolean, - onClick: () -> Unit, -) { +fun RadioItem(label: String, selected: Boolean, onClick: () -> Unit) { BaseSettingsItem( label = label, widget = { @@ -314,11 +291,7 @@ fun TriStateItem( } @Composable -fun TextItem( - label: String, - value: String, - onChange: (String) -> Unit, -) { +fun TextItem(label: String, value: String, onChange: (String) -> Unit) { OutlinedTextField( modifier = Modifier .fillMaxWidth() @@ -331,10 +304,7 @@ fun TextItem( } @Composable -fun SettingsChipRow( - @StringRes labelRes: Int, - content: @Composable FlowRowScope.() -> Unit, -) { +fun SettingsChipRow(@StringRes labelRes: Int, content: @Composable FlowRowScope.() -> Unit) { Column { HeadingItem(labelRes) FlowRow( diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt index c65aa96069..4f44f60e25 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/VerticalFastScroller.kt @@ -197,7 +197,8 @@ private fun rememberColumnWidthSums( horizontalArrangement, contentPadding, ) { - { constraints -> + { + constraints -> require(constraints.maxWidth != Constraints.Infinity) { "LazyVerticalGrid's width should be bound by parent" } diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/AlertDialog.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/AlertDialog.kt index 9bbce88bf3..3db94c0183 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/AlertDialog.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/AlertDialog.kt @@ -30,7 +30,9 @@ fun AlertDialogContent( title = title, content = { Column { - CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant) { + CompositionLocalProvider( + LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant, + ) { val textStyle = MaterialTheme.typography.bodyMedium ProvideTextStyle(textStyle) { Box( @@ -54,7 +56,9 @@ fun AlertDialogContent( ) .align(Alignment.End), ) { - CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.primary) { + CompositionLocalProvider( + LocalContentColor provides MaterialTheme.colorScheme.primary, + ) { val textStyle = MaterialTheme.typography.labelLarge ProvideTextStyle(value = textStyle, content = buttons) } @@ -86,7 +90,9 @@ fun AlertDialogContent( .fillMaxWidth(), ) { icon?.let { - CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.secondary) { + CompositionLocalProvider( + LocalContentColor provides MaterialTheme.colorScheme.secondary, + ) { Box( Modifier .padding(IconPadding) @@ -97,7 +103,9 @@ fun AlertDialogContent( } } title?.let { - CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) { + CompositionLocalProvider( + LocalContentColor provides MaterialTheme.colorScheme.onSurface, + ) { val textStyle = MaterialTheme.typography.headlineSmall ProvideTextStyle(textStyle) { Box( diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Button.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Button.kt index 3a5de02759..6a645ed6ac 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Button.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Button.kt @@ -64,20 +64,19 @@ fun TextButton( ), contentPadding: PaddingValues = M3ButtonDefaults.TextButtonContentPadding, content: @Composable RowScope.() -> Unit, -) = - Button( - onClick = onClick, - modifier = modifier, - onLongClick = onLongClick, - enabled = enabled, - interactionSource = interactionSource, - elevation = elevation, - shape = shape, - border = border, - colors = colors, - contentPadding = contentPadding, - content = content, - ) +) = Button( + onClick = onClick, + modifier = modifier, + onLongClick = onLongClick, + enabled = enabled, + interactionSource = interactionSource, + elevation = elevation, + shape = shape, + border = border, + colors = colors, + contentPadding = contentPadding, + content = content, +) /** * Button with additional onLongClick functionality. diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconButton.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconButtonTokens.kt similarity index 100% rename from presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconButton.kt rename to presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconButtonTokens.kt diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/NavigationRail.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/NavigationRail.kt index 02e670ca75..39c00895b3 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/NavigationRail.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/NavigationRail.kt @@ -48,7 +48,10 @@ fun NavigationRail( .padding(vertical = MaterialTheme.padding.tiny) .selectableGroup(), horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.tiny, alignment = Alignment.CenterVertically), + verticalArrangement = Arrangement.spacedBy( + MaterialTheme.padding.tiny, + alignment = Alignment.CenterVertically, + ), ) { if (header != null) { header() diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Scaffold.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Scaffold.kt index 7ecd5964c1..cd14e2c0ed 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Scaffold.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Scaffold.kt @@ -99,7 +99,9 @@ import kotlin.math.max @Composable fun Scaffold( modifier: Modifier = Modifier, - topBarScrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()), + topBarScrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior( + rememberTopAppBarState(), + ), topBar: @Composable (TopAppBarScrollBehavior) -> Unit = {}, bottomBar: @Composable () -> Unit = {}, startBar: @Composable () -> Unit = {}, @@ -116,7 +118,11 @@ fun Scaffold( androidx.compose.material3.Surface( modifier = Modifier .nestedScroll(topBarScrollBehavior.nestedScrollConnection) - .onConsumedWindowInsetsChanged { remainingWindowInsets.insets = contentWindowInsets.exclude(it) } + .onConsumedWindowInsetsChanged { + remainingWindowInsets.insets = contentWindowInsets.exclude( + it, + ) + } .then(modifier), color = containerColor, contentColor = contentColor, @@ -271,7 +277,10 @@ private fun ScaffoldLayout( } else { max(bottomBarHeightPx.toDp(), fabOffsetDp) }, - start = max(insets.calculateStartPadding((this@SubcomposeLayout).layoutDirection), startBarWidth.toDp()), + start = max( + insets.calculateStartPadding((this@SubcomposeLayout).layoutDirection), + startBarWidth.toDp(), + ), end = insets.calculateEndPadding((this@SubcomposeLayout).layoutDirection), ) content(innerPadding) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt index eda45695fb..71866b61d2 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Surface.kt @@ -104,9 +104,7 @@ private fun surfaceColorAtElevation(color: Color, elevation: Dp): Color { } } -private fun ColorScheme.surfaceColorAtElevation( - elevation: Dp, -): Color { +private fun ColorScheme.surfaceColorAtElevation(elevation: Dp): Color { if (elevation == 0.dp) return surface val alpha = ((4.5f * ln(elevation.value + 1)) + 2f) / 100f return surfaceTint.copy(alpha = alpha).compositeOver(surface) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt index d547ad8d02..66e44ca242 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt @@ -46,10 +46,7 @@ private fun Modifier.tabIndicatorOffset( } @Composable -fun TabIndicator( - currentTabPosition: TabPosition, - currentPageOffsetFraction: Float, -) { +fun TabIndicator(currentTabPosition: TabPosition, currentPageOffsetFraction: Float) { SecondaryIndicator( modifier = Modifier .tabIndicatorOffset(currentTabPosition, currentPageOffsetFraction) @@ -59,10 +56,7 @@ fun TabIndicator( } @Composable -fun TabText( - text: String, - badgeCount: Int? = null, -) { +fun TabText(text: String, badgeCount: Int? = null) { val pillAlpha = if (isSystemInDarkTheme()) 0.12f else 0.08f Row( diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/util/Preview.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/util/ThemePreviews.kt similarity index 100% rename from presentation-core/src/main/java/tachiyomi/presentation/core/util/Preview.kt rename to presentation-core/src/main/java/tachiyomi/presentation/core/util/ThemePreviews.kt diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt index 888acec887..5b537f45d7 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt @@ -17,10 +17,7 @@ val CoverWidth = 58.dp val CoverHeight = 87.dp @Composable -fun UpdatesMangaCover( - modifier: GlanceModifier = GlanceModifier, - cover: Bitmap?, -) { +fun UpdatesMangaCover(modifier: GlanceModifier = GlanceModifier, cover: Bitmap?) { Box( modifier = modifier .size(width = CoverWidth, height = CoverHeight) diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt index 15747af982..694dd1e8a0 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt @@ -64,7 +64,9 @@ interface Source { "Use the non-RxJava API instead", ReplaceWith("getMangaDetails"), ) - fun fetchMangaDetails(manga: SManga): Observable = throw IllegalStateException("Not used") + fun fetchMangaDetails(manga: SManga): Observable = throw IllegalStateException( + "Not used", + ) /** * Returns an observable with all the available chapters for a manga. @@ -75,7 +77,9 @@ interface Source { "Use the non-RxJava API instead", ReplaceWith("getChapterList"), ) - fun fetchChapterList(manga: SManga): Observable> = throw IllegalStateException("Not used") + fun fetchChapterList(manga: SManga): Observable> = throw IllegalStateException( + "Not used", + ) /** * Returns an observable with the list of pages a chapter has. Pages should be returned diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Filter.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Filter.kt index f30b2f52d3..99c72e58e9 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Filter.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/model/Filter.kt @@ -3,7 +3,10 @@ package eu.kanade.tachiyomi.source.model sealed class Filter(val name: String, var state: T) { open class Header(name: String) : Filter(name, 0) open class Separator(name: String = "") : Filter(name, 0) - abstract class Select(name: String, val values: Array, state: Int = 0) : Filter(name, state) + abstract class Select(name: String, val values: Array, state: Int = 0) : Filter( + name, + state, + ) abstract class Text(name: String, state: String = "") : Filter(name, state) abstract class CheckBox(name: String, state: Boolean = false) : Filter(name, state) abstract class TriState(name: String, state: Int = STATE_IGNORE) : Filter(name, state) { diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt index 7378f43a8f..5a0acc50eb 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -135,7 +135,11 @@ abstract class HttpSource : CatalogueSource { * @param query the search query. * @param filters the list of filters to apply. */ - override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + override fun fetchSearchManga( + page: Int, + query: String, + filters: FilterList, + ): Observable { return Observable.defer { try { client.newCall(searchMangaRequest(page, query, filters)).asObservableSuccess() @@ -157,7 +161,11 @@ abstract class HttpSource : CatalogueSource { * @param query the search query. * @param filters the list of filters to apply. */ - protected abstract fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request + protected abstract fun searchMangaRequest( + page: Int, + query: String, + filters: FilterList, + ): Request /** * Parses the response from the site and returns a [MangasPage] object.