Skip to content

Instantly share code, notes, and snippets.

View kakai248's full-sized avatar

Ricardo Carrapiço kakai248

View GitHub Profile
inline fun Modifier.conditional(
condition: Boolean,
ifTrue: Modifier.() -> Modifier,
ifFalse: Modifier.() -> Modifier = { this },
): Modifier = if (condition) {
then(ifTrue(this))
} else {
then(ifFalse(this))
}
class UploadFilesUseCase(
private val schedulerProvider: SchedulerProvider,
private val httpManager: HttpManager
) {
private var operation: Completable? = null
fun uploadFiles(): Completable = synchronized(this) {
operation
?: (doUploadFiles()
@MainThread
inline fun <reified VM : ViewModel> ComponentActivity.viewModel(
noinline provider: (SavedStateHandle) -> VM
) = createLazyViewModel(
viewModelClass = VM::class,
savedStateRegistryOwnerProducer = { this },
viewModelStoreOwnerProducer = { this },
viewModelProvider = provider
)
abstract class BaseFragment<VB : ViewBinding>(
private val bindingFactory: (LayoutInflater, ViewGroup?, Boolean) -> VB
) : Fragment() {
private var _binding: VB? = null
val binding: VB
get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
@kakai248
kakai248 / Example.kt
Created February 24, 2020 18:00
Example on how to to inject SavedStateHandle into ViewModel's
// ViewModel factory
@MainThread
inline fun <reified VM : ViewModel> ComponentActivity.viewModel(
noinline provider: (SavedStateHandle) -> VM
) = createLazyViewModel(
viewModelClass = VM::class,
savedStateRegistryOwnerProducer = { this },
viewModelStoreOwnerProducer = { this },
viewModelProvider = provider
const puppeteerLottie = require("puppeteer-lottie");
const fs = require("fs");
const baseInputDir = "lotties/";
const baseOutputDir = "lotties-rendered/";
const outputExtension = '.mp4';
(async () => {
await run();
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
@Module
abstract class FragmentBindingModule {
@Binds
abstract fun bindFragmentFactory(factory: FragmentInjectionFactory): FragmentFactory
@Binds
@IntoMap
@FragmentKey(MainFragment::class)
abstract fun bindMainFragment(fragment: MainFragment): Fragment
@kakai248
kakai248 / Consumer.java
Created March 12, 2018 18:43
SpanBuilder
public interface Consumer<T> {
void accept(T value);
}
package me.mesmo.app.utils.cache;
import com.jakewharton.rxrelay2.PublishRelay;
import com.jakewharton.rxrelay2.Relay;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import io.reactivex.Completable;
import io.reactivex.Observable;