This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tonal.trainer.anvilcompilers | |
import com.google.auto.service.AutoService | |
import com.squareup.anvil.annotations.ContributesTo | |
import com.squareup.anvil.compiler.api.AnvilContext | |
import com.squareup.anvil.compiler.api.CodeGenerator | |
import com.squareup.anvil.compiler.api.GeneratedFile | |
import com.squareup.anvil.compiler.api.createGeneratedFile | |
import com.squareup.anvil.compiler.internal.asClassName | |
import com.squareup.anvil.compiler.internal.buildFile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun ImageVector.colorPath(pathName: String, color: Color): ImageVector { | |
val path = root.findPath(pathName) | |
val f = VectorPath::class.java.getDeclaredField("fill") | |
f.isAccessible = true | |
f.set(path, SolidColor(color)) | |
return this | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.contracts.ExperimentalContracts | |
import kotlin.contracts.contract | |
@OptIn(ExperimentalContracts::class) | |
internal inline fun <T> List<T>.fastForEach(action: (T) -> Unit) { | |
contract { callsInPlace(action) } | |
for (index in indices) { | |
val item = get(index) | |
action(item) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.* | |
import androidx.compose.foundation.shape.CircleShape | |
import androidx.compose.foundation.shape.RoundedCornerShape | |
import androidx.compose.material.Card | |
import androidx.compose.material.MaterialTheme | |
import androidx.compose.material.Surface |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.SideEffect | |
import androidx.compose.runtime.remember | |
class Ref(var value: Int) | |
@Composable | |
inline fun LogRecompositions(composableTag: String) { | |
val ref = remember { Ref(0) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// conversions based on https://material.io/blog/migrating-material-3, deprecated colors set to Colors.Red | |
@Composable | |
fun fromMaterial3Theme(isLight: Boolean): Colors { | |
val scheme = MaterialTheme.colorScheme | |
return Colors( | |
primary = scheme.primary, | |
primaryVariant = Color.Red, | |
secondary = scheme.secondary, | |
secondaryVariant = Color.Red, | |
background = scheme.background, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ffmpeg ... -vf "scale=w=min(iw\,1280):h=-2" ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <Param> View.debounce(debounceMillis: Long = 300, block: (Param) -> Unit): (Param) -> Unit { | |
val handler = handler | |
var runnable: Runnable? = null | |
androidx.core.view.doOnDetach { runnable?.let(handler::removeCallbacks) } | |
return { | |
runnable?.let(handler::removeCallbacks) | |
val newRunnable = Runnable { block(it) } | |
handler.postDelayed(newRunnable, debounceMillis) | |
runnable = newRunnable | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified VB: ViewBinding> viewBinding(crossinline f: VB.() -> Unit) = { activity: Activity -> | |
val vbclass = VB::class.java | |
val inflate = vbclass.getMethod("inflate", LayoutInflater::class.java) | |
val binding = inflate.invoke(null, activity.layoutInflater) as VB | |
f(binding) | |
activity.setContentView(binding.root) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `validate file content for FooSummable`() { | |
val kotlinSource = SourceFile.kotlin( | |
"file2.kt", """ | |
package com.tests.summable | |
import com.codegen.sample.IntSummable | |
@IntSummable | |
data class FooAlsoSummable( |