pull/42/head
kunfei 5 years ago
parent 80bad4de21
commit f104cb27ee
  1. 12
      app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt
  2. 29
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt

@ -17,11 +17,15 @@ import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.utils.LogUtils import io.legado.app.utils.LogUtils
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.putPrefBoolean import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.putPrefString
class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, class ConfigFragment : PreferenceFragmentCompat(),
FileChooserDialog.CallBack,
Preference.OnPreferenceChangeListener,
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
private val downloadPath = 25324
private val packageManager = App.INSTANCE.packageManager private val packageManager = App.INSTANCE.packageManager
private val componentName = ComponentName( private val componentName = ComponentName(
App.INSTANCE, App.INSTANCE,
@ -54,6 +58,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange
"downloadPath" -> fragmentManager?.let { "downloadPath" -> fragmentManager?.let {
FileChooserDialog.show( FileChooserDialog.show(
it, it,
downloadPath,
mode = FileChooserDialog.DIRECTORY mode = FileChooserDialog.DIRECTORY
) )
} }
@ -121,4 +126,9 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange
) )
} }
} }
override fun onFilePicked(requestCode: Int, currentPath: String) {
super.onFilePicked(requestCode, currentPath)
putPrefString("downloadPath", currentPath)
}
} }

@ -32,6 +32,7 @@ class FileChooserDialog : DialogFragment(),
fun show( fun show(
manager: FragmentManager, manager: FragmentManager,
requestCode: Int,
mode: Int = FILE, mode: Int = FILE,
title: String? = null, title: String? = null,
isShowHomeDir: Boolean = false, isShowHomeDir: Boolean = false,
@ -40,11 +41,14 @@ class FileChooserDialog : DialogFragment(),
) { ) {
val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog)
?: FileChooserDialog().apply { ?: FileChooserDialog().apply {
this.mode = mode val bundle = Bundle()
this.title = title bundle.putInt("mode", mode)
this.isShowHomeDir = isShowHomeDir bundle.putInt("requestCode", requestCode)
this.isShowUpDir = isShowUpDir bundle.putString("title", title)
this.isShowHideDir = isShowHideDir bundle.putBoolean("isShowHomeDir", isShowHomeDir)
bundle.putBoolean("isShowUpDir", isShowUpDir)
bundle.putBoolean("isShowHideDir", isShowHideDir)
arguments = bundle
} }
fragment.show(manager, tag) fragment.show(manager, tag)
} }
@ -57,6 +61,7 @@ class FileChooserDialog : DialogFragment(),
override var isShowUpDir: Boolean = true override var isShowUpDir: Boolean = true
override var isShowHideDir: Boolean = false override var isShowHideDir: Boolean = false
private var requestCode: Int = 0
var title: String? = null var title: String? = null
private var initPath = FileUtils.getSdCardPath() private var initPath = FileUtils.getSdCardPath()
private var mode: Int = FILE private var mode: Int = FILE
@ -82,6 +87,14 @@ class FileChooserDialog : DialogFragment(),
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
ATH.applyBackgroundTint(view) ATH.applyBackgroundTint(view)
ATH.applyBackgroundTint(rv_path) ATH.applyBackgroundTint(rv_path)
arguments?.let {
requestCode = it.getInt("requestCode")
mode = it.getInt("mode", FILE)
title = it.getString("title")
isShowHomeDir = it.getBoolean("isShowHomeDir")
isShowUpDir = it.getBoolean("isShowUpDir")
isShowHideDir = it.getBoolean("isShowHideDir")
}
tool_bar.title = title ?: let { tool_bar.title = title ?: let {
if (isOnlyListDir) { if (isOnlyListDir) {
getString(R.string.folder_chooser) getString(R.string.folder_chooser)
@ -110,8 +123,8 @@ class FileChooserDialog : DialogFragment(),
} else { } else {
fileItem?.path?.let { path -> fileItem?.path?.let { path ->
if (mode != DIRECTORY) { if (mode != DIRECTORY) {
(parentFragment as? CallBack)?.onFilePicked(path) (parentFragment as? CallBack)?.onFilePicked(requestCode, path)
(activity as? CallBack)?.onFilePicked(path) (activity as? CallBack)?.onFilePicked(requestCode, path)
dismiss() dismiss()
} }
} }
@ -145,6 +158,6 @@ class FileChooserDialog : DialogFragment(),
} }
interface CallBack { interface CallBack {
fun onFilePicked(currentPath: String) fun onFilePicked(requestCode: Int, currentPath: String) {}
} }
} }
Loading…
Cancel
Save