From 3dca59dfd83bfd13f43dac7ca581133588390fc5 Mon Sep 17 00:00:00 2001 From: lukstbit <52494258+lukstbit@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:44:08 +0300 Subject: [PATCH] Add BundleUtils.getNullableInt helper method --- .../src/main/java/com/ichi2/utils/BundleUtils.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/utils/BundleUtils.kt b/AnkiDroid/src/main/java/com/ichi2/utils/BundleUtils.kt index 809331df818d..7969855ddd54 100644 --- a/AnkiDroid/src/main/java/com/ichi2/utils/BundleUtils.kt +++ b/AnkiDroid/src/main/java/com/ichi2/utils/BundleUtils.kt @@ -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) + } + } }