pull/78/head
kunfei 5 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) {
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<ConfigViewModel>(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()

@ -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<Preference>(key)?.summary = getPreferenceString(key)
findPreference<Preference>(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) ?: ""
}
}

@ -211,7 +211,7 @@
<string name="no_download">暂无任务</string>
<string name="download_count">已下载 %d/%d</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="remove_from_bookshelf">删除书籍</string>
<string name="start_read">开始阅读</string>
@ -316,7 +316,7 @@
<string name="use_to">替换范围,选填书名或者源名</string>
<string name="menu_action_group">分组</string>
<string name="download_path">内容缓存路径</string>
<string name="cleancache">清理缓存</string>
<string name="cleanCache">清理缓存</string>
<string name="sys_file_picker">系统文件选择器</string>
<string name="new_version">新版本</string>
<string name="download_update">下载更新</string>

@ -22,6 +22,21 @@
android:title="显示订阅"
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
android:defaultValue="true"
android:key="process_text"
@ -35,13 +50,4 @@
android: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" />
</androidx.preference.PreferenceScreen>
Loading…
Cancel
Save