pull/32/head
kunfei 5 years ago
parent e47a8602e7
commit 8d85662aa1
  1. 10
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 19
      app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt
  3. 5
      app/src/main/res/xml/pref_config.xml

@ -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) {

@ -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, "")
}
}
}

@ -24,4 +24,9 @@
android:title="文字操作显示搜索"
app:iconSpaceReserved="false" />
<Preference
android:key="downloadPath"
android:title="@string/download_path"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceScreen>
Loading…
Cancel
Save