Skip to content

Commit

Permalink
PWN-8992 - make utils to get drawable with needed sizes to fix issues…
Browse files Browse the repository at this point in the history
… with icon size on UiKitStartAmountView.kt
  • Loading branch information
kabramovp2p committed Jun 26, 2023
1 parent d39c67c commit 02d517c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import org.p2p.core.utils.insets.consume
import org.p2p.core.utils.insets.doOnApplyWindowInsets
import org.p2p.core.utils.insets.systemAndIme
import org.p2p.uikit.utils.getColor
import org.p2p.uikit.utils.toPx
import org.p2p.wallet.R
import org.p2p.wallet.common.mvp.BaseMvpFragment
import org.p2p.wallet.databinding.FragmentSecurityAndPrivacyBinding
import org.p2p.wallet.intercom.IntercomService
import org.p2p.wallet.settings.ui.devices.DevicesFragment
import org.p2p.wallet.settings.ui.security.unlock.SeedPhraseUnlockFragment
import org.p2p.wallet.utils.DrawableUtils.getDrawableWithSizes
import org.p2p.wallet.utils.popBackStack
import org.p2p.wallet.utils.replaceFragment
import org.p2p.wallet.utils.showInfoDialog
Expand Down Expand Up @@ -65,7 +67,14 @@ class SecurityAndPrivacyFragment :
binding.recoveryViewDevice.apply {
subtitle = deviceName
if (showWarning) {
setSubtitleDrawable(left = R.drawable.ic_warning_solid)
val drawableSize = 16.toPx()
val scaledDrawable = getDrawableWithSizes(
context = requireContext(),
drawableId = R.drawable.ic_warning_solid,
width = drawableSize,
height = drawableSize
)
setSubtitleDrawable(left = scaledDrawable)
setSubtitleColor(getColor(R.color.icons_rose))
}
}
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/org/p2p/wallet/utils/DrawableUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.p2p.wallet.utils

import androidx.annotation.Dimension
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources
import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable

object DrawableUtils {
fun getDrawableWithSizes(
context: Context,
@DrawableRes drawableId: Int,
@Dimension(unit = Dimension.DP)
width: Int,
@Dimension(unit = Dimension.DP)
height: Int,
): Drawable? {
val drawable = AppCompatResources.getDrawable(context, drawableId) ?: return null
return getResizedDrawableUsingSpecificSize(drawable, width, height)
}

private fun getResizedDrawableUsingSpecificSize(drawable: Drawable, newWidth: Int, newHeight: Int): LayerDrawable {
return LayerDrawable(arrayOf(drawable)).also { it.setLayerSize(0, newWidth, newHeight) }
}
}
10 changes: 10 additions & 0 deletions ui-kit/src/main/kotlin/org/p2p/uikit/atoms/UiKitStartAmountView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.annotation.DrawableRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.res.use
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import org.p2p.uikit.R
import org.p2p.uikit.databinding.WidgetStartAmountViewBinding
Expand Down Expand Up @@ -53,6 +54,15 @@ class UiKitStartAmountView @JvmOverloads constructor(
binding.subtitleTextView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
}

fun setSubtitleDrawable(
left: Drawable? = null,
top: Drawable? = null,
right: Drawable? = null,
bottom: Drawable? = null
) {
binding.subtitleTextView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
}

fun setSubtitleColor(@ColorInt subtitleTextColor: Int) {
binding.subtitleTextView.setTextColor(subtitleTextColor)
}
Expand Down

0 comments on commit 02d517c

Please sign in to comment.