forked from leonlatsch/Photok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
150 lines (130 loc) · 5.18 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import java.util.*
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
val kotlinVersion = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5")
classpath("com.google.dagger:hilt-android-gradle-plugin:2.28-alpha")
classpath("com.jaredsburrows:gradle-license-plugin:0.8.90")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven("https://jitpack.io")
}
}
tasks.register("updateVersion") {
val version: String? by project
version ?: throw GradleException("Not version provided")
val file = file("gradle.properties")
if (file.canRead()) {
val properties = Properties().apply {
load(file.inputStream())
}
val oldVersionCode: String = properties["photokVersionCode"] as String
val newVersionCode: String = oldVersionCode.toInt().inc().toString()
properties["photokVersionName"] = version!!
properties["photokVersionCode"] = newVersionCode
properties.store(file.writer(), null)
} else {
throw GradleException("${file.name} not readable")
}
}
tasks.register("updateTranslations") {
val resPath = "app/src/main/res"
val bytes = java.io.FileInputStream(File("$resPath/values/strings.xml")).readBytes()
val enLines = String(bytes).split("\n")
var enStrings = 0
for (line in enLines) {
if (line.contains("<string")) {
enStrings++
}
}
val badges = arrayListOf<String>()
File(resPath).walk().forEach { dir ->
if (dir.isDirectory &&
dir.name.contains("values") &&
dir.name != "values"
) {
dir.walk().forEach { stringsFile ->
if (stringsFile.name == "strings.xml") {
var strings = 0
var author = "UNKNOWN"
val lines = String(java.io.FileInputStream(stringsFile).readBytes()).split("\n")
for (line in lines) {
if (line.contains("<string") && !line.contains("TODO")) {
strings++
} else if (line.contains("MAINTAINED BY")) {
author = line.substring(line.indexOf("(") + 1, line.indexOf(")"))
}
}
val localeName = dir.name.replace("values-", "")
val percentage = (strings.toDouble() / enStrings.toDouble()) * 100
val template =
"![{alt-locale}](https://img.shields.io/badge/{locale}-{percentage}{color})\nMaintained by {author}\n\n"
val color = when {
percentage > 99 -> "25-brightgreen"
percentage > 75 -> "25-yellow"
percentage > 50 -> "25-orange"
percentage > 0 -> "25-red"
else -> "lightgrey"
}
val localeDisplay = Locale.forLanguageTag(localeName.replace("-r", "-"))
.getDisplayName(Locale.US)
val badge = template
.replace("{locale}", localeDisplay.replace(" ", "%20"))
.replace("{alt-locale}", localeDisplay)
.replace("{percentage}", "${percentage.toInt()}%")
.replace("{color}", color)
.replace("{author}", author)
badges.add(badge)
}
}
}
} // READ strings.xml
if (badges.isNotEmpty()) {
badges.sort()
val readmeString = String(java.io.FileInputStream(File("README.md")).readBytes())
val readmeLines = readmeString.split("\n")
var beginIndex = 0
var endIndex = 0
var i = 0
while (i < readmeLines.size) {
if (readmeLines[i].contains("BEGIN-TRANSLATIONS")) {
beginIndex = i + 1
}
if (readmeLines[i].contains("END-TRANSLATIONS")) {
endIndex = i
}
i++
}
val prefixStrings = readmeLines.subList(0, beginIndex)
val suffixStrings = readmeLines.subList(endIndex, readmeLines.size - 1)
var badgeString = ""
badgeString += "![English](https://img.shields.io/badge/English-100%25-brightgreen)\nMaintained by @leonlatsch\n\n" // Hard code add english
badges.forEach {
badgeString += it
}
var newReadmeString = ""
prefixStrings.forEach {
newReadmeString += "$it\n"
}
newReadmeString += badgeString
suffixStrings.forEach {
newReadmeString += "$it\n"
}
if (newReadmeString.isNotEmpty()) {
File("README.md").writeText(newReadmeString)
}
}
}