Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement runOnAfterSDK23 and fix lint errors #386

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import com.skydoves.balloon.extensions.isFinishing
import com.skydoves.balloon.extensions.px2Sp
import com.skydoves.balloon.extensions.runOnAfterSDK21
import com.skydoves.balloon.extensions.runOnAfterSDK22
import com.skydoves.balloon.extensions.runOnAfterSDK23
import com.skydoves.balloon.extensions.sumOfCompoundPadding
import com.skydoves.balloon.extensions.visible
import com.skydoves.balloon.internals.LTR
Expand Down Expand Up @@ -268,25 +269,29 @@ public class Balloon private constructor(
x = getArrowConstraintPositionX(anchor)
y = binding.balloonCard.y + binding.balloonCard.height - SIZE_ARROW_BOUNDARY
ViewCompat.setElevation(this, builder.arrowElevation)
foreground = getArrowForeground(x, binding.balloonCard.height.toFloat())
runOnAfterSDK23 {
foreground = getArrowForeground(x, binding.balloonCard.height.toFloat())
}
}
ArrowOrientation.TOP -> {
rotation = 0f
x = getArrowConstraintPositionX(anchor)
y = binding.balloonCard.y - builder.arrowSize + SIZE_ARROW_BOUNDARY
foreground = getArrowForeground(x, 0f)
runOnAfterSDK23 { foreground = getArrowForeground(x, 0f) }
}
ArrowOrientation.START -> {
rotation = -90f
x = binding.balloonCard.x - builder.arrowSize + SIZE_ARROW_BOUNDARY
y = getArrowConstraintPositionY(anchor)
foreground = getArrowForeground(0f, y)
runOnAfterSDK23 { foreground = getArrowForeground(0f, y) }
}
ArrowOrientation.END -> {
rotation = 90f
x = binding.balloonCard.x + binding.balloonCard.width - SIZE_ARROW_BOUNDARY
y = getArrowConstraintPositionY(anchor)
foreground = getArrowForeground(binding.balloonCard.width.toFloat(), y)
runOnAfterSDK23 {
foreground = getArrowForeground(binding.balloonCard.width.toFloat(), y)
}
}
}
visible(builder.isVisibleArrow)
Expand Down Expand Up @@ -649,7 +654,7 @@ public class Balloon private constructor(
}

private fun getBalloonHighlightAnimation(): Animation? {
val animRes = if (builder.balloonHighlightAnimationStyle == NO_INT_VALUE) {
val animRes: Int = if (builder.balloonHighlightAnimationStyle == NO_INT_VALUE) {
when (builder.balloonHighlightAnimation) {
BalloonHighlightAnimation.HEARTBEAT -> {
if (builder.isVisibleArrow) {
Expand Down Expand Up @@ -1756,7 +1761,7 @@ public class Balloon private constructor(
@set:JvmSynthetic
public var balloonHighlightAnimation: BalloonHighlightAnimation = BalloonHighlightAnimation.NONE

@StyleRes
@AnimRes
@set:JvmSynthetic
public var balloonHighlightAnimationStyle: Int = NO_INT_VALUE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,25 @@ internal inline fun runOnAfterSDK22(block: () -> Unit) {
}
}

/**
* Runs a [block] lambda when the device's SDK level is 23 or higher.
*
* @param block A lambda that should be run when the device's SDK level is 23 or higher.
*/
@JvmSynthetic
@PublishedApi
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.M, lambda = 0)
internal inline fun runOnAfterSDK23(block: () -> Unit) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
block()
}
}

/**
* Checks if the current device's API level is higher than 23 (M).
*/
@JvmSynthetic
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.M)
internal fun isAPILevelHigherThan23(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
}