Releases: skydoves/WhatIf
1.0.6
1.0.5
🎉 Released a new version 1.0.5
! 🎉
What's New?
- Added whatIfElse.
An expression for invoking whatIf lambda when the target boolean is not null and false.
nullableBoolean.whatIfElse {
log("nullableBoolean is not null and false")
}
- Added whatIfAnd, whatIfOr.
An expression for invoking whatIf lambda when the target boolean is true and/or a predicate receiver is true.
nullableBoolean.whatIfAnd(predicate) {
log("nullableBoolean is true and the predicate is also true")
}
nullableBoolean.whatIfOr(predicate) {
log("nullableBoolean is true or the predicate is true")
}
WhatIf for Android fragment
- whatIfNotNullContext.
An expression for invoking whatIf lambda when the Context is not null.
class WhatIfFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
whatIfNotNullContext {
Toast.makeText(it, "context is not null!", Toast.LENGTH_SHORT).show()
}
}
}
- whatIfNotNullArguments
An expression for invoking whatIf when the Fragment.getArguments is not null.
whatIfNotNullArguments {
it.getString("name").whatIfNotNull {
log("my name is $it")
}
}
- whatIfNotNullActivity
whatIfNotNullActivity { activity ->
activity.supportFragmentManager.addOnBackStackChangedListener {
// .. //
}
}
1.0.4
Released version 1.0.4
.
WhatIfHasExtras
An expression for invoking whatIf lambda when the Activity's intent extras is not null and not empty.
var foo: String? = null
this@MainActivity.whatIfHasExtras {
foo = "${it.getString("foo")}"
}
And we can handle the null case.
this@MainActivity.whatIfHasExtras(
whatIf = { foo = "${it.getString("foo")}" },
whatIfNot = { log("intent extras is null or empty.") }
)
1.0.3
Released version 1.0.3
.
Implemented whatIfNotNullOrEmpty
for string type.
We can execute a single lambda if the string is not null and not empty.
val nullableString: String? = "NotNullOrEmpty"
nullableString.whatIfNotNullOrEmpty {
log("$it is not null and not empty")
}
Or we can handle the null or empty case.
nullableString.whatIfNotNullOrEmpty(
whatIf = { nullableString = it },
whatIfNot = { nullableString = "NullOrEmpty" }
)
1.0.2
Version 1.0.2
is released.
Changed whatIfNotNullOrEmpty
collections separated toList
and Set
.
In whatIfNotNullOrEmpty
, whatIf lambda will receive not-null type collection type.
Implemented whatIfNotNullAs
.
If the target is not null, the receiver will get a casted type.
var nullableIntList: MutableList<Int>? = null
nullableIntList.whatIfNotNullAs<List<Int>> {
nullableInt = it.size
}
1.0.1
Version 1.0.1 is released.
Implemented below functionality extensions.
whatIfNotNullOrEmpty
for array type and collections.
Array type : Array, ByteArray, ShortArray, IntArray, LongArray, FloatArray, DoubleArray, BooleanArray, CharArray
Collections: List, Map, Set