diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index b427f687b..1ba9ba6cf 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -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" 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 e9d223956..bbf317066 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index e8ea335c0..58caa351d 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -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(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. diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 4ecfb8a8e..b049bcf22 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -37,6 +37,11 @@ android:title="@string/threads_num_title" app:iconSpaceReserved="false" /> + +