From 40773b6244663c807b934c9f5b5570b4a6cea3e4 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 21 Sep 2021 08:36:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/WebService.kt | 17 +++++++++++++++-- .../io/legado/app/service/WebTileService.kt | 18 ------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 3bfb7c524..56d196a4b 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -2,6 +2,7 @@ package io.legado.app.service import android.content.Context import android.content.Intent +import android.os.Build import androidx.core.app.NotificationCompat import io.legado.app.R import io.legado.app.base.BaseService @@ -40,7 +41,7 @@ class WebService : BaseService() { isRun = true notificationContent = getString(R.string.service_starting) upNotification() - WebTileService.setState(this, true) + upTile(true) } override fun onDestroy() { @@ -53,7 +54,7 @@ class WebService : BaseService() { webSocketServer?.stop() } postEvent(EventBus.WEB_SERVICE, "") - WebTileService.setState(this, false) + upTile(false) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -123,4 +124,16 @@ class WebService : BaseService() { val notification = builder.build() startForeground(AppConst.notificationIdWeb, notification) } + + private fun upTile(active: Boolean) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + startService { + action = if (active) { + IntentAction.start + } else { + IntentAction.stop + } + } + } + } } diff --git a/app/src/main/java/io/legado/app/service/WebTileService.kt b/app/src/main/java/io/legado/app/service/WebTileService.kt index 3c964bf71..3f9882add 100644 --- a/app/src/main/java/io/legado/app/service/WebTileService.kt +++ b/app/src/main/java/io/legado/app/service/WebTileService.kt @@ -1,6 +1,5 @@ package io.legado.app.service -import android.content.Context import android.content.Intent import android.os.Build import android.service.quicksettings.Tile @@ -8,7 +7,6 @@ import android.service.quicksettings.TileService import androidx.annotation.RequiresApi import io.legado.app.constant.IntentAction import io.legado.app.utils.printOnDebug -import io.legado.app.utils.startService /** * web服务快捷开关 @@ -16,22 +14,6 @@ import io.legado.app.utils.startService @RequiresApi(Build.VERSION_CODES.N) class WebTileService : TileService() { - companion object { - - fun setState(context: Context, active: Boolean) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - context.startService { - action = if (active) { - IntentAction.start - } else { - IntentAction.stop - } - } - } - } - - } - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { try { when (intent?.action) {