diff --git a/resources-ktx/CHANGELOG.md b/resources-ktx/CHANGELOG.md index 15e60fb..7bc0fd5 100644 --- a/resources-ktx/CHANGELOG.md +++ b/resources-ktx/CHANGELOG.md @@ -8,6 +8,10 @@ - **Fragment**: new extensions `getQuantityString` - **View**: new extensions `getQuantityString` +### Fixed + +- `Inline` modifier added back to all resource accessors + ### Dependencies - androidx.core 1.5.0 -> 1.6.0 diff --git a/resources-ktx/src/main/kotlin/FragmentResourcesAccessors.kt b/resources-ktx/src/main/kotlin/FragmentResourcesAccessors.kt index 8dbcb47..b673298 100644 --- a/resources-ktx/src/main/kotlin/FragmentResourcesAccessors.kt +++ b/resources-ktx/src/main/kotlin/FragmentResourcesAccessors.kt @@ -15,13 +15,13 @@ import androidx.fragment.app.Fragment * @see ContextCompat.getColor */ @ColorInt -public fun Fragment.getColor(@ColorRes resId: Int): Int = ContextCompat.getColor(requireContext(), resId) +public inline fun Fragment.getColor(@ColorRes resId: Int): Int = ContextCompat.getColor(requireContext(), resId) /** * Returns a color state list associated with given [resId]. * @see ContextCompat.getColorStateList */ -public fun Fragment.getColorStateList(@ColorRes resId: Int): ColorStateList? { +public inline fun Fragment.getColorStateList(@ColorRes resId: Int): ColorStateList? { return ContextCompat.getColorStateList(requireContext(), resId) } @@ -31,7 +31,7 @@ public fun Fragment.getColorStateList(@ColorRes resId: Int): ColorStateList? { * @see AppCompatResources.getDrawable * @see getDrawableWithTint */ -public fun Fragment.getDrawable(@DrawableRes resId: Int): Drawable? { +public inline fun Fragment.getDrawable(@DrawableRes resId: Int): Drawable? { return AppCompatResources.getDrawable(requireContext(), resId) } @@ -41,7 +41,7 @@ public fun Fragment.getDrawable(@DrawableRes resId: Int): Drawable? { * @see getDrawable * @see getDrawableWithTint */ -public fun Fragment.getDrawableWithTint(@DrawableRes resId: Int, @ColorInt tint: Int): Drawable? { +public inline fun Fragment.getDrawableWithTint(@DrawableRes resId: Int, @ColorInt tint: Int): Drawable? { return getDrawable(resId)?.withTint(tint) } @@ -49,7 +49,7 @@ public fun Fragment.getDrawableWithTint(@DrawableRes resId: Int, @ColorInt tint: * Returns a dimension value associated with given [resId] in pixels. * @see Resources.getDimension */ -public fun Fragment.getDimension(@DimenRes resId: Int): Float = resources.getDimension(resId) +public inline fun Fragment.getDimension(@DimenRes resId: Int): Float = resources.getDimension(resId) /** * Returns a dimension value associated with given [resId] in integer pixels. @@ -57,20 +57,20 @@ public fun Fragment.getDimension(@DimenRes resId: Int): Float = resources.getDim * a non-zero base value is at least one pixel in size. * @see Resources.getDimensionPixelSize */ -public fun Fragment.getDimensionPixelSize(@DimenRes resId: Int): Int = resources.getDimensionPixelSize(resId) +public inline fun Fragment.getDimensionPixelSize(@DimenRes resId: Int): Int = resources.getDimensionPixelSize(resId) /** * Returns a dimension value associated with given [resId] in integer pixels. * An offset conversion involves simply truncating the base value to an integer. * @see Resources.getDimensionPixelOffset */ -public fun Fragment.getDimensionPixelOffset(@DimenRes resId: Int): Int = resources.getDimensionPixelOffset(resId) +public inline fun Fragment.getDimensionPixelOffset(@DimenRes resId: Int): Int = resources.getDimensionPixelOffset(resId) /** * Returns a string associated with given [resId] and pluralized according to [quantity]. * @see Resources.getQuantityString */ -public fun Fragment.getQuantityString(@PluralsRes resId: Int, quantity: Int): String { +public inline fun Fragment.getQuantityString(@PluralsRes resId: Int, quantity: Int): String { return resources.getQuantityString(resId, quantity) } @@ -79,6 +79,6 @@ public fun Fragment.getQuantityString(@PluralsRes resId: Int, quantity: Int): St * substituting the [formatArgs] as defined in [String.format]. * @see Resources.getQuantityString */ -public fun Fragment.getQuantityString(@PluralsRes resId: Int, quantity: Int, vararg formatArgs: Any): String { +public inline fun Fragment.getQuantityString(@PluralsRes resId: Int, quantity: Int, vararg formatArgs: Any): String { return resources.getQuantityString(resId, quantity, *formatArgs) } diff --git a/resources-ktx/src/main/kotlin/Text.kt b/resources-ktx/src/main/kotlin/Text.kt index 84f347c..40e56a1 100644 --- a/resources-ktx/src/main/kotlin/Text.kt +++ b/resources-ktx/src/main/kotlin/Text.kt @@ -1,3 +1,5 @@ +@file:Suppress("NOTHING_TO_INLINE") + package com.redmadrobot.extensions.resources import android.content.Context @@ -37,16 +39,16 @@ public sealed class Text { * Unwraps and returns a string for the given [text]. * @see Text */ -public fun Context.getString(text: Text): String = text.get(this) +public inline fun Context.getString(text: Text): String = text.get(this) /** * Unwraps and returns a string for the given [text]. * @see Text */ -public fun Fragment.getString(text: Text): String = requireContext().getString(text) +public inline fun Fragment.getString(text: Text): String = requireContext().getString(text) /** * Unwraps and returns a string for the given [text]. * @see Text */ -public fun View.getString(text: Text): String = context.getString(text) +public inline fun View.getString(text: Text): String = context.getString(text) diff --git a/resources-ktx/src/main/kotlin/ViewResourcesAccessors.kt b/resources-ktx/src/main/kotlin/ViewResourcesAccessors.kt index 7cc7ae8..f4ade85 100644 --- a/resources-ktx/src/main/kotlin/ViewResourcesAccessors.kt +++ b/resources-ktx/src/main/kotlin/ViewResourcesAccessors.kt @@ -15,20 +15,20 @@ import androidx.core.content.ContextCompat * @see ContextCompat.getColor */ @ColorInt -public fun View.getColor(@ColorRes resId: Int): Int = ContextCompat.getColor(context, resId) +public inline fun View.getColor(@ColorRes resId: Int): Int = ContextCompat.getColor(context, resId) /** * Returns a color state list associated with given [resId]. * @see ContextCompat.getColorStateList */ -public fun View.getColorStateList(@ColorRes resId: Int): ColorStateList? = +public inline fun View.getColorStateList(@ColorRes resId: Int): ColorStateList? = ContextCompat.getColorStateList(context, resId) /** * Returns a dimension value associated with given [resId] in pixels. * @see Resources.getDimension */ -public fun View.getDimension(@DimenRes resId: Int): Float = resources.getDimension(resId) +public inline fun View.getDimension(@DimenRes resId: Int): Float = resources.getDimension(resId) /** * Returns a dimension value associated with given [resId] in integer pixels. @@ -36,14 +36,14 @@ public fun View.getDimension(@DimenRes resId: Int): Float = resources.getDimensi * a non-zero base value is at least one pixel in size. * @see Resources.getDimensionPixelSize */ -public fun View.getDimensionPixelSize(@DimenRes resId: Int): Int = resources.getDimensionPixelSize(resId) +public inline fun View.getDimensionPixelSize(@DimenRes resId: Int): Int = resources.getDimensionPixelSize(resId) /** * Returns a dimension value associated with given [resId] in integer pixels. * An offset conversion involves simply truncating the base value to an integer. * @see Resources.getDimensionPixelOffset */ -public fun View.getDimensionPixelOffset(@DimenRes resId: Int): Int = resources.getDimensionPixelOffset(resId) +public inline fun View.getDimensionPixelOffset(@DimenRes resId: Int): Int = resources.getDimensionPixelOffset(resId) /** * Returns a drawable associated with given [resId], @@ -51,7 +51,7 @@ public fun View.getDimensionPixelOffset(@DimenRes resId: Int): Int = resources.g * @see AppCompatResources.getDrawable * @see getDrawableWithTint */ -public fun View.getDrawable(@DrawableRes resId: Int): Drawable? = AppCompatResources.getDrawable(context, resId) +public inline fun View.getDrawable(@DrawableRes resId: Int): Drawable? = AppCompatResources.getDrawable(context, resId) /** * Returns a drawable associated with given [resId], @@ -59,7 +59,7 @@ public fun View.getDrawable(@DrawableRes resId: Int): Drawable? = AppCompatResou * @see getDrawable * @see getDrawableWithTint */ -public fun View.requireDrawable(@DrawableRes resId: Int): Drawable = requireNotNull(getDrawable(resId)) +public inline fun View.requireDrawable(@DrawableRes resId: Int): Drawable = requireNotNull(getDrawable(resId)) /** * Returns a drawable associated with given [resId] and tinted with specified [tint] color, @@ -67,7 +67,7 @@ public fun View.requireDrawable(@DrawableRes resId: Int): Drawable = requireNotN * @see getDrawable * @see withTint */ -public fun View.getDrawableWithTint(@DrawableRes resId: Int, @ColorInt tint: Int): Drawable? { +public inline fun View.getDrawableWithTint(@DrawableRes resId: Int, @ColorInt tint: Int): Drawable? { return getDrawable(resId)?.withTint(tint) } @@ -75,7 +75,7 @@ public fun View.getDrawableWithTint(@DrawableRes resId: Int, @ColorInt tint: Int * Returns a localized string associated with given [resId]. * @see Resources.getString */ -public fun View.getString(@StringRes resId: Int): String = resources.getString(resId) +public inline fun View.getString(@StringRes resId: Int): String = resources.getString(resId) /** * Returns a localized formatted string associated with given [resId], @@ -83,14 +83,14 @@ public fun View.getString(@StringRes resId: Int): String = resources.getString(r * @see Resources.getString */ @Suppress("SpreadOperator") // Doesn't affect performance -public fun View.getString(@StringRes resId: Int, vararg formatArgs: Any): String = +public inline fun View.getString(@StringRes resId: Int, vararg formatArgs: Any): String = resources.getString(resId, *formatArgs) /** * Returns a string associated with given [resId] and pluralized according to [quantity]. * @see Resources.getQuantityString */ -public fun View.getQuantityString(@PluralsRes resId: Int, quantity: Int): String { +public inline fun View.getQuantityString(@PluralsRes resId: Int, quantity: Int): String { return resources.getQuantityString(resId, quantity) } @@ -99,6 +99,6 @@ public fun View.getQuantityString(@PluralsRes resId: Int, quantity: Int): String * substituting the [formatArgs] as defined in [String.format]. * @see Resources.getQuantityString */ -public fun View.getQuantityString(@PluralsRes resId: Int, quantity: Int, vararg formatArgs: Any): String { +public inline fun View.getQuantityString(@PluralsRes resId: Int, quantity: Int, vararg formatArgs: Any): String { return resources.getQuantityString(resId, quantity, *formatArgs) }