Skip to content

Commit

Permalink
Header Image: Fix animation while using zoom to fit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Apr 11, 2024
1 parent 7306439 commit ab8655d
Showing 1 changed file with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,24 @@ class HeaderImage(context: Context?) : ModPack(context!!) {
mQsHeaderLayout!!.setFadeSizes(0, 0, bottomFadeAmount, 0)
}

private fun addOrRemoveProperty(view: View, property: Int, flag: Boolean) {
try {
val layoutParams = view.layoutParams as RelativeLayout.LayoutParams
private fun ImageView.addCenterProperty() {
val layoutParams = layoutParams

if (flag) {
layoutParams.addRule(property)
} else {
layoutParams.removeRule(property)
when (layoutParams) {
is RelativeLayout.LayoutParams -> {
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT)
}

view.setLayoutParams(layoutParams)
} catch (throwable: Throwable) {
val layoutParams = view.layoutParams as LinearLayout.LayoutParams

if (flag) {
layoutParams.gravity = property
} else {
layoutParams.gravity = Gravity.NO_GRAVITY
is LinearLayout.LayoutParams -> {
layoutParams.gravity = Gravity.CENTER
}

view.setLayoutParams(layoutParams)
else -> {
log(TAG + "Invalid layoutParams: $layoutParams")
}
}

setLayoutParams(layoutParams)
}

private fun loadImageOrGif(iv: ImageView) {
Expand Down Expand Up @@ -255,8 +251,7 @@ class HeaderImage(context: Context?) : ModPack(context!!) {
iv.setAdjustViewBounds(false)
iv.cropToPadding = false
iv.setMinimumWidth(ViewGroup.LayoutParams.MATCH_PARENT)

addOrRemoveProperty(iv, RelativeLayout.CENTER_IN_PARENT, true)
iv.addCenterProperty()
}

if (drawable is AnimatedImageDrawable) {
Expand Down

0 comments on commit ab8655d

Please sign in to comment.