Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Added doBeforeSdk function #567

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion anko/library/static/commons/src/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ inline fun <T: Any> Fragment.configuration(
else null
}

/**
* Execute [f] only if the current Android SDK version is [version] or older.
* Do nothing otherwise.
*/
inline fun doBeforeSdk(version: Int, f: () -> Unit) {
if (Build.VERSION.SDK_INT <= version) f()
}

/**
* Execute [f] only if the current Android SDK version is [version] or newer.
* Do nothing otherwise.
Expand Down Expand Up @@ -269,4 +277,4 @@ inline fun <T> attempt(f: () -> T): AttemptResult<T> {
error = t
}
return AttemptResult(value, error)
}
}