From 668c073822ec54d938b92713467ed9b1409870d3 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Mon, 7 Oct 2024 12:38:35 +0200 Subject: [PATCH] refactor: Assorted code inspection cleanups (#985) Code inspection found some mechanical code cleanups. --- app/src/main/java/app/pachli/TabViewData.kt | 4 +--- app/src/main/java/app/pachli/fragment/SFragment.kt | 4 ++-- .../data/repository/StatusDisplayOptionsRepository.kt | 2 +- .../main/kotlin/app/pachli/core/model/ContentFilters.kt | 2 +- .../plugins/markdown2resource/Markdown2ResourcePlugin.kt | 3 +-- tools/build.gradle.kts | 8 ++++---- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/app/pachli/TabViewData.kt b/app/src/main/java/app/pachli/TabViewData.kt index 92d672bae..4dcc13260 100644 --- a/app/src/main/java/app/pachli/TabViewData.kt +++ b/app/src/main/java/app/pachli/TabViewData.kt @@ -58,9 +58,7 @@ data class TabViewData( other as TabViewData - if (timeline != other.timeline) return false - - return true + return timeline == other.timeline } override fun hashCode() = timeline.hashCode() diff --git a/app/src/main/java/app/pachli/fragment/SFragment.kt b/app/src/main/java/app/pachli/fragment/SFragment.kt index 3fb1943aa..0309a99bc 100644 --- a/app/src/main/java/app/pachli/fragment/SFragment.kt +++ b/app/src/main/java/app/pachli/fragment/SFragment.kt @@ -122,10 +122,10 @@ abstract class SFragment : Fragment(), StatusActionListener viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { serverRepository.flow.collect { result -> result.onSuccess { - serverCanTranslate = it?.can( + serverCanTranslate = it.can( operation = ORG_JOINMASTODON_STATUSES_TRANSLATE, constraint = ">=1.0".toConstraint(), - ) ?: false + ) } result.onFailure { val msg = getString( diff --git a/core/data/src/main/kotlin/app/pachli/core/data/repository/StatusDisplayOptionsRepository.kt b/core/data/src/main/kotlin/app/pachli/core/data/repository/StatusDisplayOptionsRepository.kt index 46e9ed755..939845a14 100644 --- a/core/data/src/main/kotlin/app/pachli/core/data/repository/StatusDisplayOptionsRepository.kt +++ b/core/data/src/main/kotlin/app/pachli/core/data/repository/StatusDisplayOptionsRepository.kt @@ -163,7 +163,7 @@ class StatusDisplayOptionsRepository @Inject constructor( result.onSuccess { server -> _flow.update { it.copy( - canTranslate = server?.can(ORG_JOINMASTODON_STATUSES_TRANSLATE, ">=1.0".toConstraint()) ?: false, + canTranslate = server.can(ORG_JOINMASTODON_STATUSES_TRANSLATE, ">=1.0".toConstraint()), ) } } diff --git a/core/model/src/main/kotlin/app/pachli/core/model/ContentFilters.kt b/core/model/src/main/kotlin/app/pachli/core/model/ContentFilters.kt index 9844245ed..6ddc9520e 100644 --- a/core/model/src/main/kotlin/app/pachli/core/model/ContentFilters.kt +++ b/core/model/src/main/kotlin/app/pachli/core/model/ContentFilters.kt @@ -52,7 +52,7 @@ data class ContentFilter( val filterAction: FilterAction, val keywords: List = emptyList(), ) : Parcelable { - companion object {} + companion object } /** A filter choice, either content filter or account filter. */ diff --git a/plugins/markdown2resource/src/main/kotlin/app/pachli/plugins/markdown2resource/Markdown2ResourcePlugin.kt b/plugins/markdown2resource/src/main/kotlin/app/pachli/plugins/markdown2resource/Markdown2ResourcePlugin.kt index 8b52a8fa2..e47058830 100644 --- a/plugins/markdown2resource/src/main/kotlin/app/pachli/plugins/markdown2resource/Markdown2ResourcePlugin.kt +++ b/plugins/markdown2resource/src/main/kotlin/app/pachli/plugins/markdown2resource/Markdown2ResourcePlugin.kt @@ -35,7 +35,6 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction -import org.gradle.configurationcache.extensions.capitalized import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor import org.intellij.markdown.html.HtmlGenerator import org.intellij.markdown.parser.MarkdownParser @@ -136,7 +135,7 @@ class Markdown2ResourcePlugin : Plugin { appExtension.libraryVariants.all { variant -> val outputDir = target.layout.buildDirectory.dir("generated/source/${variant.name}") - val taskName = "markdown2resource${variant.name.capitalized()}" + val taskName = "markdown2resource${variant.name.toString().replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }}" extension.packageName.convention(variant.mergeResourcesProvider.get().namespace) diff --git a/tools/build.gradle.kts b/tools/build.gradle.kts index d8653c68a..8a070c113 100644 --- a/tools/build.gradle.kts +++ b/tools/build.gradle.kts @@ -15,7 +15,7 @@ * see . */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { alias(libs.plugins.kotlin.jvm) @@ -25,9 +25,9 @@ subprojects { apply(plugin = "kotlin") apply(plugin = "application") - tasks.withType().configureEach { - kotlinOptions { - freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn" + tasks.named>("compileKotlin").configure { + compilerOptions { + freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn") } }