Skip to content

Instantly share code, notes, and snippets.

View brescia123's full-sized avatar

Giacomo Bresciani brescia123

View GitHub Profile
@brescia123
brescia123 / CompositionActivity.kt
Last active May 5, 2017 13:25
Base Activity/Fragment that enables composition within the Activity/Fragment lifecycle
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
abstract class CompositionActivity : AppCompatActivity() {
private val onCreateFeatures = mutableListOf<CompositionActivity.OnCreateFeature>()
private val onStartFeatures = mutableListOf<CompositionActivity.OnStartFeature>()
private val onResumeFeatures = mutableListOf<CompositionActivity.OnResumeFeature>()
@brescia123
brescia123 / AndroidKUtilis.kt
Created April 19, 2017 08:00
Kotlin useful extension functions for Android
@ColorInt fun Context.color(@ColorRes id: Int, theme: Resources.Theme? = getTheme()): Int =
if (Build.VERSION.SDK_INT >= 23)
resources.getColor(id, theme)
else
resources.getColor(id)
@brescia123
brescia123 / kSnackbar.kt
Last active April 26, 2017 16:11
kUtils - Snackbar
fun View.createSnackbar(text: String,
duration: Int = Snackbar.LENGTH_SHORT,
actionLabel: String = "Action",
dismissOnAction: Boolean = true,
action: ((View) -> Unit)? = null): Snackbar {
val snackbar = Snackbar.make(this, text, duration)
action?.let {
snackbar.setAction(actionLabel, {
action(it)
@brescia123
brescia123 / ViewVisibilityExtensions.kt
Last active May 10, 2023 12:28
Useful Android Kotlin Extension functions to easily change the visibility of a View
/** Set the View visibility to VISIBLE and eventually animate the View alpha till 100% */
fun View.visible(animate: Boolean = true) {
if (animate) {
animate().alpha(1f).setDuration(300).setListener(object : AnimatorListenerAdapter() {
override fun onAnimationStart(animation: Animator) {
super.onAnimationStart(animation)
visibility = View.VISIBLE
}
})
} else {