Skip to content

Commit

Permalink
Feature add base class extensions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
samideliceli authored Jun 2, 2023
1 parent f203766 commit ed1a380
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mobillium.klobalx.nativeext

val Boolean?.orFalse: Boolean
get() = this ?: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mobillium.klobalx.nativeext

val Double?.orZero: Double
get() = this ?: 0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mobillium.klobalx.nativeext

val Float?.orZero: Float
get() = this ?: 0.0f
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mobillium.klobalx.nativeext

val Int?.orZero: Int
get() = this ?: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.mobillium.klobalx.nativeext

val Long?.orZero: Long
get() = this ?: 0L
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
package com.mobillium.klobalx.nativeext

import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan

const val EMPTY_STRING = ""
const val SPACE_STRING = " "
const val SPACE_STRING = " "

fun String.getColorizedSpannable(
vararg strings: String,
color: Int,
flags: Int = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
): SpannableString {
return SpannableString(this).apply {
strings.forEach { string ->
val startIndex = this.indexOf(string)
val endIndex = startIndex + string.length

setSpan(
ForegroundColorSpan(color),
startIndex,
endIndex,
flags
)
}
}
}

0 comments on commit ed1a380

Please sign in to comment.