From 227c4f4b7fc44de1562340df92e4362e14dd35cb Mon Sep 17 00:00:00 2001 From: Hidetsugu Tamaki Date: Fri, 29 Nov 2024 21:44:58 +0900 Subject: [PATCH] Adjust ktlint configuration and fix for ktlint --- .editorconfig | 28 ++++++++++++++++--- apng-drawable/build.gradle.kts | 5 +++- .../kotlin/com/linecorp/apng/ApngDrawable.kt | 28 +++++++++---------- .../linecorp/apng/RepeatAnimationCallback.kt | 10 ++----- .../linecorp/apng/decoder/ApngException.kt | 8 ++++++ 5 files changed, 51 insertions(+), 28 deletions(-) diff --git a/.editorconfig b/.editorconfig index aa5c41e..9e78226 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,13 +12,33 @@ trim_trailing_whitespace = true ij_continuation_indent_size = 8 ij_smart_tabs = false -[{*.kt, *.kts}] +[*.{kt,kts}] +# https://pinterest.github.io/ktlint/rules/configuration-ktlint/ +ktlint_code_style = android_studio + +# Disable the rules from the 'standard' rule set provided by KtLint +ktlint_standard_discouraged-comment-location = disabled +ktlint_standard_comment-wrapping = disabled +ktlint_standard_property-naming = disabled +ktlint_standard_class-naming = disabled +ktlint_standard_trailing-comma-on-call-site = disabled +ktlint_standard_trailing-comma-on-declaration-site = disabled +ktlint_standard_no-semi = disabled + ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL -continuation_indent_size = 4 -ij_continuation_indent_size = 4 +ij_kotlin_line_comment_at_first_column = false +ij_kotlin_line_comment_add_space = true +ij_kotlin_use_custom_formatting_for_modifiers = true ij_kotlin_name_count_to_use_star_import = 2147483647 ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 -disabled_rules = import-ordering +ij_kotlin_keep_blank_lines_in_declarations = 1 +ij_kotlin_keep_blank_lines_in_code = 1 +ij_kotlin_keep_blank_lines_before_right_brace = 0 +ij_kotlin_align_multiline_parameters = false +continuation_indent_size = 4 +ij_continuation_indent_size = 4 +ij_kotlin_import_nested_classes = false +ij_kotlin_imports_layout = *, ^ [{*.yml, *.yaml}] indent_size = 2 diff --git a/apng-drawable/build.gradle.kts b/apng-drawable/build.gradle.kts index 56ae16e..faf15c4 100644 --- a/apng-drawable/build.gradle.kts +++ b/apng-drawable/build.gradle.kts @@ -120,7 +120,10 @@ afterEvaluate { pom { packaging = "aar" name.set("ApngDrawable") - description.set("Fast and light weight Animated Portable Network Graphics(APNG) image decoder library for Android platform") + description.set( + "Fast and light weight Animated Portable Network Graphics(APNG) image" + + " decoder library for Android platform" + ) url.set("https://github.com/line/apng-drawable") licenses { license { diff --git a/apng-drawable/src/main/kotlin/com/linecorp/apng/ApngDrawable.kt b/apng-drawable/src/main/kotlin/com/linecorp/apng/ApngDrawable.kt index bf08f1d..94a7b6b 100644 --- a/apng-drawable/src/main/kotlin/com/linecorp/apng/ApngDrawable.kt +++ b/apng-drawable/src/main/kotlin/com/linecorp/apng/ApngDrawable.kt @@ -132,13 +132,18 @@ class ApngDrawable @VisibleForTesting internal constructor( */ val currentFrameIndex: Int get() { - var progressMillisInCurrentLoop = if (durationMillis == 0) 0 else animationElapsedTimeMillis % durationMillis + var progressMillisInCurrentLoop = + if (durationMillis == 0) 0 else animationElapsedTimeMillis % durationMillis progressMillisInCurrentLoop += if (exceedsRepeatCountLimitation()) durationMillis else 0 return calculateCurrentFrameIndex(0, frameCount - 1, progressMillisInCurrentLoop) } private val currentLoopIndexInternal: Int - get() = if (durationMillis == 0) 0 else (animationElapsedTimeMillis / durationMillis).toInt() + get() = if (durationMillis == 0) { + 0 + } else { + (animationElapsedTimeMillis / durationMillis).toInt() + } private val paint: Paint = Paint(Paint.FILTER_BITMAP_FLAG or Paint.DITHER_FLAG) private val animationCallbacks: MutableList = arrayListOf() private val repeatAnimationCallbacks: MutableList = arrayListOf() @@ -237,9 +242,8 @@ class ApngDrawable @VisibleForTesting internal constructor( repeatAnimationCallbacks.add(repeatCallback) } - fun unregisterRepeatAnimationCallback( - repeatCallback: RepeatAnimationCallback - ): Boolean = repeatAnimationCallbacks.remove(repeatCallback) + fun unregisterRepeatAnimationCallback(repeatCallback: RepeatAnimationCallback): Boolean = + repeatAnimationCallbacks.remove(repeatCallback) override fun clearAnimationCallbacks() = animationCallbacks.clear() @@ -542,11 +546,8 @@ class ApngDrawable @VisibleForTesting internal constructor( */ @WorkerThread @Throws(ApngException::class, FileNotFoundException::class, IOException::class) - fun decode( - filePath: String, - width: Int? = null, - height: Int? = null - ): ApngDrawable = decode(File(filePath), width, height) + fun decode(filePath: String, width: Int? = null, height: Int? = null): ApngDrawable = + decode(File(filePath), width, height) /** * Creates [ApngDrawable] from given [file]. @@ -565,11 +566,8 @@ class ApngDrawable @VisibleForTesting internal constructor( */ @WorkerThread @Throws(ApngException::class, FileNotFoundException::class, IOException::class) - fun decode( - file: File, - width: Int? = null, - height: Int? = null - ): ApngDrawable = file.inputStream().buffered().use { decode(it, width, height) } + fun decode(file: File, width: Int? = null, height: Int? = null): ApngDrawable = + file.inputStream().buffered().use { decode(it, width, height) } /** * Creates [ApngDrawable] from given [stream]. diff --git a/apng-drawable/src/main/kotlin/com/linecorp/apng/RepeatAnimationCallback.kt b/apng-drawable/src/main/kotlin/com/linecorp/apng/RepeatAnimationCallback.kt index cb01d72..0b3c738 100644 --- a/apng-drawable/src/main/kotlin/com/linecorp/apng/RepeatAnimationCallback.kt +++ b/apng-drawable/src/main/kotlin/com/linecorp/apng/RepeatAnimationCallback.kt @@ -12,10 +12,7 @@ interface RepeatAnimationCallback { message = "Use onAnimationRepeat", replaceWith = ReplaceWith("") ) - fun onRepeat( - drawable: ApngDrawable, - nextLoop: Int - ) = Unit + fun onRepeat(drawable: ApngDrawable, nextLoop: Int) = Unit /** * This is called when animation is about to be repeated. @@ -26,8 +23,5 @@ interface RepeatAnimationCallback { * @param [nextLoopIndex] loop index of the next animation. e.g. If [nextLoopIndex] equals to * `[ApngDrawable.loopCount] - 1`, the last loop will be started. */ - fun onAnimationRepeat( - drawable: ApngDrawable, - nextLoopIndex: Int - ) = Unit + fun onAnimationRepeat(drawable: ApngDrawable, nextLoopIndex: Int) = Unit } diff --git a/apng-drawable/src/main/kotlin/com/linecorp/apng/decoder/ApngException.kt b/apng-drawable/src/main/kotlin/com/linecorp/apng/decoder/ApngException.kt index 5ee5493..e3e3754 100644 --- a/apng-drawable/src/main/kotlin/com/linecorp/apng/decoder/ApngException.kt +++ b/apng-drawable/src/main/kotlin/com/linecorp/apng/decoder/ApngException.kt @@ -51,35 +51,43 @@ class ApngException internal constructor( * When an error occurs in [java.io.InputStream.read]. */ ERR_STREAM_READ_FAIL(-100), + /** * When EOF came before reading the required size in [java.io.InputStream.read]. */ ERR_UNEXPECTED_EOF(-101), + /** * When an image was not in APNG format. */ ERR_INVALID_FILE_FORMAT(-102), + /** * When using an image that has not yet been decoded or deleted. */ ERR_NOT_EXIST_IMAGE(-103), + /** * When using a frame outside the range of this image. */ ERR_FRAME_INDEX_OUT_OF_RANGE(-104), + /** * When memory can not be allocated. */ ERR_OUT_OF_MEMORY(-105), + /** * When an error occurs in the operation to the [android.graphics.Bitmap]. */ ERR_BITMAP_OPERATION(-106), + /** * When an image is not supported APNG image. * Example: tries to load non-4 channel image.(Currently, supported 4 channel image only.) */ ERR_UNSUPPORTED_TYPE(-107), + /** * When there is an inner exception. */