diff --git a/app/src/main/kotlin/li/songe/gkd/data/AppInfo.kt b/app/src/main/kotlin/li/songe/gkd/data/AppInfo.kt index e5aa959..a5483b1 100644 --- a/app/src/main/kotlin/li/songe/gkd/data/AppInfo.kt +++ b/app/src/main/kotlin/li/songe/gkd/data/AppInfo.kt @@ -22,18 +22,16 @@ data class AppInfo( ) val selfAppInfo by lazy { - app.packageManager.getPackageInfo(app.packageName, 0).toAppInfo()!! + app.packageManager.getPackageInfo(app.packageName, 0).toAppInfo() } /** * 平均单次调用时间 11ms */ -fun PackageInfo.toAppInfo(): AppInfo? { - applicationInfo ?: return null +fun PackageInfo.toAppInfo(): AppInfo { + val info = applicationInfo return AppInfo( id = packageName, - name = applicationInfo.loadLabel(app.packageManager).toString(), - icon = applicationInfo.loadIcon(app.packageManager), versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { longVersionCode } else { @@ -41,8 +39,10 @@ fun PackageInfo.toAppInfo(): AppInfo? { versionCode.toLong() }, versionName = versionName, - isSystem = (ApplicationInfo.FLAG_SYSTEM and applicationInfo.flags) != 0, mtime = lastUpdateTime, - hidden = app.packageManager.getLaunchIntentForPackage(packageName) == null + hidden = app.packageManager.getLaunchIntentForPackage(packageName) == null, + name = info?.run { loadLabel(app.packageManager).toString() } ?: packageName, + icon = info?.loadIcon(app.packageManager), + isSystem = info?.run { (ApplicationInfo.FLAG_SYSTEM and flags) != 0 } ?: false, ) } \ No newline at end of file diff --git a/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt b/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt index 874fae8..8c21169 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt @@ -83,9 +83,8 @@ private fun updateAppInfo(appId: String) { } catch (e: PackageManager.NameNotFoundException) { null } - val newAppInfo = info?.toAppInfo() - if (newAppInfo != null) { - newMap[appId] = newAppInfo + if (info != null) { + newMap[appId] = info.toAppInfo() } else { newMap.remove(appId) } @@ -106,10 +105,7 @@ suspend fun initOrResetAppInfoCache() { withContext(Dispatchers.IO) { app.packageManager.getInstalledPackages(0).forEach { packageInfo -> if (!oldAppIds.contains(packageInfo.packageName)) { - val info = packageInfo.toAppInfo() - if (info != null) { - appMap[packageInfo.packageName] = info - } + appMap[packageInfo.packageName] = packageInfo.toAppInfo() } } } diff --git a/app/src/main/kotlin/li/songe/gkd/util/BitmapExt.kt b/app/src/main/kotlin/li/songe/gkd/util/BitmapExt.kt deleted file mode 100644 index 004953e..0000000 --- a/app/src/main/kotlin/li/songe/gkd/util/BitmapExt.kt +++ /dev/null @@ -1,8 +0,0 @@ -package li.songe.gkd.util - -import android.graphics.Bitmap - -fun Bitmap.isEmptyBitmap(): Boolean { - val emptyBitmap = Bitmap.createBitmap(width, height, config) - return this.sameAs(emptyBitmap) -} \ No newline at end of file diff --git a/app/src/main/kotlin/li/songe/gkd/util/Others.kt b/app/src/main/kotlin/li/songe/gkd/util/Others.kt index ab2a67e..4fe342b 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/Others.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/Others.kt @@ -1,6 +1,7 @@ package li.songe.gkd.util import android.content.ComponentName +import android.graphics.Bitmap import li.songe.gkd.META import kotlin.reflect.KClass import kotlin.reflect.jvm.jvmName @@ -13,3 +14,15 @@ private val componentNameCache by lazy { HashMap() } val KClass<*>.componentName get() = componentNameCache.getOrPut(jvmName) { ComponentName(META.appId, jvmName) } + +fun Bitmap.isEmptyBitmap(): Boolean { + // png + repeat(width) { x -> + repeat(height) { y -> + if (getPixel(x, y) != 0) { + return false + } + } + } + return true +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index fbf2acd..fe7deb2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ android.useAndroidX=true android.enableJetifier=true android.debug.obsoleteApi=true kotlin.code.style=official -android_compileSdk=34 -android_targetSdk=34 -android_buildToolsVersion=34.0.0 +android_compileSdk=35 +android_targetSdk=35 +android_buildToolsVersion=35.0.0 android_minSdk=26 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0aedffe..d988e1d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] kotlin = "2.0.20" ksp = "2.0.20-1.0.25" -android = "8.6.1" +android = "8.7.0" compose = "1.7.3" rikka = "4.4.0" room = "2.6.1" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a6f9181..709dee4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME