From 7bf5f6c20beb25a0e1a19f2abf4f6e4696f612ac Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 25 Oct 2019 16:10:23 +0800 Subject: [PATCH] up --- .../java/io/legado/app/constant/PreferKey.kt | 8 ++++++ .../main/java/io/legado/app/help/BookHelp.kt | 5 ++-- .../io/legado/app/ui/config/ConfigFragment.kt | 25 +++++++++++-------- .../app/ui/filechooser/FileChooserDialog.kt | 6 +++++ 4 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/io/legado/app/constant/PreferKey.kt diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt new file mode 100644 index 000000000..11480d669 --- /dev/null +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -0,0 +1,8 @@ +package io.legado.app.constant + +object PreferKey { + + const val downloadPath = "downloadPath" + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index e198a316f..53eae7501 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt index 884ab1e57..3d5c43896 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt @@ -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, - downloadPath, - mode = FileChooserDialog.DIRECTORY - ) - } + PreferKey.downloadPath -> FileChooserDialog.show( + childFragmentManager, + downloadPath, + 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(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) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index 2aeff7041..1462622bb 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -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