Skip to content

Commit

Permalink
fix: 后台隐藏 (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 10, 2023
1 parent f270910 commit a2eef9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
21 changes: 16 additions & 5 deletions app/src/main/java/li/songe/gkd/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package li.songe.gkd

import android.app.ActivityManager
import android.content.Context
import androidx.activity.compose.setContent
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.rememberNavController
import com.dylanc.activityresult.launcher.PickContentLauncher
import com.dylanc.activityresult.launcher.RequestPermissionLauncher
import com.dylanc.activityresult.launcher.StartActivityLauncher
import com.ramcosta.composedestinations.DestinationsNavHost
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.map
import li.songe.gkd.composition.CompositionActivity
import li.songe.gkd.composition.CompositionExt.useLifeCycleLog
import li.songe.gkd.ui.NavGraphs
Expand All @@ -19,6 +24,8 @@ import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.LocalPickContentLauncher
import li.songe.gkd.util.LocalRequestPermissionLauncher
import li.songe.gkd.util.UpgradeDialog
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.storeFlow

@AndroidEntryPoint
class MainActivity : CompositionActivity({
Expand All @@ -29,11 +36,15 @@ class MainActivity : CompositionActivity({
val pickContentLauncher = PickContentLauncher(this)
val requestPermissionLauncher = RequestPermissionLauncher(this)

// https://juejin.cn/post/7169147194400833572
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// window.attributes.layoutInDisplayCutoutMode =
// WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
// }
lifecycleScope.launchTry(Dispatchers.IO) {
storeFlow.map { s -> s.excludeFromRecents }.collect {
(app.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).let { manager ->
manager.appTasks.forEach { task ->
task?.setExcludeFromRecents(it)
}
}
}
}

setContent {
UpgradeDialog()
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/java/li/songe/gkd/ui/SettingsPage.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package li.songe.gkd.ui

import android.app.ActivityManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
Expand Down Expand Up @@ -55,7 +53,6 @@ import com.blankj.utilcode.util.ZipUtils
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import li.songe.gkd.MainActivity
import li.songe.gkd.app
import li.songe.gkd.appScope
import li.songe.gkd.ui.component.SettingItem
import li.songe.gkd.ui.component.TextSwitch
Expand Down Expand Up @@ -118,12 +115,6 @@ fun SettingsPage() {
desc = "在[最近任务]界面中隐藏本应用",
checked = store.excludeFromRecents,
onCheckedChange = {

(app.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).let { manager ->
manager.appTasks.forEach { task ->
task?.setExcludeFromRecents(it)
}
}
updateStorage(
storeFlow, store.copy(
excludeFromRecents = it
Expand Down

0 comments on commit a2eef9c

Please sign in to comment.