This commit is contained in:
Horis
2024-04-28 12:56:35 +08:00
parent e57ad3a09e
commit 33e9286a8e
@@ -5,9 +5,12 @@ import android.content.Intent
import android.os.Build import android.os.Build
import android.service.quicksettings.Tile import android.service.quicksettings.Tile
import android.service.quicksettings.TileService import android.service.quicksettings.TileService
import android.view.WindowManager.BadTokenException
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.os.postDelayed
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.utils.buildMainHandler
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
@@ -17,6 +20,8 @@ import io.legado.app.utils.printOnDebug
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
class WebTileService : TileService() { class WebTileService : TileService() {
private val handler by lazy { buildMainHandler() }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
try { try {
when (intent?.action) { when (intent?.action) {
@@ -24,6 +29,7 @@ class WebTileService : TileService() {
state = Tile.STATE_ACTIVE state = Tile.STATE_ACTIVE
updateTile() updateTile()
} }
IntentAction.stop -> qsTile?.run { IntentAction.stop -> qsTile?.run {
state = Tile.STATE_INACTIVE state = Tile.STATE_INACTIVE
updateTile() updateTile()
@@ -55,9 +61,15 @@ class WebTileService : TileService() {
val dialog = Dialog(this, R.style.AppTheme_Transparent) val dialog = Dialog(this, R.style.AppTheme_Transparent)
dialog.setOnShowListener { dialog.setOnShowListener {
WebService.startForeground(this) WebService.startForeground(this)
dialog.dismiss() handler.postDelayed(1000) {
dialog.dismiss()
}
}
try {
showDialog(dialog)
} catch (e: BadTokenException) {
e.printStackTrace()
} }
showDialog(dialog)
} else { } else {
WebService.start(this) WebService.start(this)
} }