-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
maksim.zhemerenko
committed
Jan 30, 2024
1 parent
9fe09b9
commit 047465d
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
android/src/main/kotlin/com/ionic/plugin/android/core/utils/BundleUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ionic.plugin.android.core.utils | ||
|
||
import android.os.Bundle | ||
|
||
fun Bundle.optStringSafely(key: String): String? { | ||
if (!containsKey(key)) return null | ||
return getString(key) | ||
} | ||
|
||
fun Bundle.getStringSafely(key: String): String { | ||
return optStringSafely(key) ?: throw IllegalArgumentException("String with '$key' not found in the bundle") | ||
} | ||
|
||
fun Bundle.optIntSafely(key: String): Int? { | ||
if (!containsKey(key)) return null | ||
return getInt(key) | ||
} | ||
|
||
fun Bundle.getIntSafely(key: String): Int { | ||
return optIntSafely(key) ?: throw IllegalArgumentException("Int with '$key' not found in the bundle") | ||
} | ||
|
||
fun Bundle.optBooleanSafely(key: String): Boolean? { | ||
if (!containsKey(key)) return null | ||
return getBoolean(key) | ||
} | ||
|
||
fun Bundle.getBooleanSafely(key: String): Boolean { | ||
return optBooleanSafely(key) ?: throw IllegalArgumentException("Boolean with '$key' not found in the bundle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters