Skip to content

Instantly share code, notes, and snippets.

View alexfacciorusso's full-sized avatar

Alex Facciorusso alexfacciorusso

View GitHub Profile
@alexfacciorusso
alexfacciorusso / FluentBorderStroke.kt
Last active November 1, 2023 13:13
Useful Fluent composables for Compose Desktop
/*
* Copyright © 2023 Alex Facciorusso
*
* Licensed under MIT The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@alexfacciorusso
alexfacciorusso / Main.kt
Last active August 30, 2024 21:53
Start recording Skia frames in SKP files from Kotlin Compose Desktop
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
LaunchedEffect(Unit) {
window.attachSkiaDebugger()
}
MaterialTheme {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.background(Color.LightGray).height(IntrinsicSize.Min)
) {
@alexfacciorusso
alexfacciorusso / AtomicKtx
Created July 1, 2021 09:10
Kotlin delegate for Atomic reference
/**
* Delegates a field to an AtomicReference.
*/
fun <T> atomicReference(): ReadWriteProperty<Any?, T?> = object : ReadWriteProperty<Any?, T?> {
private val atomic = AtomicReference<T>()
override operator fun getValue(thisRef: Any?, property: KProperty<*>): T? = atomic.get()
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
atomic.set(value)
class Cat {
val meow = "Meowww...? :3"
}
fun main(args: Array<String>) {
var aBoringClassInstance: Cat? = Cat()
aBoringClassInstance!!
val sureNull: Cat? = null
sureNull!!
@alexfacciorusso
alexfacciorusso / DaggerViewModelFactory.kt
Last active September 16, 2017 22:04
A Dagger 2 injected ViewModelProvider.Factory implementation.
@Singleton
class DaggerViewModelFactory
@Inject constructor(
private val creators: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val creator = creators[modelClass] ?:
creators.asIterable().firstOrNull { modelClass.isAssignableFrom(it.key) }?.value
?: throw IllegalArgumentException("unknown model class " + modelClass)
@alexfacciorusso
alexfacciorusso / expand-collapse.java
Created June 27, 2016 08:13 — forked from ZkHaider/expand-collapse.java
Simple Expand / Collapse RecyclerView Item
public static class ExampleViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
private int originalHeight = 0;
private boolean isViewExpanded = false;
private YourCustomView yourCustomView
public ExampleViewHolder(View v) {
super(v);
v.setOnClickListener(this);
@alexfacciorusso
alexfacciorusso / KtRetrofit.kt
Last active September 12, 2019 12:05
Retrofit Kotlin extensions
import retrofit.Call
import retrofit.Callback
import retrofit.Response
import retrofit.Retrofit
/**
* @author Alex Facciorusso
* @since 06/11/15
*/
@alexfacciorusso
alexfacciorusso / BindingCompatActivity.java
Created August 11, 2015 14:04
Some utility classes for Data Binding.
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
/**
* @author alexfacciorusso
* @since 11/08/15.
*/
@alexfacciorusso
alexfacciorusso / layout.xml
Created May 31, 2015 21:39
Layout used in project with issue
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
@alexfacciorusso
alexfacciorusso / PostActivity.java
Created May 30, 2015 10:00
AppBarLayout + WebView issue
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">