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 b3ae92f19..d32e4d077 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -16,12 +16,16 @@ import kotlin.math.min object BookHelp { - private var downloadPath = - App.INSTANCE.getPrefString("downloadPath") ?: App.INSTANCE.getExternalFilesDir(null) + private var downloadPath: String = + App.INSTANCE.getPrefString("downloadPath") + ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath + ?: App.INSTANCE.cacheDir.absolutePath fun upDownloadPath() { downloadPath = - App.INSTANCE.getPrefString("downloadPath") ?: App.INSTANCE.getExternalFilesDir(null) + App.INSTANCE.getPrefString("downloadPath") + ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath + ?: App.INSTANCE.cacheDir.absolutePath } fun saveContent(book: Book, bookChapter: BookChapter, content: String) { 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 2885572ae..c3b0ae799 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 @@ -6,7 +6,9 @@ import android.view.View import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import io.legado.app.App import io.legado.app.R +import io.legado.app.help.BookHelp import io.legado.app.lib.theme.ATH import io.legado.app.utils.getPrefString @@ -16,6 +18,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config) + bindPreferenceSummaryToValue(findPreference("downloadPath")) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -34,8 +37,9 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { - - + when (key) { + "downloadPath" -> BookHelp.upDownloadPath() + } } override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { @@ -57,9 +61,18 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange preference.onPreferenceChangeListener = this onPreferenceChange( preference, - preference.context.getPrefString(preference.key, "") + getPreferenceString(preference.key) ) } } + private fun getPreferenceString(key: String): String { + return when (key) { + "downloadPath" -> getPrefString("downloadPath") + ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath + ?: App.INSTANCE.cacheDir.absolutePath + else -> getPrefString(key, "") + } + } + } \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config.xml b/app/src/main/res/xml/pref_config.xml index 043eb7cbc..a682044d0 100644 --- a/app/src/main/res/xml/pref_config.xml +++ b/app/src/main/res/xml/pref_config.xml @@ -24,4 +24,9 @@ android:title="文字操作显示搜索" app:iconSpaceReserved="false" /> + + \ No newline at end of file