pull/42/head
kunfei 5 years ago
parent dc600dbba8
commit 7bf5f6c20b
  1. 8
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 5
      app/src/main/java/io/legado/app/help/BookHelp.kt
  3. 21
      app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt
  4. 6
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt

@ -0,0 +1,8 @@
package io.legado.app.constant
object PreferKey {
const val downloadPath = "downloadPath"
}

@ -1,6 +1,7 @@
package io.legado.app.help package io.legado.app.help
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
@ -13,13 +14,13 @@ import kotlin.math.min
object BookHelp { object BookHelp {
private var downloadPath: String = private var downloadPath: String =
App.INSTANCE.getPrefString("downloadPath") App.INSTANCE.getPrefString(PreferKey.downloadPath)
?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath
?: App.INSTANCE.cacheDir.absolutePath ?: App.INSTANCE.cacheDir.absolutePath
fun upDownloadPath() { fun upDownloadPath() {
downloadPath = downloadPath =
App.INSTANCE.getPrefString("downloadPath") App.INSTANCE.getPrefString(PreferKey.downloadPath)
?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath
?: App.INSTANCE.cacheDir.absolutePath ?: App.INSTANCE.cacheDir.absolutePath
} }

@ -10,6 +10,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.receiver.SharedReceiverActivity
@ -35,7 +36,7 @@ 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)
bindPreferenceSummaryToValue(findPreference("downloadPath")) bindPreferenceSummaryToValue(findPreference(PreferKey.downloadPath))
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -55,20 +56,22 @@ class ConfigFragment : PreferenceFragmentCompat(),
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
"downloadPath" -> fragmentManager?.let { PreferKey.downloadPath -> FileChooserDialog.show(
FileChooserDialog.show( childFragmentManager,
it,
downloadPath, downloadPath,
mode = FileChooserDialog.DIRECTORY mode = FileChooserDialog.DIRECTORY,
initPath = getPreferenceString(PreferKey.downloadPath)
) )
} }
}
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) { when (key) {
"downloadPath" -> BookHelp.upDownloadPath() PreferKey.downloadPath -> {
BookHelp.upDownloadPath()
findPreference<Preference>(key)?.summary = getPreferenceString(key)
}
"recordLog" -> LogUtils.upLevel() "recordLog" -> LogUtils.upLevel()
"process_text" -> sharedPreferences?.let { "process_text" -> sharedPreferences?.let {
setProcessTextEnable(it.getBoolean("process_text", true)) setProcessTextEnable(it.getBoolean("process_text", true))
@ -102,7 +105,7 @@ class ConfigFragment : PreferenceFragmentCompat(),
private fun getPreferenceString(key: String): String { private fun getPreferenceString(key: String): String {
return when (key) { return when (key) {
"downloadPath" -> getPrefString("downloadPath") PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath)
?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath
?: App.INSTANCE.cacheDir.absolutePath ?: App.INSTANCE.cacheDir.absolutePath
else -> getPrefString(key, "") else -> getPrefString(key, "")
@ -129,6 +132,6 @@ class ConfigFragment : PreferenceFragmentCompat(),
override fun onFilePicked(requestCode: Int, currentPath: String) { override fun onFilePicked(requestCode: Int, currentPath: String) {
super.onFilePicked(requestCode, currentPath) super.onFilePicked(requestCode, currentPath)
putPrefString("downloadPath", currentPath) putPrefString(PreferKey.downloadPath, currentPath)
} }
} }

@ -36,6 +36,7 @@ class FileChooserDialog : DialogFragment(),
requestCode: Int, requestCode: Int,
mode: Int = FILE, mode: Int = FILE,
title: String? = null, title: String? = null,
initPath: String? = null,
isShowHomeDir: Boolean = false, isShowHomeDir: Boolean = false,
isShowUpDir: Boolean = true, isShowUpDir: Boolean = true,
isShowHideDir: Boolean = false isShowHideDir: Boolean = false
@ -49,6 +50,7 @@ class FileChooserDialog : DialogFragment(),
bundle.putBoolean("isShowHomeDir", isShowHomeDir) bundle.putBoolean("isShowHomeDir", isShowHomeDir)
bundle.putBoolean("isShowUpDir", isShowUpDir) bundle.putBoolean("isShowUpDir", isShowUpDir)
bundle.putBoolean("isShowHideDir", isShowHideDir) bundle.putBoolean("isShowHideDir", isShowHideDir)
bundle.putString("initPath", initPath)
arguments = bundle arguments = bundle
} }
fragment.show(manager, tag) fragment.show(manager, tag)
@ -95,6 +97,9 @@ class FileChooserDialog : DialogFragment(),
isShowHomeDir = it.getBoolean("isShowHomeDir") isShowHomeDir = it.getBoolean("isShowHomeDir")
isShowUpDir = it.getBoolean("isShowUpDir") isShowUpDir = it.getBoolean("isShowUpDir")
isShowHideDir = it.getBoolean("isShowHideDir") isShowHideDir = it.getBoolean("isShowHideDir")
it.getString("initPath")?.let { path ->
initPath = path
}
} }
tool_bar.title = title ?: let { tool_bar.title = title ?: let {
if (isOnlyListDir) { if (isOnlyListDir) {
@ -132,6 +137,7 @@ class FileChooserDialog : DialogFragment(),
R.id.menu_add -> fileAdapter.currentPath?.let { R.id.menu_add -> fileAdapter.currentPath?.let {
(parentFragment as? CallBack)?.onFilePicked(requestCode, it) (parentFragment as? CallBack)?.onFilePicked(requestCode, it)
(activity as? CallBack)?.onFilePicked(requestCode, it) (activity as? CallBack)?.onFilePicked(requestCode, it)
dismiss()
} }
} }
return true return true

Loading…
Cancel
Save