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

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

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

Loading…
Cancel
Save