From e18adfc030f9d90220ffbd64da826c67423ec3aa Mon Sep 17 00:00:00 2001 From: NoahCode Date: Tue, 26 Nov 2024 10:38:09 +0800 Subject: [PATCH] feat(design): implement real-time update for exclude from recents setting - Add OnChangedListener to excludeFromRecents setting item - Update exclude from recents status for all app tasks when setting changes - Use ActivityManager to access and modify app tasks --- .../github/kr328/clash/design/AppSettingsDesign.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt b/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt index aa8e597e..230f5046 100644 --- a/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt @@ -1,5 +1,6 @@ package com.github.kr328.clash.design +import android.app.ActivityManager import android.content.Context import android.view.View import com.github.kr328.clash.design.databinding.DesignSettingsCommonBinding @@ -70,7 +71,15 @@ class AppSettingsDesign( icon = R.drawable.eye_off, title = R.string.exclude_from_recents, summary = R.string.exclude_from_recents_summary, - ) + ) { + listener = OnChangedListener { + (context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).let { manager -> + manager.appTasks.forEach { task -> + task?.setExcludeFromRecents(uiStore.excludeFromRecents) + } + } + } + } category(R.string.service)