Skip to content

Commit

Permalink
Add BundleUtils.getNullableInt helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstbit authored and mikehardy committed Sep 28, 2024
1 parent ac0f2c2 commit 3dca59d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/utils/BundleUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ object BundleUtils {
}
return getLong(key)
}

/**
* Retrieves a [Int] value from a [Bundle] using a key, returns null if not found
*
* can be null to support nullable bundles like [androidx.fragment.app.Fragment.getArguments]
* @param key the key to use
* @return the int value, or null if not found
*/
fun Bundle.getNullableInt(key: String): Int? {
return if (!containsKey(key)) {
null
} else {
getInt(key)
}
}
}

0 comments on commit 3dca59d

Please sign in to comment.