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

Commit 49e7630

Browse files
AkshayChordiya4u7
authored andcommitted
Added doBeforeSdk function (#567)
Added function to execute if SDK version is less than the provided, opposite of `doFromSdk` function.
1 parent 70b428d commit 49e7630

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

anko/library/static/commons/src/Helpers.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ inline fun <T: Any> Fragment.configuration(
217217
else null
218218
}
219219

220+
/**
221+
* Execute [f] only if the current Android SDK version is [version] or older.
222+
* Do nothing otherwise.
223+
*/
224+
inline fun doBeforeSdk(version: Int, f: () -> Unit) {
225+
if (Build.VERSION.SDK_INT <= version) f()
226+
}
227+
220228
/**
221229
* Execute [f] only if the current Android SDK version is [version] or newer.
222230
* Do nothing otherwise.
@@ -269,4 +277,4 @@ inline fun <T> attempt(f: () -> T): AttemptResult<T> {
269277
error = t
270278
}
271279
return AttemptResult(value, error)
272-
}
280+
}

0 commit comments

Comments
 (0)