Skip to content

Commit

Permalink
Replace Enum.values() by Enum.entries
Browse files Browse the repository at this point in the history
> Prior to the introduction of entries in Kotlin 1.9.0, the values() function was used to retrieve an array of enum constants.

from https://kotlinlang.org/docs/enum-classes.html#working-with-enum-constants

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Jun 27, 2024
1 parent 9cb20ff commit 76900ca
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ open class CustomInputTypePreference(context: Context, attrs: AttributeSet) :
inputType = getInt(0, 0)
autofillHints = getString(1)?.split(',')?.toTypedArray()
val whitespaceBehaviorId = getInt(2, 0)
whitespaceBehavior = if (whitespaceBehaviorId < WhitespaceBehavior.values().size) {
WhitespaceBehavior.values()[whitespaceBehaviorId]
whitespaceBehavior = if (whitespaceBehaviorId < WhitespaceBehavior.entries.size) {
WhitespaceBehavior.entries[whitespaceBehaviorId]
} else {
WhitespaceBehavior.IGNORE
}
Expand Down Expand Up @@ -114,8 +114,8 @@ open class CustomInputTypePreference(context: Context, attrs: AttributeSet) :
}
}
val whitespaceBehaviorId = arguments?.getInt(KEY_WHITESPACE_BEHAVIOR, 0) ?: 0
whitespaceBehavior = if (whitespaceBehaviorId < WhitespaceBehavior.values().size) {
WhitespaceBehavior.values()[whitespaceBehaviorId]
whitespaceBehavior = if (whitespaceBehaviorId < WhitespaceBehavior.entries.size) {
WhitespaceBehavior.entries[whitespaceBehaviorId]
} else {
WhitespaceBehavior.IGNORE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class WidgetImageView(context: Context, attrs: AttributeSet?) : AppCompatImageVi
emptyHeightToWidthRatio = getFraction(R.styleable.WidgetImageView_emptyHeightToWidthRatio, 1, 1, 0f)
addRandomnessToUrl = getBoolean(R.styleable.WidgetImageView_addRandomnessToUrl, false)
val imageScalingType = getInt(R.styleable.WidgetImageView_imageScalingType, 0)
if (imageScalingType < ImageScalingType.values().size) {
setImageScalingType(ImageScalingType.values()[imageScalingType])
if (imageScalingType < ImageScalingType.entries.size) {
setImageScalingType(ImageScalingType.entries[imageScalingType])
}
recycle()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ class CacheManager private constructor(appContext: Context) {
}

fun removeWidgetIcon(widgetId: Int) {
IconFormat.values().forEach { format -> getWidgetIconFile(widgetId, format).delete() }
IconFormat.entries.forEach { format -> getWidgetIconFile(widgetId, format).delete() }
}

fun getWidgetIconFormat(widgetId: Int): IconFormat? {
return IconFormat.values()
return IconFormat.entries
.firstOrNull { format -> getWidgetIconFile(widgetId, format).exists() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ItemTest {
@Test
fun tagsHaveLabel() {
val mustHaveLabel = listOf(Item.Tag.Location, Item.Tag.Equipment)
Item.Tag.values()
Item.Tag.entries
.filter { tag -> tag.parent in mustHaveLabel }
.forEach { tag ->
assertNotNull(tag.labelResId)
Expand Down

0 comments on commit 76900ca

Please sign in to comment.