Skip to content

Commit

Permalink
Adjust ktlint configuration and fix for ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
r-ralph committed Nov 29, 2024
1 parent b2089e6 commit 227c4f4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
28 changes: 24 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion apng-drawable/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 13 additions & 15 deletions apng-drawable/src/main/kotlin/com/linecorp/apng/ApngDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Animatable2Compat.AnimationCallback> = arrayListOf()
private val repeatAnimationCallbacks: MutableList<RepeatAnimationCallback> = arrayListOf()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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].
Expand All @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 227c4f4

Please sign in to comment.