Skip to content

Commit 914e449

Browse files
committed
refactor: migrate and update to YukiHookAPI 1.3.0
1 parent 1b44e23 commit 914e449

File tree

10 files changed

+271
-222
lines changed

10 files changed

+271
-222
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ dependencies {
8181
compileOnly(de.robv.android.xposed.api)
8282
implementation(com.highcapable.yukihookapi.api)
8383
ksp(com.highcapable.yukihookapi.ksp.xposed)
84+
implementation(com.highcapable.kavaref.kavaref.core)
85+
implementation(com.highcapable.kavaref.kavaref.extension)
8486
implementation(com.fankes.projectpromote.project.promote)
8587
implementation(com.github.topjohnwu.libsu.core)
8688
implementation(com.github.duanhong169.drawabletoolbox)

app/src/main/java/com/fankes/miui/notify/hook/entity/SystemUIHooker.kt

Lines changed: 209 additions & 205 deletions
Large diffs are not rendered by default.

app/src/main/java/com/fankes/miui/notify/ui/activity/base/BaseActivity.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@
2020
*
2121
* This file is created by fankes on 2022/1/30.
2222
*/
23-
@file:Suppress("DEPRECATION")
24-
2523
package com.fankes.miui.notify.ui.activity.base
2624

2725
import android.os.Build
2826
import android.os.Bundle
27+
import android.view.LayoutInflater
2928
import androidx.appcompat.app.AppCompatActivity
3029
import androidx.core.content.res.ResourcesCompat
3130
import androidx.core.view.WindowCompat
3231
import androidx.viewbinding.ViewBinding
3332
import com.fankes.miui.notify.R
3433
import com.fankes.miui.notify.utils.factory.isNotSystemInDarkMode
35-
import com.highcapable.yukihookapi.hook.factory.current
36-
import com.highcapable.yukihookapi.hook.factory.method
37-
import com.highcapable.yukihookapi.hook.type.android.LayoutInflaterClass
34+
import com.highcapable.kavaref.KavaRef.Companion.resolve
35+
import com.highcapable.kavaref.extension.genericSuperclassTypeArguments
36+
import com.highcapable.kavaref.extension.toClassOrNull
3837

3938
abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
4039

@@ -50,10 +49,11 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
5049
override fun onCreate(savedInstanceState: Bundle?) {
5150
super.onCreate(savedInstanceState)
5251
isMainThreadRunning = true
53-
binding = current().generic()?.argument()?.method {
52+
val bindingClass = javaClass.genericSuperclassTypeArguments().firstOrNull()?.toClassOrNull()
53+
binding = bindingClass?.resolve()?.optional()?.firstMethodOrNull {
5454
name = "inflate"
55-
param(LayoutInflaterClass)
56-
}?.get()?.invoke<VB>(layoutInflater) ?: error("binding failed")
55+
parameters(LayoutInflater::class)
56+
}?.invoke<VB>(layoutInflater) ?: error("binding failed")
5757
if (Build.VERSION.SDK_INT >= 35) binding.root.fitsSystemWindows = true
5858
setContentView(binding.root)
5959
/** 隐藏系统的标题栏 */
@@ -63,6 +63,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
6363
isAppearanceLightStatusBars = isNotSystemInDarkMode
6464
isAppearanceLightNavigationBars = isNotSystemInDarkMode
6565
}
66+
@Suppress("DEPRECATION")
6667
ResourcesCompat.getColor(resources, R.color.colorThemeBackground, null).also {
6768
window?.statusBarColor = it
6869
window?.navigationBarColor = it

app/src/main/java/com/fankes/miui/notify/utils/factory/BaseAdapterFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class BaseAdapterCreater(val context: Context) {
6464
* 绑定 [BaseAdapter] 到 [ListView]
6565
* @param bindViews 回调 - ([VB] 每项,[Int] 下标)
6666
*/
67+
@Suppress("DEPRECATION")
6768
inline fun <reified VB : ViewBinding> onBindViews(crossinline bindViews: (binding: VB, position: Int) -> Unit) {
6869
baseAdapter = object : BaseAdapter() {
6970
override fun getCount() = listDataCallback?.let { it() }?.size ?: 0

app/src/main/java/com/fankes/miui/notify/utils/factory/DialogBuilderFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ inline fun Context.showDialog(initiate: DialogBuilder<*>.() -> Unit) = DialogBui
6868
* @param context 实例
6969
* @param bindingClass [ViewBinding] 的 [Class] 实例 or null
7070
*/
71+
@Suppress("DEPRECATION")
7172
class DialogBuilder<VB : ViewBinding>(val context: Context, private val bindingClass: Class<*>? = null) {
7273

7374
/** 实例对象 */

app/src/main/java/com/fankes/miui/notify/utils/factory/FunctionFactory.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ import androidx.core.app.NotificationManagerCompat
6363
import androidx.core.content.getSystemService
6464
import androidx.core.content.pm.PackageInfoCompat
6565
import androidx.core.content.res.ResourcesCompat
66+
import androidx.core.graphics.createBitmap
67+
import androidx.core.net.toUri
6668
import com.fankes.miui.notify.wrapper.BuildConfigWrapper
6769
import com.google.android.material.snackbar.Snackbar
6870
import com.highcapable.yukihookapi.hook.factory.hasClass
@@ -148,6 +150,7 @@ val isNotMiSystem get() = !isMiSystem
148150
* 当前设备是否是 MIUI 定制 Android 系统
149151
* @return [Boolean] 是否符合条件
150152
*/
153+
@Suppress("DEPRECATION")
151154
val isMIUI by lazy { "android.miui.R".hasClass() }
152155

153156
/**
@@ -541,7 +544,7 @@ val String.bitmap: Bitmap get() = unbase64.bitmap
541544
* @return [Bitmap] 圆角后的位图 - 失败会返回处理之前的位图
542545
*/
543546
fun Bitmap.round(radius: Float): Bitmap = safeOf(default = this) {
544-
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).also { out ->
547+
createBitmap(width, height).also { out ->
545548
Canvas(out).also { canvas ->
546549
Paint().also { paint ->
547550
paint.isAntiAlias = true
@@ -561,6 +564,7 @@ fun Bitmap.round(radius: Float): Bitmap = safeOf(default = this) {
561564
* @param default 默认值
562565
* @return [String]
563566
*/
567+
@Suppress("DEPRECATION")
564568
fun findPropString(key: String, default: String = "") = safeOf(default) {
565569
"android.os.SystemProperties".toClassOrNull()?.method {
566570
name = "get"
@@ -634,7 +638,7 @@ fun Context.openBrowser(url: String, packageName: String = "") = runCatching {
634638
startActivity(Intent().apply {
635639
if (packageName.isNotBlank()) setPackage(packageName)
636640
action = Intent.ACTION_VIEW
637-
data = Uri.parse(url)
641+
data = url.toUri()
638642
/** 防止顶栈一样重叠在自己的 APP 中 */
639643
flags = Intent.FLAG_ACTIVITY_NEW_TASK
640644
})

app/src/main/java/com/fankes/miui/notify/utils/tool/BitmapCompatTool.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import android.graphics.drawable.BitmapDrawable
3232
import android.graphics.drawable.Drawable
3333
import android.graphics.drawable.VectorDrawable
3434
import android.util.ArrayMap
35+
import androidx.core.graphics.createBitmap
3536
import androidx.core.graphics.drawable.toBitmap
3637
import com.fankes.miui.notify.utils.factory.safeOfFalse
3738
import kotlin.math.abs
@@ -77,7 +78,7 @@ object BitmapCompatTool {
7778
var width = bitmap.width
7879
if (height > 64 || width > 64) {
7980
if (tempCompactBitmap == null) {
80-
tempCompactBitmap = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888)
81+
tempCompactBitmap = createBitmap(64, 64)
8182
.also { tempCompactBitmapCanvas = Canvas(it) }
8283
tempCompactBitmapPaint = Paint(Paint.FILTER_BITMAP_FLAG).apply { isFilterBitmap = true }
8384
}
@@ -91,11 +92,12 @@ object BitmapCompatTool {
9192
val size = height * width
9293
ensureBufferSize(size)
9394
tempCompactBitmap?.getPixels(tempBuffer, 0, width, 0, 0, width, height)
94-
for (i in 0 until size)
95+
for (i in 0 until size) {
9596
if (isGrayscaleColor(tempBuffer[i]).not()) {
9697
cachedBitmapGrayscales[bitmap.generationId] = false
9798
return@let false
9899
}
100+
}
99101
cachedBitmapGrayscales[bitmap.generationId] = true
100102
true
101103
}

app/src/main/res/layout/activity_main.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,35 @@
14571457
android:textColor="@color/colorTextGray"
14581458
android:textSize="11sp" />
14591459
</LinearLayout>
1460+
1461+
<LinearLayout
1462+
android:layout_width="match_parent"
1463+
android:layout_height="wrap_content"
1464+
android:layout_marginLeft="15dp"
1465+
android:layout_marginRight="15dp"
1466+
android:layout_marginBottom="10dp"
1467+
android:background="@drawable/bg_permotion_round"
1468+
android:gravity="center|start"
1469+
android:orientation="horizontal"
1470+
android:padding="10dp">
1471+
1472+
<ImageView
1473+
android:layout_width="35dp"
1474+
android:layout_height="35dp"
1475+
android:layout_marginEnd="10dp"
1476+
android:src="@mipmap/ic_kavaref" />
1477+
1478+
<TextView
1479+
android:layout_width="match_parent"
1480+
android:layout_height="wrap_content"
1481+
android:autoLink="web"
1482+
android:ellipsize="end"
1483+
android:lineSpacingExtra="6dp"
1484+
android:maxLines="2"
1485+
android:text="此模块使用 KavaRef 强力驱动。\n了解更多 https://github.com/HighCapable/KavaRef"
1486+
android:textColor="@color/colorTextGray"
1487+
android:textSize="11sp" />
1488+
</LinearLayout>
14601489
</LinearLayout>
14611490
</androidx.core.widget.NestedScrollView>
14621491
</LinearLayout>
17 KB
Loading

gradle/sweet-dependency/sweet-dependency-config.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repositories:
2222
plugins:
2323
com.android.application:
2424
alias: android-application
25-
version: 8.9.0
25+
version: 8.9.3
2626
org.jetbrains.kotlin.android:
2727
alias: kotlin-android
2828
version: 2.1.10
@@ -43,9 +43,14 @@ libraries:
4343
rovo89-xposed-api
4444
com.highcapable.yukihookapi:
4545
api:
46-
version: 1.2.1
46+
version: 1.3.0
4747
ksp-xposed:
4848
version-ref: <this>::api
49+
com.highcapable.kavaref:
50+
kavaref-core:
51+
version: 1.0.0
52+
kavaref-extension:
53+
version: 1.0.0
4954
com.github.topjohnwu.libsu:
5055
core:
5156
version: 5.2.2
@@ -55,13 +60,13 @@ libraries:
5560
version: 1.0.7
5661
com.squareup.okhttp3:
5762
okhttp:
58-
version: 5.0.0-alpha.14
63+
version: 5.0.0-alpha.16
5964
androidx.core:
6065
core-ktx:
61-
version: 1.15.0
66+
version: 1.16.0
6267
androidx.appcompat:
6368
appcompat:
64-
version: 1.7.0
69+
version: 1.7.1
6570
com.google.android.material:
6671
material:
6772
version: 1.12.0

0 commit comments

Comments
 (0)