chore: 更新依赖版本并优化代码

main
mojo 4 weeks ago
parent 3a47b16003
commit a276704071

@ -1,7 +1,7 @@
[versions]
agp = "8.2.0"
kotlin = "1.9.0"
coreKtx = "1.17.0"
coreKtx = "1.0.0"
junit = "4.13.2"
junitVersion = "1.3.0"
espressoCore = "3.7.0"

@ -27,6 +27,7 @@ class PinService(
private const val HTTP_STATUS_OK = 200
private const val POLLING_INTERVAL_MS = 1000L
private const val MS_TO_SECONDS = 1000f
private val TAG = PinService::class.java.simpleName
}
// ==================== 主执行方法 ====================
@ -64,7 +65,7 @@ class PinService(
taskConfig.notificationCache.add(notificationMessage)
}
LogUtils.info("PinService: next list: ${nextList.map { "${it.regexp}, ${it.contain}" }}")
LogUtils.info("$TAG: next list: ${nextList.map { "${it.regexp}, ${it.contain}" }}")
withTimeoutOrNull(action.delay.toDuration(DurationUnit.SECONDS)) {
while (isActive) {
@ -73,20 +74,20 @@ class PinService(
if (shouldCheckForMessages(nextList, notificationCache)) {
val notificationMessages = haveNextCatchTargetMessage(notificationCache, nextList)
if (notificationMessages.isNotEmpty()) {
LogUtils.info("PinService: catch target message...")
LogUtils.info("$TAG: catch target message...")
messageLog.addAll(notificationMessages)
break
}
}
val elapsed = System.currentTimeMillis() - start
LogUtils.info("PinService: waiting for target message... delay: ${action.delay}s, elapsed: ${elapsed / MS_TO_SECONDS}s")
LogUtils.info("$TAG: waiting for target message... delay: ${action.delay}s, elapsed: ${elapsed / MS_TO_SECONDS}s")
delay(POLLING_INTERVAL_MS)
}
}
val cost = System.currentTimeMillis() - start
LogUtils.info("PinService: waiting finished, cost: ${cost / MS_TO_SECONDS}s")
LogUtils.info("$TAG: waiting finished, cost: ${cost / MS_TO_SECONDS}s")
NotificationManger.stopPolling()
return ExecutionResult(messageLog, cost, nextList)
}
@ -238,7 +239,7 @@ class PinService(
return emptyList()
}
LogUtils.info("PinService: message size: ${notificationCache.size}")
LogUtils.info("$TAG: message size: ${notificationCache.size}")
// 预编译正则表达式以提高性能
val compiledPatterns = compileRegexPatterns(nextList)
@ -264,12 +265,12 @@ class PinService(
compiledPatterns: Map<Next, Regex>
): NotificationMessage? {
for (notify in notificationCache) {
LogUtils.info("PinService: checking notify: ${notify.content}")
LogUtils.info("$TAG: checking notify: ${notify.content}")
for (next in nextList) {
if (next.step <= 0) continue
LogUtils.info("PinService: checking next: $next")
LogUtils.info("$TAG: checking next: $next")
if (matchesContain(notify, next) || matchesRegex(notify, next, compiledPatterns)) {
return notify

@ -4,6 +4,7 @@ import android.app.Application
import com.galaxy.demo.services.AccountUtils
import com.galaxy.permision.DistrictFilter
import com.galaxy.permision.PermissionChecker
import com.galaxy.permision.operatorCode
class App:Application() {
override fun onCreate() {
@ -13,8 +14,8 @@ class App:Application() {
private fun init() {
PermissionChecker.showPermissionDialog(this, DistrictFilter("460"))
AccountUtils.addAccount(this)
PermissionChecker.showPermissionDialog(this, DistrictFilter(operatorCode()))
// AccountUtils.addAccount(this)
}
}

@ -1,6 +1,7 @@
package com.galaxy.demo
import android.Manifest
import android.R
import android.app.Activity
import android.app.NotificationChannel
import android.app.NotificationManager
@ -159,7 +160,7 @@ class MainActivity : Activity() {
val mBuilder = NotificationCompat.Builder(context, mNormalChannelId)
.setContentTitle("It's time to exercise.") // 标题
.setContentText("Make a little progress every day, and your body will unleash its unlimited potential.") // 文本
// .setSmallIcon(R.mipmap.ic_launcher)
.setSmallIcon(R.mipmap.sym_def_app_icon)
.setPriority(NotificationCompat.PRIORITY_MAX) // 7.0 设置优先级
.setContentIntent(pendingIntent) // 跳转配置
.setAutoCancel(true) // 是否自动消失点击or mManager.cancel(mNormalNotificationId)、cancelAll、setTimeoutAfter()

Loading…
Cancel
Save