add clear adFile

pull/28/head
fengyuecanzhu 3 years ago
parent 58e5b5470f
commit 97d7dab086
No known key found for this signature in database
GPG Key ID: 04B78AD06A9D6E6C
  1. 1
      .idea/misc.xml
  2. 44
      dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt
  3. 106
      dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix.kt

@ -3,6 +3,7 @@
<component name="DesignSurface"> <component name="DesignSurface">
<option name="filePathToZoomLevelMap"> <option name="filePathToZoomLevelMap">
<map> <map>
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_ad_setting.xml" value="0.12132725430597771" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_donate.xml" value="0.264" /> <entry key="..\:/android/FYReader/app/src/main/res/layout/activity_donate.xml" value="0.264" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_more_setting.xml" value="0.2" /> <entry key="..\:/android/FYReader/app/src/main/res/layout/activity_more_setting.xml" value="0.2" />
<entry key="..\:/android/FYReader/app/src/main/res/layout/activity_read.xml" value="0.12132725430597771" /> <entry key="..\:/android/FYReader/app/src/main/res/layout/activity_read.xml" value="0.12132725430597771" />

@ -45,29 +45,21 @@ class AppLoadImpl : IAppLoader {
App243Fix::class.java, App243Fix::class.java,
App244Fix::class.java, App244Fix::class.java,
App244Fix2::class.java, App244Fix2::class.java,
App245Fix::class.java, App246Fix::class.java,
) )
override fun onLoad(appParam: AppParam) { override fun onLoad(appParam: AppParam) {
val sb = StringBuilder() val sb = StringBuilder()
fixList.forEach { fixList.forEach {
val annotation = it.getAnnotation(AppFix::class.java)!! val annotation = it.getAnnotation(AppFix::class.java)!!
for (version in annotation.versions) { if (annotation.versions.isEmpty()) {
if (App.getVersionCode() == version) { fix(sb, annotation, it)
val fix = it.newInstance() } else {
val fixResult = fix.onFix(annotation.date) for (version in annotation.versions) {
if (!spu.getBoolean(annotation.date, false)) { if (App.getVersionCode() == version) {
if (sb.isNotEmpty()) sb.append("\n") fix(sb, annotation, it)
sb.append("${annotation.date}\n") break
fixResult.forEachIndexed { i, b ->
sb.append("${i + 1}${annotation.fixLog[i]}${if (b) "成功" else "失败"}\n")
}
spu.edit().run {
putBoolean(annotation.date, true)
apply()
}
} }
break
} }
} }
} }
@ -85,6 +77,26 @@ class AppLoadImpl : IAppLoader {
} }
} }
private fun fix(
sb: StringBuilder,
annotation: AppFix,
fixClz: Class<out AppFixHandle>
) {
val fix = fixClz.newInstance()
val fixResult = fix.onFix(annotation.date)
if (!spu.getBoolean(annotation.date, false)) {
if (sb.isNotEmpty()) sb.append("\n")
sb.append("${annotation.date}\n")
fixResult.forEachIndexed { i, b ->
sb.append("${i + 1}${annotation.fixLog[i]}${if (b) "成功" else "失败"}\n")
}
spu.edit().run {
putBoolean(annotation.date, true)
apply()
}
}
}
private fun announce(title: String, msg: String) { private fun announce(title: String, msg: String) {
try { try {
MapleUtils.findAndHookMethod( MapleUtils.findAndHookMethod(

@ -0,0 +1,106 @@
/*
* This file is part of FYReader.
* FYReader is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FYReader is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FYReader. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright (C) 2020 - 2022 fengyuecanzhu
*/
package xyz.fycz.dynamic.fix
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.ScrollView
import android.widget.TextView
import androidx.core.view.get
import androidx.viewbinding.ViewBinding
import me.fycz.maple.MapleBridge
import me.fycz.maple.MapleUtils
import me.fycz.maple.MethodHook
import xyz.fycz.myreader.R
import xyz.fycz.myreader.base.adapter2.onClick
import xyz.fycz.myreader.ui.activity.MoreSettingActivity
import xyz.fycz.myreader.util.ToastUtils
import xyz.fycz.myreader.util.utils.FileUtils
import xyz.fycz.myreader.util.utils.ScreenUtils
/**
* @author fengyue
* @date 2022/6/3 15:34
*/
@AppFix([], ["设置-缓存设置新增清除广告文件"], "2022-06-03")
class App246Fix : AppFixHandle {
override fun onFix(key: String): BooleanArray {
val result = try {
fxAdFile()
true
} catch (e: Exception) {
MapleUtils.log(e)
false
}
fixResult(key, "adFile", result)
return booleanArrayOf(result)
}
fun fxAdFile() {
MapleUtils.findAndHookMethod(
MoreSettingActivity::class.java,
"initWidget",
object : MethodHook() {
override fun afterHookedMethod(param: MapleBridge.MethodHookParam) {
val binding =
MapleUtils.getObjectField(param.thisObject, "binding") as ViewBinding
val rootLayout =
binding.root.findViewById<ScrollView>(R.id.sv_content)[0] as ViewGroup
addDeleteAdFileView(rootLayout, rootLayout.childCount)
}
}
)
}
fun addDeleteAdFileView(rootLayout: ViewGroup, index: Int) {
val context = rootLayout.context
val resources = context.resources
val rlDeleteAdFile = RelativeLayout(context)
val layoutParams = RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ScreenUtils.dpToPx(50)
)
rlDeleteAdFile.setPadding(
ScreenUtils.dpToPx(20),
0,
ScreenUtils.dpToPx(20),
0
)
rlDeleteAdFile.background = resources.getDrawable(R.drawable.selector_common_bg)
rlDeleteAdFile.id = R.id.rl_delete_ad_file
val textview = TextView(context)
val textViewParams = RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
addRule(RelativeLayout.CENTER_VERTICAL)
}
textview.setText(R.string.delete_ad_file)
textview.setTextColor(resources.getColor(R.color.textSecondary))
textview.textSize =
ScreenUtils.pxToSp(resources.getDimension(R.dimen.text_normal_size).toInt()).toFloat()
rlDeleteAdFile.addView(textview, textViewParams)
rlDeleteAdFile.onClick {
FileUtils.deleteFile(FileUtils.getFilePath())
ToastUtils.showSuccess("广告文件删除成功")
}
rootLayout.addView(rlDeleteAdFile, index, layoutParams)
}
}
Loading…
Cancel
Save