Skip to content

Commit a02327e

Browse files
lukstbitmikehardy
authored andcommitted
Add SavedStateHandle.getLongOrNull() helper
1 parent 043399a commit a02327e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import com.ichi2.anki.utils.CollectionPreferences
6464
import com.ichi2.anki.utils.Destination
6565
import com.ichi2.anki.utils.ext.answerCard
6666
import com.ichi2.anki.utils.ext.flag
67+
import com.ichi2.anki.utils.ext.getLongOrNull
6768
import com.ichi2.anki.utils.ext.setUserFlagForCards
6869
import kotlinx.coroutines.CompletableDeferred
6970
import kotlinx.coroutines.Deferred

AnkiDroid/src/main/java/com/ichi2/anki/utils/ext/SavedStateHandle.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ fun <T> SavedStateHandle.require(key: String): T =
2121
checkNotNull(get(key)) {
2222
"Wrong type or key '$key' not found"
2323
}
24+
25+
/**
26+
* Retrieves the [Long] value for the provided [key], returns null if not found.
27+
*
28+
* @param key the key to use
29+
* @return the long value, or null if not found
30+
*/
31+
fun SavedStateHandle.getLongOrNull(key: String): Long? =
32+
if (contains(key)) {
33+
get(key) as Long?
34+
} else {
35+
null
36+
}

0 commit comments

Comments
 (0)