pull/78/head
kunfei 6 years ago
parent 6423f91798
commit 070a6e2524
  1. 6
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  2. 29
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  3. 4
      app/src/main/res/values/strings.xml
  4. 24
      app/src/main/res/xml/pref_config_other.xml

@ -18,9 +18,9 @@ class ConfigActivity : VMBaseActivity<ConfigViewModel>(R.layout.activity_config)
when (viewModel.configType) { when (viewModel.configType) {
ConfigViewModel.TYPE_CONFIG -> { ConfigViewModel.TYPE_CONFIG -> {
title_bar.title = getString(R.string.other_setting) title_bar.title = getString(R.string.other_setting)
val fTag = "configFragment" val fTag = "otherConfigFragment"
var configFragment = supportFragmentManager.findFragmentByTag(fTag) var configFragment = supportFragmentManager.findFragmentByTag(fTag)
if (configFragment == null) configFragment = ConfigFragment() if (configFragment == null) configFragment = OtherConfigFragment()
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.replace(R.id.configFrameLayout, configFragment, fTag) .replace(R.id.configFrameLayout, configFragment, fTag)
.commit() .commit()
@ -36,7 +36,7 @@ class ConfigActivity : VMBaseActivity<ConfigViewModel>(R.layout.activity_config)
} }
ConfigViewModel.TYPE_WEB_DAV_CONFIG -> { ConfigViewModel.TYPE_WEB_DAV_CONFIG -> {
title_bar.title = getString(R.string.backup_restore) title_bar.title = getString(R.string.backup_restore)
val fTag = "backupFragment" val fTag = "backupConfigFragment"
var configFragment = supportFragmentManager.findFragmentByTag(fTag) var configFragment = supportFragmentManager.findFragmentByTag(fTag)
if (configFragment == null) configFragment = BackupConfigFragment() if (configFragment == null) configFragment = BackupConfigFragment()
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()

@ -19,7 +19,7 @@ import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.utils.* import io.legado.app.utils.*
class ConfigFragment : PreferenceFragmentCompat(), class OtherConfigFragment : PreferenceFragmentCompat(),
FileChooserDialog.CallBack, FileChooserDialog.CallBack,
Preference.OnPreferenceChangeListener, Preference.OnPreferenceChangeListener,
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
@ -33,8 +33,9 @@ class ConfigFragment : PreferenceFragmentCompat(),
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean("process_text", isProcessTextEnabled()) putPrefBoolean("process_text", isProcessTextEnabled())
addPreferencesFromResource(R.xml.pref_config) addPreferencesFromResource(R.xml.pref_config_other)
bindPreferenceSummaryToValue(findPreference(PreferKey.downloadPath)) bindPreferenceSummaryToValue(findPreference(PreferKey.downloadPath))
bindPreferenceSummaryToValue(findPreference("threadCount"))
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -58,7 +59,7 @@ class ConfigFragment : PreferenceFragmentCompat(),
childFragmentManager, childFragmentManager,
downloadPath, downloadPath,
mode = FileChooserDialog.DIRECTORY, mode = FileChooserDialog.DIRECTORY,
initPath = getPreferenceString(PreferKey.downloadPath) initPath = getPreferenceString(PreferKey.downloadPath).toString()
) )
PreferKey.cleanCache -> { PreferKey.cleanCache -> {
BookHelp.clearCache() BookHelp.clearCache()
@ -72,7 +73,7 @@ class ConfigFragment : PreferenceFragmentCompat(),
when (key) { when (key) {
PreferKey.downloadPath -> { PreferKey.downloadPath -> {
BookHelp.upDownloadPath() BookHelp.upDownloadPath()
findPreference<Preference>(key)?.summary = getPreferenceString(key) findPreference<Preference>(key)?.summary = getPreferenceString(key).toString()
} }
PreferKey.recordLog -> LogUtils.upLevel() PreferKey.recordLog -> LogUtils.upLevel()
PreferKey.processText -> sharedPreferences?.let { PreferKey.processText -> sharedPreferences?.let {
@ -84,14 +85,15 @@ class ConfigFragment : PreferenceFragmentCompat(),
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
val stringValue = newValue.toString() val stringValue = newValue.toString()
when {
if (preference is ListPreference) { preference is ListPreference -> {
val index = preference.findIndexOfValue(stringValue) val index = preference.findIndexOfValue(stringValue)
// Set the summary to reflect the new value. // Set the summary to reflect the new value.
preference.setSummary(if (index >= 0) preference.entries[index] else null) preference.setSummary(if (index >= 0) preference.entries[index] else null)
} else { }
// For all other preferences, set the summary to the value's preference?.key == "threadCount" -> preference.summary =
preference?.summary = stringValue getString(R.string.threads_num, stringValue)
else -> preference?.summary = stringValue
} }
return true return true
} }
@ -106,11 +108,12 @@ class ConfigFragment : PreferenceFragmentCompat(),
} }
} }
private fun getPreferenceString(key: String): String { private fun getPreferenceString(key: String): Any {
return when (key) { return when (key) {
PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath)
?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath
?: App.INSTANCE.cacheDir.absolutePath ?: App.INSTANCE.cacheDir.absolutePath
"threadCount" -> getPrefInt("threadCount", 6)
else -> getPrefString(key) ?: "" else -> getPrefString(key) ?: ""
} }
} }

@ -211,7 +211,7 @@
<string name="no_download">暂无任务</string> <string name="no_download">暂无任务</string>
<string name="download_count">已下载 %d/%d</string> <string name="download_count">已下载 %d/%d</string>
<string name="import_select_book">导入选择书籍</string> <string name="import_select_book">导入选择书籍</string>
<string name="update_search_threads_num">更新和搜索线程数,如感觉卡顿请减小线程数,量力而行</string> <string name="threads_num_title">更新和搜索线程数,太多会卡顿</string>
<string name="change_icon">切换图标</string> <string name="change_icon">切换图标</string>
<string name="remove_from_bookshelf">删除书籍</string> <string name="remove_from_bookshelf">删除书籍</string>
<string name="start_read">开始阅读</string> <string name="start_read">开始阅读</string>
@ -316,7 +316,7 @@
<string name="use_to">替换范围,选填书名或者源名</string> <string name="use_to">替换范围,选填书名或者源名</string>
<string name="menu_action_group">分组</string> <string name="menu_action_group">分组</string>
<string name="download_path">内容缓存路径</string> <string name="download_path">内容缓存路径</string>
<string name="cleancache">清理缓存</string> <string name="cleanCache">清理缓存</string>
<string name="sys_file_picker">系统文件选择器</string> <string name="sys_file_picker">系统文件选择器</string>
<string name="new_version">新版本</string> <string name="new_version">新版本</string>
<string name="download_update">下载更新</string> <string name="download_update">下载更新</string>

@ -22,6 +22,21 @@
android:title="显示订阅" android:title="显示订阅"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<Preference
android:key="threadCount"
android:title="@string/threads_num_title"
app:iconSpaceReserved="false" />
<Preference
android:key="downloadPath"
android:title="@string/download_path"
app:iconSpaceReserved="false" />
<Preference
android:key="cleanCache"
android:title="@string/cleanCache"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference <io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="process_text" android:key="process_text"
@ -35,13 +50,4 @@
android:title="记录日志" android:title="记录日志"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<Preference
android:key="downloadPath"
android:title="@string/download_path"
app:iconSpaceReserved="false" />
<Preference
android:key="cleanCache"
android:title="@string/cleancache"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>
Loading…
Cancel
Save