Skip to content

Commit 84dfe88

Browse files
committed
Refactor: Copy resources from ReVanced Patches
Instead of manually copying resources, this change introduces a new Gradle task, `CopyResourcesTask`. This task automatically copies necessary drawable resources from the `revanced-patches` submodule into the appropriate `res/drawable` directory during the build process. This change also removes the no longer needed drawables.
1 parent fe1e678 commit 84dfe88

39 files changed

+39
-888
lines changed

app/build.gradle.kts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import groovy.xml.MarkupBuilder
22
import groovy.xml.XmlSlurper
33
import groovy.xml.slurpersupport.NodeChild
4+
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
45
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
56
import java.util.Properties
67
import kotlin.apply
@@ -17,7 +18,9 @@ android {
1718
applicationId = "io.github.chsbuffer.revancedxposed"
1819
versionCode = 23
1920
versionName = "1.0.$versionCode"
20-
val patchVersion = "5.31.2"
21+
val patchVersion = Properties().apply {
22+
File("revanced-patches/gradle.properties").inputStream().use { load(it) }
23+
}["version"]
2124
buildConfigField("String", "PATCH_VERSION", "\"$patchVersion\"")
2225
}
2326
flavorDimensions += "abi"
@@ -170,13 +173,46 @@ abstract class GenerateStringsTask @Inject constructor(
170173
}
171174
}
172175

176+
abstract class CopyResourcesTask @Inject constructor() : DefaultTask() {
177+
@get:InputDirectory
178+
@get:PathSensitive(PathSensitivity.RELATIVE)
179+
abstract val inputDirectory: DirectoryProperty
180+
181+
@get:OutputDirectory
182+
abstract val outputDirectory: DirectoryProperty
183+
184+
@TaskAction
185+
fun action() {
186+
val baseDir = inputDirectory.get().asFile
187+
val outputDir = outputDirectory.get().asFile
188+
189+
val drawables = listOf(
190+
"settings/drawable",
191+
"sponsorblock/drawable",
192+
"swipecontrols/drawable"
193+
)
194+
195+
for (drawable in drawables) {
196+
File(baseDir, drawable).copyRecursively(File(outputDir, "drawable"), overwrite = true)
197+
}
198+
}
199+
}
200+
173201
androidComponents {
174202
onVariants { variant ->
175-
val task = project.tasks.register<GenerateStringsTask>("generate${variant.name}Strings") {
203+
val variantName = variant.name.uppercaseFirstChar()
204+
val strTask = project.tasks.register<GenerateStringsTask>("generateStrings$variantName") {
176205
inputDirectory.set(project.file("../revanced-patches/patches/src/main/resources/addresources"))
177206
}
178207
variant.sources.res?.addGeneratedSourceDirectory(
179-
task, GenerateStringsTask::outputDirectory
208+
strTask, GenerateStringsTask::outputDirectory
209+
)
210+
211+
val resTask = project.tasks.register<CopyResourcesTask>("copyResources$variantName") {
212+
inputDirectory.set(project.file("../revanced-patches/patches/src/main/resources"))
213+
}
214+
variant.sources.res?.addGeneratedSourceDirectory(
215+
resTask, CopyResourcesTask::outputDirectory
180216
)
181217
}
182218
}

app/src/main/res/drawable/revanced_ic_dialog_alert.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_brightness_auto.xml

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_brightness_full.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_brightness_high.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_brightness_low.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_brightness_medium.xml

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_volume_high.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_volume_low.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/src/main/res/drawable/revanced_ic_sc_volume_mute.xml

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)