Skip to content

Instantly share code, notes, and snippets.

View realdadfish's full-sized avatar

Thomas Keller realdadfish

View GitHub Profile
@realdadfish
realdadfish / LicenseReportPlugin.kt
Created January 28, 2021 15:35
Leveraging Gradle's ArtifactView
package some.package
import nl.javadude.gradle.plugins.license.DownloadLicensesExtension
import nl.javadude.gradle.plugins.license.DownloadLicensesReportExtension
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.attributes.Attribute
import org.gradle.api.attributes.AttributeCompatibilityRule
@realdadfish
realdadfish / ProgressIterator.kt
Created November 11, 2021 11:58
A trial to mimic "Type-driven design in Rust" (https://www.youtube.com/watch?v=bnnacleqg6k) with Kotlin
@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS")
interface ExactSizeIterator<T> : Iterator<T> {
val length: UInt
}
fun <T> Collection<T>.exactSizeIterator() = object : ExactSizeIterator<T> {
private val inner = iterator()
override val length: UInt = size.toUInt()
override fun hasNext(): Boolean = inner.hasNext()
class HiltFragmentScenario<F : Fragment> private constructor(
private val fragmentClass: Class<F>,
val activityScenario: ActivityScenario<TestHiltActivity>
) {
@Suppress("UNCHECKED_CAST")
val fragment: F?
get() = activityScenario.getActivity()?.supportFragmentManager?.findFragmentByTag(FRAGMENT_TAG) as? F?
/**
* Moves Fragment state to a new state.
@realdadfish
realdadfish / AndroidManifest.xml
Last active September 14, 2022 08:25
Enable / disable buttons in list
...
<application>
<activity
android:name="androidx.activity.ComponentActivity"
android:exported="false"/>
</application>
...
@realdadfish
realdadfish / ScopeCancel.kt
Created February 7, 2023 11:53
Why does my shared flow subscription not complete after the scope it's shared in is canceled?
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.shareIn