Merge branch 'master' of https://github.com/gedoor/legado into master

pull/399/head
Robot 4 years ago
commit 34b89d7605
  1. 2
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 8
      app/src/main/java/io/legado/app/service/WebService.kt
  3. 18
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  4. 2
      app/src/main/res/values-zh-rHK/strings.xml
  5. 2
      app/src/main/res/values-zh-rTW/strings.xml
  6. 2
      app/src/main/res/values-zh/strings.xml
  7. 2
      app/src/main/res/values/strings.xml

@ -17,7 +17,7 @@ object EventBus {
const val AUDIO_SIZE = "audioSize"
const val AUDIO_SPEED = "audioSpeed"
const val SHOW_RSS = "showRss"
const val WEB_SERVICE_STOP = "webServiceStop"
const val WEB_SERVICE = "webService"
const val UP_DOWNLOAD = "upDownload"
const val SAVE_CONTENT = "saveContent"
const val CHECK_INIT = "checkInit"

@ -24,6 +24,7 @@ class WebService : BaseService() {
companion object {
var isRun = false
var hostAddress = ""
fun start(context: Context) {
context.startService<WebService>()
@ -36,6 +37,7 @@ class WebService : BaseService() {
context.startService(intent)
}
}
}
private var httpServer: HttpServer? = null
@ -56,7 +58,7 @@ class WebService : BaseService() {
if (webSocketServer?.isAlive == true) {
webSocketServer?.stop()
}
postEvent(EventBus.WEB_SERVICE_STOP, true)
postEvent(EventBus.WEB_SERVICE, "")
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@ -82,8 +84,10 @@ class WebService : BaseService() {
try {
httpServer?.start()
webSocketServer?.start(1000 * 30) // 通信超时设置
hostAddress = getString(R.string.http_ip, address.hostAddress, port)
isRun = true
updateNotification(getString(R.string.http_ip, address.hostAddress, port))
postEvent(EventBus.WEB_SERVICE, hostAddress)
updateNotification(hostAddress)
} catch (e: IOException) {
launch {
toast(e.localizedMessage ?: "")

@ -29,7 +29,10 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.ui.widget.prefs.NameListPreference
import io.legado.app.ui.widget.prefs.PreferenceCategory
import io.legado.app.ui.widget.prefs.SwitchPreference
import io.legado.app.utils.*
import io.legado.app.utils.LogUtils
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.observeEventSticky
import io.legado.app.utils.putPrefBoolean
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity
@ -80,8 +83,15 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog.
}
addPreferencesFromResource(R.xml.pref_main)
val webServicePre = findPreference<SwitchPreference>(PreferKey.webService)
observeEvent<Boolean>(EventBus.WEB_SERVICE_STOP) {
webServicePre?.isChecked = false
observeEventSticky<String>(EventBus.WEB_SERVICE) {
webServicePre?.let {
it.isChecked = WebService.isRun
it.summary = if (WebService.isRun) {
WebService.hostAddress
} else {
getString(R.string.web_service_desc)
}
}
}
findPreference<NameListPreference>(PreferKey.themeMode)?.let {
it.setOnPreferenceChangeListener { _, _ ->
@ -118,10 +128,8 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog.
PreferKey.webService -> {
if (requireContext().getPrefBoolean("webService")) {
WebService.start(requireContext())
toast(R.string.service_start)
} else {
WebService.stop(requireContext())
toast(R.string.service_stop)
}
}
"recordLog" -> LogUtils.upLevel()

@ -82,7 +82,7 @@
<string name="is_loading">載入中…</string>
<string name="retry">重試</string>
<string name="web_service">Web 服務</string>
<string name="web_service_desc">啟用 Web 服務</string>
<string name="web_service_desc">瀏覽器寫源,看書</string>
<string name="web_edit_source">web 編輯書源</string>
<string name="http_ip">http://%1$s:%2$d</string>
<string name="offline_cache">離線緩存</string>

@ -82,7 +82,7 @@
<string name="is_loading">載入中…</string>
<string name="retry">重試</string>
<string name="web_service">Web 服務</string>
<string name="web_service_desc">啟用Web服務</string>
<string name="web_service_desc">瀏覽器寫源,看書</string>
<string name="web_edit_source">web編輯書源</string>
<string name="http_ip">http://%1$s:%2$d</string>
<string name="offline_cache">離線緩存</string>

@ -84,7 +84,7 @@
<string name="is_loading">加载中…</string>
<string name="retry">重试</string>
<string name="web_service">Web 服务</string>
<string name="web_service_desc">启用Web服务</string>
<string name="web_service_desc">浏览器写源,看书</string>
<string name="web_edit_source">web编辑书源</string>
<string name="http_ip">http://%1$s:%2$d</string>
<string name="offline_cache">离线缓存</string>

@ -84,7 +84,7 @@
<string name="is_loading">Loading…</string>
<string name="retry">Retry</string>
<string name="web_service">Web service</string>
<string name="web_service_desc">Enable web service</string>
<string name="web_service_desc">Web edit source and read book</string>
<string name="web_edit_source">Edit book sources on the web</string>
<string name="http_ip">http://%1$s:%2$d</string>
<string name="offline_cache">Offline cache</string>

Loading…
Cancel
Save