Skip to content

Instantly share code, notes, and snippets.

View marcellogalhardo's full-sized avatar
🇧🇷
Gradle is building...

Marcello Galhardo marcellogalhardo

🇧🇷
Gradle is building...
View GitHub Profile
#!/bin/bash
# Originally written by Ralf Kistner <[email protected]>, but placed in the public domain
set +e
bootanim=""
failcounter=0
timeout_in_sec=360
@marcellogalhardo
marcellogalhardo / Lce.kt
Last active December 20, 2018 10:46
The [Lce] interface and its subclasses are a form of container to help handling with loading, data fetch, and error handling on Streams. This class was designed as an Immutable object that contains the data and status of each Stream operation.
/**
* The [Lce] interface and its subclasses are a form of container
* to help handling with loading, data fetch, and error handling
* on Streams. This class was designed as an Immutable object that contains
* the data and status of each Stream operation.
*/
interface Lce<T> {
fun getData(): T?

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@marcellogalhardo
marcellogalhardo / ActivityScope.kt
Last active January 20, 2021 10:11
Scoping Dagger Components with ViewModels
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ActivityScope
@marcellogalhardo
marcellogalhardo / Coordinator.kt
Last active April 29, 2020 19:10
Coordinator base class.
package com.marcellogalhardo.coordinator
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentFactory
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.AbstractSavedStateViewModelFactory
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.HasDefaultViewModelProviderFactory
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.SavedStateHandle
interface SavedStateViewModelFactory {
fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T
}
private fun SavedStateViewModelFactory.asViewModelProviderFactory(
owner: SavedStateRegistryOwner
): ViewModelProvider.Factory {
return object : AbstractSavedStateViewModelFactory(owner, owner.arguments) {
override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T {
return [email protected](key, modelClass, handle)
package com.marcellogalhardo.AutoClearedValue
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.observe
import kotlin.properties.ReadOnlyProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
package com.marcellogalhardo.weak
import java.lang.ref.WeakReference
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
* Creates a new instance of the [WeakDelegate] for better Kotlin
* syntax using the [referent] parameter as an initial reference.
*
package com.marcellogalhardo.viewmodel.factory
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import javax.inject.Inject
import javax.inject.Provider
/**
* A [ViewModelProvider.Factory] that can hold a ViewModel [producer] function
@marcellogalhardo
marcellogalhardo / LifecycleCollect.kt
Last active June 3, 2021 08:46
Utility functions to collect coroutines Flow respecting Android's Lifecycle.
package dev.marcellogalhardo.lifecycle
import android.app.Activity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow