pull/63/head
kunfei 5 years ago
parent 1944ace954
commit d9e2f979ae
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 3
      app/src/main/java/io/legado/app/service/WebService.kt
  3. 17
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.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"
}

@ -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 {

@ -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<Boolean>(Bus.WEB_SERVICE_STOP) {
findPreference<SwitchPreference>("webService")?.let {
it.isChecked = false
}
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

Loading…
Cancel
Save