Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RemoveUnusedImg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengjunjing
RemoveUnusedImg
Commits
c83e3457
Commit
c83e3457
authored
Mar 10, 2022
by
pengjunjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:完善删除未使用资源的判断逻辑
parent
1d7e30ba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
6 deletions
+34
-6
ParseUtil.kt
src/main/java/com/laihua/projecthelper/unuse/ParseUtil.kt
+34
-6
No files found.
src/main/java/com/laihua/projecthelper/unuse/ParseUtil.kt
View file @
c83e3457
...
...
@@ -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,7 +82,10 @@ class ParseUtil {
//有包含资源的代码行
outFor
@
for
(
i
in
fileNames
.
indices
)
{
inFor
@
for
(
parseFileLine
:
String
in
parseFileLines
)
{
if
(
parseFileLine
.
contains
(
fileNames
[
i
]))
{
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
])
...
...
@@ -66,6 +93,7 @@ class ParseUtil {
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment