feat: 优化代码

pull/132/head
kunfei 5 years ago
parent 11de854088
commit b7bae95675
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 6
      app/src/main/java/io/legado/app/service/WebService.kt
  3. 22
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  4. 5
      app/src/main/res/xml/pref_config_other.xml

@ -27,6 +27,7 @@ object PreferKey {
const val fontFolder = "fontFolder"
const val backupPath = "backupUri"
const val threadCount = "threadCount"
const val webPort = "webPort"
const val keepLight = "keep_light"
const val webService = "webService"
const val webDavUrl = "web_dav_url"

@ -3,12 +3,12 @@ package io.legado.app.service
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.IntentAction
import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction
import io.legado.app.constant.PreferKey
import io.legado.app.help.IntentHelp
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.getPrefInt
@ -96,7 +96,7 @@ class WebService : BaseService() {
}
private fun getPort(): Int {
var port = App.INSTANCE.getPrefInt("webPort", 1122)
var port = getPrefInt(PreferKey.webPort, 1122)
if (port > 65530 || port < 1024) {
port = 1122
}

@ -18,6 +18,7 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
import io.legado.app.lib.theme.ATH
import io.legado.app.receiver.SharedReceiverActivity
import io.legado.app.service.WebService
import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.ui.filechooser.FilePicker
import io.legado.app.ui.widget.number.NumberPickerDialog
@ -34,12 +35,14 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
App.INSTANCE,
SharedReceiverActivity::class.java.name
)
private val webPort get() = getPrefInt(PreferKey.webPort, 1122)
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.processText, isProcessTextEnabled())
addPreferencesFromResource(R.xml.pref_config_other)
upPreferenceSummary(PreferKey.downloadPath, BookHelp.downloadPath)
upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString())
upPreferenceSummary(PreferKey.webPort, webPort.toString())
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -63,6 +66,14 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
.show {
AppConfig.threadCount = it
}
PreferKey.webPort -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.web_port_title))
.setMaxValue(60000)
.setMinValue(1024)
.setValue(webPort)
.show {
putPrefInt(PreferKey.webPort, it)
}
PreferKey.downloadPath -> selectDownloadPath()
PreferKey.cleanCache -> {
BookHelp.clearCache()
@ -78,9 +89,15 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
upPreferenceSummary(key, BookHelp.downloadPath)
}
PreferKey.threadCount -> upPreferenceSummary(
PreferKey.threadCount,
AppConfig.threadCount.toString()
key, AppConfig.threadCount.toString()
)
PreferKey.webPort -> {
upPreferenceSummary(key, webPort.toString())
if (WebService.isRun) {
WebService.stop(requireContext())
WebService.start(requireContext())
}
}
PreferKey.recordLog -> LogUtils.upLevel()
PreferKey.processText -> sharedPreferences?.let {
setProcessTextEnable(it.getBoolean(key, true))
@ -93,6 +110,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
val preference = findPreference<Preference>(preferenceKey) ?: return
when (preferenceKey) {
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, value)
else -> if (preference is ListPreference) {
val index = preference.findIndexOfValue(value)
// Set the summary to reflect the new value.

@ -37,6 +37,11 @@
android:title="@string/threads_num_title"
app:iconSpaceReserved="false" />
<Preference
android:key="webPort"
android:title="@string/web_port_title"
app:iconSpaceReserved="false" />
<Preference
android:key="downloadPath"
android:title="@string/download_path"

Loading…
Cancel
Save