feat: 仅传输期间显示通知——空闲不发常驻通知,任务结束移除进度通知
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId = "com.smbfast.app"
|
applicationId = "com.smbfast.app"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 28
|
versionCode = 29
|
||||||
versionName = "1.22.1"
|
versionName = "1.23.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package com.smbfast.app
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import com.smbfast.app.smb.SmbClientPool
|
import com.smbfast.app.smb.SmbClientPool
|
||||||
import com.smbfast.app.transfer.Notifier
|
|
||||||
import com.smbfast.app.transfer.Status
|
|
||||||
import com.smbfast.app.transfer.TransferManager
|
import com.smbfast.app.transfer.TransferManager
|
||||||
import com.smbfast.app.util.CrashLog
|
import com.smbfast.app.util.CrashLog
|
||||||
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
||||||
@@ -23,12 +21,8 @@ class App : Application() {
|
|||||||
Security.addProvider(BouncyCastleProvider())
|
Security.addProvider(BouncyCastleProvider())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 常驻"就绪"通知(含灵动岛自检):普通通知直发,不启动前台服务——
|
// 通知策略:仅在下载/上传进行期间显示进度通知(TransferManager 直发),
|
||||||
// 避免在 FGS 被系统限制(dataSync 配额/侧载策略)时整条链路静默失效
|
// 空闲时不挂常驻通知
|
||||||
runCatching {
|
|
||||||
val running = transferManager.items.value.filter { it.status == Status.RUNNING }
|
|
||||||
Notifier.notifyState(this, running)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTerminate() {
|
override fun onTerminate() {
|
||||||
|
|||||||
@@ -55,14 +55,19 @@ object Notifier {
|
|||||||
runCatching { NotificationManagerCompat.from(ctx).notify(NOTIF_ID, n) }
|
runCatching { NotificationManagerCompat.from(ctx).notify(NOTIF_ID, n) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 按当前任务状态立即重发一条通知(设置切换岛开关/模式后调用) */
|
/** 按当前任务状态发通知;无传输任务时改为清除通知(仅在传输期间显示) */
|
||||||
fun refresh(ctx: Context) {
|
fun refresh(ctx: Context) {
|
||||||
val running = runCatching {
|
val running = runCatching {
|
||||||
(ctx.applicationContext as? com.smbfast.app.App)
|
(ctx.applicationContext as? com.smbfast.app.App)
|
||||||
?.transferManager?.items?.value
|
?.transferManager?.items?.value
|
||||||
?.filter { it.status == Status.RUNNING }
|
?.filter { it.status == Status.RUNNING }
|
||||||
}.getOrNull() ?: emptyList()
|
}.getOrNull() ?: emptyList()
|
||||||
notifyState(ctx, running)
|
if (running.isEmpty()) cancelProgress(ctx) else notifyState(ctx, running)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 传输全部结束:移除进度通知(空闲不显示常驻通知) */
|
||||||
|
fun cancelProgress(ctx: Context) {
|
||||||
|
runCatching { NotificationManagerCompat.from(ctx).cancel(NOTIF_ID) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 发一条独立 id 的测试通知,验证通道可见性。返回是否成功 */
|
/** 发一条独立 id 的测试通知,验证通道可见性。返回是否成功 */
|
||||||
|
|||||||
@@ -79,10 +79,10 @@ class TransferManager(private val appContext: Context) {
|
|||||||
.onFailure { com.smbfast.app.util.CrashLog.append("notify", it) }
|
.onFailure { com.smbfast.app.util.CrashLog.append("notify", it) }
|
||||||
}
|
}
|
||||||
} else if (hadRunning) {
|
} else if (hadRunning) {
|
||||||
// 全部结束:恢复"就绪"常驻态
|
// 全部结束:直接移除通知(空闲不显示常驻通知)
|
||||||
hadRunning = false
|
hadRunning = false
|
||||||
lastNotify = 0
|
lastNotify = 0
|
||||||
runCatching { Notifier.notifyState(appContext, emptyList()) }
|
runCatching { Notifier.cancelProgress(appContext) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user