diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 395d51ec4..b14c9f538 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -18,4 +18,5 @@ object Bus { const val AUDIO_SIZE = "audioSize" const val AUDIO_SPEED = "audioSpeed" const val SHOW_RSS = "showRss" + const val WEB_SERVICE_STOP = "webServiceStop" } \ No newline at end of file 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 b32e6d6bc..25f2b6822 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -8,9 +8,11 @@ import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.Action import io.legado.app.constant.AppConst +import io.legado.app.constant.Bus import io.legado.app.help.IntentHelp import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getPrefInt +import io.legado.app.utils.postEvent import io.legado.app.web.HttpServer import io.legado.app.web.WebSocketServer import kotlinx.coroutines.launch @@ -54,6 +56,7 @@ class WebService : BaseService() { if (webSocketServer?.isAlive == true) { webSocketServer?.stop() } + postEvent(Bus.WEB_SERVICE_STOP, true) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index b84538aa1..e19d68ec5 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -7,9 +7,11 @@ import android.view.MenuItem import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import androidx.preference.SwitchPreference import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment +import io.legado.app.constant.Bus import io.legado.app.help.BookHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat @@ -23,10 +25,7 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.replacerule.ReplaceRuleActivity -import io.legado.app.utils.LogUtils -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.startActivity -import io.legado.app.utils.toast +import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -64,7 +63,17 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + if (WebService.isRun) { + putPrefBoolean("webService", true) + } else { + putPrefBoolean("webService", false) + } addPreferencesFromResource(R.xml.pref_main) + observeEvent(Bus.WEB_SERVICE_STOP) { + findPreference("webService")?.let { + it.isChecked = false + } + } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) {