-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move functions to top level
- Loading branch information
Showing
12 changed files
with
379 additions
and
170 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,37 @@ | ||
[versions] | ||
jackson-module-kotlin = "2.16.1" | ||
jadb = "1.2.1" | ||
kotlin = "2.0.0" | ||
revanced-patcher = "20.0.0-dev.2" | ||
binary-compatibility-validator = "0.15.1" | ||
android = "8.5.1" | ||
bcpkix-jdk15on = "1.70" | ||
binary-compatibility-validator = "0.15.1" | ||
core-ktx = "1.13.1" | ||
guava = "33.0.0-jre" | ||
jackson-module-kotlin = "2.16.1" | ||
jadb = "1.2.1" | ||
kotlin = "2.0.0" | ||
kotlinx-coroutines = "1.8.1" | ||
kotlinx-serialization = "1.7.1" | ||
libsu = "5.2.2" | ||
core-ktx = "1.13.1" | ||
revanced-patcher = "20.0.0-dev.2" | ||
|
||
[libraries] | ||
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" } | ||
jadb = { module = "app.revanced:jadb", version.ref = "jadb" } | ||
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } | ||
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } | ||
revanced-patcher = { module = "app.revanced:revanced-patcher", version.ref = "revanced-patcher" } | ||
apkzlib = { module = "com.android.tools.build:apkzlib", version.ref = "android" } | ||
apksig = { module = "com.android.tools.build:apksig", version.ref = "android" } | ||
bcpkix-jdk15on = { module = "org.bouncycastle:bcpkix-jdk15on", version.ref = "bcpkix-jdk15on" } | ||
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" } | ||
guava = { module = "com.google.guava:guava", version.ref = "guava" } | ||
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" } | ||
jadb = { module = "app.revanced:jadb", version.ref = "jadb" } # Fork with Shell v2 support. | ||
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } | ||
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } | ||
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } | ||
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } | ||
libsu-core = { module = "com.github.topjohnwu.libsu:core", version.ref = "libsu" } | ||
libsu-nio = { module = "com.github.topjohnwu.libsu:nio", version.ref = "libsu" } | ||
libsu-service = { module = "com.github.topjohnwu.libsu:service", version.ref = "libsu" } | ||
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" } | ||
revanced-patcher = { module = "app.revanced:revanced-patcher", version.ref = "revanced-patcher" } | ||
|
||
[plugins] | ||
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" } | ||
android-library = { id = "com.android.library", version.ref = "android" } | ||
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" } | ||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } | ||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } | ||
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package app.revanced.library | ||
|
||
import app.revanced.patcher.patch.Package | ||
import app.revanced.patcher.patch.Patch | ||
|
||
typealias PackageName = String | ||
typealias Version = String | ||
typealias Count = Int | ||
|
||
typealias VersionMap = LinkedHashMap<Version, Count> | ||
typealias PackageNameMap = Map<PackageName, VersionMap> | ||
|
||
/** | ||
* Get the count of versions for each compatible package from the set of [Patch] ordered by the most common version. | ||
* | ||
* @param packageNames The names of the compatible packages to include. If null, all packages will be included. | ||
* @param countUnusedPatches Whether to count patches that are not used. | ||
* @return A map of package names to a map of versions to their count. | ||
*/ | ||
fun Set<Patch<*>>.mostCommonCompatibleVersions( | ||
packageNames: Set<String>? = null, | ||
countUnusedPatches: Boolean = false, | ||
): PackageNameMap = buildMap { | ||
fun filterWantedPackages(compatiblePackages: List<Package>): List<Package> { | ||
val wantedPackages = packageNames?.toHashSet() ?: return compatiblePackages | ||
return compatiblePackages.filter { (name, _) -> name in wantedPackages } | ||
} | ||
|
||
this@mostCommonCompatibleVersions.filter { it.use || countUnusedPatches } | ||
.flatMap { it.compatiblePackages ?: emptyList() } | ||
.let(::filterWantedPackages) | ||
.forEach { (name, versions) -> | ||
if (versions?.isEmpty() == true) { | ||
return@forEach | ||
} | ||
|
||
val versionMap = getOrPut(name) { linkedMapOf() } | ||
|
||
versions?.forEach { version -> | ||
versionMap[version] = versionMap.getOrDefault(version, 0) + 1 | ||
} | ||
} | ||
|
||
// Sort the version maps by the most common version. | ||
forEach { (packageName, versionMap) -> | ||
this[packageName] = | ||
versionMap | ||
.asIterable() | ||
.sortedWith(compareByDescending { it.value }) | ||
.associate { it.key to it.value } as VersionMap | ||
} | ||
} |
This file contains 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
Oops, something went wrong.