设置里增加书籍文件夹配置,方便切换外部书籍保存文件夹

pull/1500/head
gedoor 3 years ago
parent e318d8d71a
commit d78b47ecdd
  1. 6
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 1
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/BaseReadBookActivity.kt
  4. 25
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  5. 2
      app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt
  6. 2
      app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt
  7. 2
      app/src/main/res/values-es-rES/strings.xml
  8. 2
      app/src/main/res/values-ja-rJP/strings.xml
  9. 2
      app/src/main/res/values-pt-rBR/strings.xml
  10. 2
      app/src/main/res/values-zh-rHK/strings.xml
  11. 2
      app/src/main/res/values-zh-rTW/strings.xml
  12. 2
      app/src/main/res/values-zh/strings.xml
  13. 2
      app/src/main/res/values/strings.xml
  14. 5
      app/src/main/res/xml/pref_config_other.xml

@ -244,6 +244,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefString(PreferKey.ttsEngine, value)
}
var webPort: Int
get() = appCtx.getPrefInt(PreferKey.webPort, 1122)
set(value) {
appCtx.putPrefInt(PreferKey.webPort, value)
}
val autoChangeSource: Boolean
get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true)

@ -48,6 +48,7 @@ class FileAssociationActivity :
if (treeUriStr.isNullOrEmpty()) {
localBookTreeSelect.launch {
title = "选择保存书籍的文件夹"
mode = HandleFileContract.DIR_SYS
}
} else {
importBook(Uri.parse(treeUriStr), uri)

@ -61,7 +61,7 @@ abstract class BaseReadBookActivity :
binding.navigationBar.setBackgroundColor(bottomBackground)
viewModel.permissionDenialLiveData.observe(this) {
selectBookFolderResult.launch {
mode = HandleFileContract.SYS_DIR
mode = HandleFileContract.DIR_SYS
title = "选择书籍所在文件夹"
}
}

@ -19,6 +19,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor
import io.legado.app.receiver.SharedReceiverActivity
import io.legado.app.service.WebService
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.utils.*
import splitties.init.appCtx
@ -32,7 +33,11 @@ class OtherConfigFragment : BasePreferenceFragment(),
appCtx,
SharedReceiverActivity::class.java.name
)
private val webPort get() = getPrefInt(PreferKey.webPort, 1122)
private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) {
it.uri?.let { treeUri ->
AppConfig.defaultBookTreeUri = treeUri.toString()
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.processText, isProcessTextEnabled())
@ -43,7 +48,10 @@ class OtherConfigFragment : BasePreferenceFragment(),
upPreferenceSummary(PreferKey.userAgent, AppConfig.userAgent)
upPreferenceSummary(PreferKey.preDownloadNum, AppConfig.preDownloadNum.toString())
upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString())
upPreferenceSummary(PreferKey.webPort, webPort.toString())
upPreferenceSummary(PreferKey.webPort, AppConfig.webPort.toString())
AppConfig.defaultBookTreeUri?.let {
upPreferenceSummary(PreferKey.defaultBookTreeUri, it)
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -61,6 +69,10 @@ class OtherConfigFragment : BasePreferenceFragment(),
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) {
PreferKey.userAgent -> showUserAgentDialog()
PreferKey.defaultBookTreeUri -> localBookTreeSelect.launch {
title = "选择保存书籍的文件夹"
mode = HandleFileContract.DIR_SYS
}
PreferKey.preDownloadNum -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.pre_download))
.setMaxValue(9999)
@ -81,9 +93,9 @@ class OtherConfigFragment : BasePreferenceFragment(),
.setTitle(getString(R.string.web_port_title))
.setMaxValue(60000)
.setMinValue(1024)
.setValue(webPort)
.setValue(AppConfig.webPort)
.show {
putPrefInt(PreferKey.webPort, it)
AppConfig.webPort = it
}
PreferKey.cleanCache -> clearCache()
"uploadRule" -> DirectLinkUploadConfig().show(childFragmentManager, "uploadRuleConfig")
@ -101,12 +113,15 @@ class OtherConfigFragment : BasePreferenceFragment(),
postEvent(PreferKey.threadCount, "")
}
PreferKey.webPort -> {
upPreferenceSummary(key, webPort.toString())
upPreferenceSummary(key, AppConfig.webPort.toString())
if (WebService.isRun) {
WebService.stop(requireContext())
WebService.start(requireContext())
}
}
PreferKey.defaultBookTreeUri -> {
upPreferenceSummary(key, AppConfig.defaultBookTreeUri)
}
PreferKey.recordLog -> LogUtils.upLevel()
PreferKey.processText -> sharedPreferences?.let {
setProcessTextEnable(it.getBoolean(key, true))

@ -58,7 +58,7 @@ class HandleFileActivity :
}
val allowExtensions = intent.getStringArrayExtra("allowExtensions")
val selectList: ArrayList<SelectItem<Int>> = when (mode) {
HandleFileContract.SYS_DIR -> getDirActions(true)
HandleFileContract.DIR_SYS -> getDirActions(true)
HandleFileContract.DIR -> getDirActions()
HandleFileContract.FILE -> getFileActions()
HandleFileContract.EXPORT -> arrayListOf(

@ -46,7 +46,7 @@ class HandleFileContract :
companion object {
const val DIR = 0
const val FILE = 1
const val SYS_DIR = 2
const val DIR_SYS = 2
const val EXPORT = 3
}

@ -909,5 +909,7 @@
<string name="tts_speech_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
<string name="expand_text_menu">展开文本选择菜单</string>
<string name="book_tree_uri_t">书籍保存位置</string>
<string name="book_tree_uri_s">从其它应用打开的书籍保存位置</string>
</resources>

@ -912,5 +912,7 @@
<string name="tts_speech_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
<string name="expand_text_menu">展开文本选择菜单</string>
<string name="book_tree_uri_t">书籍保存位置</string>
<string name="book_tree_uri_s">从其它应用打开的书籍保存位置</string>
</resources>

@ -912,5 +912,7 @@
<string name="tts_speech_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
<string name="expand_text_menu">展开文本选择菜单</string>
<string name="book_tree_uri_t">书籍保存位置</string>
<string name="book_tree_uri_s">从其它应用打开的书籍保存位置</string>
</resources>

@ -909,5 +909,7 @@
<string name="tts_speech_add">語速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
<string name="expand_text_menu">展开文本选择菜单</string>
<string name="book_tree_uri_t">书籍保存位置</string>
<string name="book_tree_uri_s">从其它应用打开的书籍保存位置</string>
</resources>

@ -911,5 +911,7 @@
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
<string name="expand_text_menu">展开文本选择菜单</string>
<string name="search_content_size">搜索結果</string>
<string name="book_tree_uri_t">书籍保存位置</string>
<string name="book_tree_uri_s">从其它应用打开的书籍保存位置</string>
</resources>

@ -911,5 +911,7 @@
<string name="tts_speech_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
<string name="expand_text_menu">展开文本选择菜单</string>
<string name="book_tree_uri_t">书籍保存位置</string>
<string name="book_tree_uri_s">从其它应用打开的书籍保存位置</string>
</resources>

@ -912,5 +912,7 @@
<string name="tts_speech_add">语速加</string>
<string name="open_sys_dir_picker_error">打开系统文件夹选择器出错,自动打开应用文件夹选择器</string>
<string name="expand_text_menu">展开文本选择菜单</string>
<string name="book_tree_uri_t">书籍保存位置</string>
<string name="book_tree_uri_s">从其它应用打开的书籍保存位置</string>
</resources>

@ -56,6 +56,11 @@
android:key="userAgent"
android:title="UserAgent" />
<io.legado.app.ui.widget.prefs.Preference
android:key="defaultBookTreeUri"
android:title="@string/book_tree_uri_t"
android:summary="@string/book_tree_uri_s" />
<io.legado.app.ui.widget.prefs.Preference
android:key="uploadRule"
android:title="@string/direct_link_upload_rule"

Loading…
Cancel
Save