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()
public class ViewModelInjectionFactory<VM extends ViewModel> implements ViewModelProvider.Factory {
private Lazy<VM> viewModel;
@Inject
public ViewModelInjectionFactory(Lazy<VM> viewModel) {
this.viewModel = viewModel;
}
@Override
@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
@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,
public class ResourceProvider {
private final Context context;
@Inject
public ResourceProvider(Context context) {
this.context = context;
}
@NonNull
@Module
abstract class FragmentBindingModule {
@Binds
abstract fun bindFragmentFactory(factory: FragmentInjectionFactory): FragmentFactory
@Binds
@IntoMap
@FragmentKey(MainFragment::class)
abstract fun bindMainFragment(fragment: MainFragment): Fragment
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