Skip to content

Instantly share code, notes, and snippets.

View victory316's full-sized avatar

SH Choi victory316

View GitHub Profile
@victory316
victory316 / BindingAdapters.kt
Last active January 3, 2023 07:15
Multiple Spanned Text BindingAdapter
@BindingAdapter(
"multipleSpannedText"
)
fun setCommentItem(
textView: TextView,
multipleSpannedText: String
) {
val clickableSpanText = commentItem.comment.formattedComment
val clickableSpan = object : ClickableSpan() {
@victory316
victory316 / CustomExtensions.kt
Last active January 3, 2023 07:14
Useful Kotlin extensions
fun Any?.isNull(): Boolean {
return this == null
}
fun Any?.isNotNull(): Boolean {
return this != null
}
@victory316
victory316 / ComposeTest.kt
Last active December 8, 2022 01:04
Matcher using when Jetpack Compose UI test with Role
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.semantics.getOrNull
import androidx.compose.ui.test.SemanticsMatcher
// needs import below
// debugImplementation 'androidx.compose.ui:ui-test-manifest:1.0.0-beta05'
// from Yasin Kaçmaz : https://proandroiddev.com/test-jetpack-compose-layouts-easily-with-role-semanticproperty-dcf19f64130f
fun withRole(role: Role) = SemanticsMatcher("${SemanticsProperties.Role.name} contains '$role'") {
@victory316
victory316 / appear_from_bottom_to_top
Created December 15, 2022 00:39
Android XML Animation sets
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fillAfter="true"
android:interpolator="@android:anim/overshoot_interpolator">
<translate
android:fromYDelta="100%"
android:toYDelta="0%" />
@victory316
victory316 / CustomView.kt
Last active December 15, 2022 13:35
CustomView template on Kotlin
class CustomView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
private var binding: CustomViewBinding
private var typedArray: TypedArray
init {
@victory316
victory316 / ViewExtensions.kt
Last active December 22, 2022 00:18
View extensions with coroutine
fun View.setDelayedJob(delayInMillis: Long, operation: () -> Unit): Job {
return CoroutineScope(Dispatchers.IO).launch {
delay(delayInMillis)
CoroutineScope(Dispatchers.Main).launch {
operation.invoke()
}
}
}
@victory316
victory316 / KotlinStatements.kt
Created December 27, 2022 08:44
When statement parsing sealed class
when (val result = queryList) {
is Result.Error -> {}
is Result.Loading -> {}
is Result.Success -> {
val mydata = result.data
// ..
}
}
@victory316
victory316 / DefaultExtensions.kt
Created January 3, 2023 07:14
Useful pre-defined default Kotlin extensions.
/**
* Returns this List if it's not `null` and the empty list otherwise.
* @sample samples.collections.Collections.Lists.listOrEmpty
*/
@kotlin.internal.InlineOnly
public inline fun <T> List<T>?.orEmpty(): List<T> = this ?: emptyList()
@victory316
victory316 / DialogExtensions.kt
Last active January 26, 2023 05:29
MaterialAlertDialog wrapper Extension function
fun Context.buildAlertDialog(
@StringRes title: Int? = null,
@StringRes message: Int? = null,
@StringRes setPositiveButton: Int? = null,
@StringRes setNegativeButton: Int? = null,
onPositiveSelected: (() -> Unit)? = null,
onNegativeSelected: (() -> Unit)? = null
): MaterialAlertDialogBuilder {
@victory316
victory316 / FragmentData.kt
Last active March 24, 2023 02:01
ViewPager2 Adapter to use with Fragments which is dynamically added or removed.
data class FragmentData(val pageId: String)