Skip to content

Instantly share code, notes, and snippets.

View arunkumar9t2's full-sized avatar

Arunkumar arunkumar9t2

View GitHub Profile
@arunkumar9t2
arunkumar9t2 / DependantModulesTask.kt
Last active July 21, 2023 15:43
Gradle task to find reverse dependencies of a module
import com.google.common.graph.Graphs
import com.google.common.graph.MutableValueGraph
import com.google.common.graph.ValueGraphBuilder
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
@arunkumar9t2
arunkumar9t2 / gradle-dependency-graph.gradle
Created March 21, 2021 15:09
Gradle task to generate project dependency graph as json
tasks.register("dependencyGraph") {
description = "Generate dependency graph json"
doLast {
def dependencyGraph = subprojects
.collect { project ->
[
"project" : project.path,
"dependencies": project.configurations
.collectMany { config ->
config
@arunkumar9t2
arunkumar9t2 / collect-classes.gradle
Created August 10, 2020 04:26
Prints all classes in an android/kotlin/java project.
tasks.register("collectClasses") {
subprojects {
dependsOn tasks.withType(JavaCompile)
dependsOn tasks.withType(KotlinJvmCompile)
}
doLast {
subprojects {
(tasks.withType(JavaCompile) + tasks.withType(KotlinJvmCompile)).forEach { compile ->
compile.destinationDirectory
.getAsFileTree()
@arunkumar9t2
arunkumar9t2 / disable-test-without-source.gradle
Last active May 29, 2022 04:44
Gradle script that disables all test tasks if it has no test sources.
subprojects {
afterEvaluate {
def hasKotlinAndroidSourceSet = extensions.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension)
?.sourceSets?.findByName("test")?.kotlin?.files?.size() != 0
def hasKotlinSourceSet = extensions.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension)
?.sourceSets?.findByName("test")?.kotlin?.files?.size() != 0
if (!hasKotlinAndroidSourceSet && !hasKotlinSourceSet) {
tasks.configureEach {
if (name.contains("Test")) {
@arunkumar9t2
arunkumar9t2 / Gradle block IDE builds.groovy
Created February 27, 2020 14:06
A gradle task that blocks Android builds started from IDE and copies the command to clipboard to quickly start build from terminal. Works only on Max
def validateIdeBuilds = tasks.register("validateIdeBuilds") {
doLast {
if (project.hasProperty("android.injected.invoked.from.ide")) {
def buildCommand = "./gradlew " + gradle.startParameter.taskNames.join(" ")
exec {
commandLine("sh", "-c", "echo \"$buildCommand\" | pbcopy")
}
throw new RuntimeException(
"Please avoid building from IDE and use commandLine instead." +
"The command has been copied to your clipboard"
val AppCompatActivity.hasSourceBounds: Boolean get() = intent?.sourceBounds != null
fun AppCompatActivity.sourceBounds(boundsAction: (Rect) -> Unit) {
intent?.sourceBounds?.let(boundsAction)
}
/**
* Disables upcoming transition when [hasSourceBounds] is true. Should be called before [AppCompatActivity.onCreate]
*/
fun AppCompatActivity.preAnimationSetup() {
@arunkumar9t2
arunkumar9t2 / PreferencesX.kt
Last active September 6, 2023 15:20
Android PreferenceScreen DSL for using with androidx.preference framework.
@file:Suppress("NOTHING_TO_INLINE")
import android.content.Context
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import androidx.preference.*
/**
* DSL marker for restricting access scope when [PreferencesBuilder.preference] is nested.
*/
rootLayout.prepareTransition {
moveResize {
+image1 // Using + operator to add targets
}
fade {
+text
}
}
text.isGone = true // Layout changes
constraintLayout.prepareTransition {
customTransition<ChangeCardColor> {
+colorChangeCardView
}
}
rootCoordinatorLayout.prepareTransition {
onStart {
// Started!
}
moveResize {
+image1
}
onEnd {
// I am done :)
}