Commit c83e3457 authored by pengjunjing's avatar pengjunjing

feat:完善删除未使用资源的判断逻辑

parent 1d7e30ba
......@@ -12,7 +12,30 @@ class ParseUtil {
//引用的代码,xml引用,java kt代码引用,布局文件
private val refCode =
listOf<String>("@drawable", "@mipmap", "R.drawable", "R.mipmap", "R.raw", "R.layout", "@layout", "@color","R.anim","@anim")
listOf<String>("@drawable",
"@mipmap",
"R.drawable",
"R.mipmap",
"R.raw",
"R.layout",
"@layout",
"@color",
"R.anim",
"@anim")
//代码引用方式
private val refCallCode: List<String> = refCode.map {
if (it.contains("@")) {
//"@mipmap/"
"$it/"
} else if (it.contains("R.")) {
//"R.drawable."
"$it."
} else {
//原文不变
it
}
}
/**
* 返回引用了图片资源的该行文本内容
......@@ -37,6 +60,7 @@ class ParseUtil {
* 开始解析未使用的资源文件
*/
fun startParseUnused(readImageRes: List<File>, readCodeFile: List<File>): MutableSet<File> {
//列表内容为文件名去后缀的字符串
val fileNames = Array<String>(readImageRes.size) {
//文件名 ,带后缀,去除后缀
val name = readImageRes[it].name
......@@ -58,11 +82,15 @@ class ParseUtil {
//有包含资源的代码行
outFor@ for (i in fileNames.indices) {
inFor@ for (parseFileLine: String in parseFileLines) {
if (parseFileLine.contains(fileNames[i])) {
//有在使用该资源
use.add(fileNames[i])
useSet.add(readImageRes[i])
continue@inFor
for (s in refCallCode) {
//拼接成 @mipmap/xxx R.layout.xxx 的形式
val s1 = s + fileNames[i]
if (parseFileLine.contains(s1)) {
//有在使用该资源
use.add(fileNames[i])
useSet.add(readImageRes[i])
continue@inFor
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment