diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index a79e3f6a9..a685ccd13 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -18,9 +18,9 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) when (viewModel.configType) { ConfigViewModel.TYPE_CONFIG -> { title_bar.title = getString(R.string.other_setting) - val fTag = "configFragment" + val fTag = "otherConfigFragment" var configFragment = supportFragmentManager.findFragmentByTag(fTag) - if (configFragment == null) configFragment = ConfigFragment() + if (configFragment == null) configFragment = OtherConfigFragment() supportFragmentManager.beginTransaction() .replace(R.id.configFrameLayout, configFragment, fTag) .commit() @@ -36,7 +36,7 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) } ConfigViewModel.TYPE_WEB_DAV_CONFIG -> { title_bar.title = getString(R.string.backup_restore) - val fTag = "backupFragment" + val fTag = "backupConfigFragment" var configFragment = supportFragmentManager.findFragmentByTag(fTag) if (configFragment == null) configFragment = BackupConfigFragment() supportFragmentManager.beginTransaction() diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt similarity index 84% rename from app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt rename to app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 74d517b20..f4c38eb70 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -19,7 +19,7 @@ import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.utils.* -class ConfigFragment : PreferenceFragmentCompat(), +class OtherConfigFragment : PreferenceFragmentCompat(), FileChooserDialog.CallBack, Preference.OnPreferenceChangeListener, SharedPreferences.OnSharedPreferenceChangeListener { @@ -33,8 +33,9 @@ class ConfigFragment : PreferenceFragmentCompat(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean("process_text", isProcessTextEnabled()) - addPreferencesFromResource(R.xml.pref_config) + addPreferencesFromResource(R.xml.pref_config_other) bindPreferenceSummaryToValue(findPreference(PreferKey.downloadPath)) + bindPreferenceSummaryToValue(findPreference("threadCount")) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -58,7 +59,7 @@ class ConfigFragment : PreferenceFragmentCompat(), childFragmentManager, downloadPath, mode = FileChooserDialog.DIRECTORY, - initPath = getPreferenceString(PreferKey.downloadPath) + initPath = getPreferenceString(PreferKey.downloadPath).toString() ) PreferKey.cleanCache -> { BookHelp.clearCache() @@ -72,7 +73,7 @@ class ConfigFragment : PreferenceFragmentCompat(), when (key) { PreferKey.downloadPath -> { BookHelp.upDownloadPath() - findPreference(key)?.summary = getPreferenceString(key) + findPreference(key)?.summary = getPreferenceString(key).toString() } PreferKey.recordLog -> LogUtils.upLevel() PreferKey.processText -> sharedPreferences?.let { @@ -84,14 +85,15 @@ class ConfigFragment : PreferenceFragmentCompat(), override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { val stringValue = newValue.toString() - - if (preference is ListPreference) { - val index = preference.findIndexOfValue(stringValue) - // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) - } else { - // For all other preferences, set the summary to the value's - preference?.summary = stringValue + when { + preference is ListPreference -> { + val index = preference.findIndexOfValue(stringValue) + // Set the summary to reflect the new value. + preference.setSummary(if (index >= 0) preference.entries[index] else null) + } + preference?.key == "threadCount" -> preference.summary = + getString(R.string.threads_num, stringValue) + else -> preference?.summary = stringValue } return true } @@ -106,11 +108,12 @@ class ConfigFragment : PreferenceFragmentCompat(), } } - private fun getPreferenceString(key: String): String { + private fun getPreferenceString(key: String): Any { return when (key) { PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath + "threadCount" -> getPrefInt("threadCount", 6) else -> getPrefString(key) ?: "" } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ceda2af3..12ceceb6d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -211,7 +211,7 @@ 暂无任务 已下载 %d/%d 导入选择书籍 - 更新和搜索线程数,如感觉卡顿请减小线程数,量力而行 + 更新和搜索线程数,太多会卡顿 切换图标 删除书籍 开始阅读 @@ -316,7 +316,7 @@ 替换范围,选填书名或者源名 分组 内容缓存路径 - 清理缓存 + 清理缓存 系统文件选择器 新版本 下载更新 diff --git a/app/src/main/res/xml/pref_config.xml b/app/src/main/res/xml/pref_config_other.xml similarity index 88% rename from app/src/main/res/xml/pref_config.xml rename to app/src/main/res/xml/pref_config_other.xml index 55f0f6021..6c38cf624 100644 --- a/app/src/main/res/xml/pref_config.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -22,6 +22,21 @@ android:title="显示订阅" app:iconSpaceReserved="false" /> + + + + + + - - - \ No newline at end of file