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 2020071a6..884ab1e57 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 @@ -17,11 +17,15 @@ import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.utils.LogUtils import io.legado.app.utils.getPrefString 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 { + private val downloadPath = 25324 private val packageManager = App.INSTANCE.packageManager private val componentName = ComponentName( App.INSTANCE, @@ -54,6 +58,7 @@ class ConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChange "downloadPath" -> fragmentManager?.let { FileChooserDialog.show( it, + downloadPath, 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) + } } \ 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 134af7df4..89f730934 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 @@ -32,6 +32,7 @@ class FileChooserDialog : DialogFragment(), fun show( manager: FragmentManager, + requestCode: Int, mode: Int = FILE, title: String? = null, isShowHomeDir: Boolean = false, @@ -40,11 +41,14 @@ class FileChooserDialog : DialogFragment(), ) { val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) ?: FileChooserDialog().apply { - this.mode = mode - this.title = title - this.isShowHomeDir = isShowHomeDir - this.isShowUpDir = isShowUpDir - this.isShowHideDir = isShowHideDir + val bundle = Bundle() + bundle.putInt("mode", mode) + bundle.putInt("requestCode", requestCode) + bundle.putString("title", title) + bundle.putBoolean("isShowHomeDir", isShowHomeDir) + bundle.putBoolean("isShowUpDir", isShowUpDir) + bundle.putBoolean("isShowHideDir", isShowHideDir) + arguments = bundle } fragment.show(manager, tag) } @@ -57,6 +61,7 @@ class FileChooserDialog : DialogFragment(), override var isShowUpDir: Boolean = true override var isShowHideDir: Boolean = false + private var requestCode: Int = 0 var title: String? = null private var initPath = FileUtils.getSdCardPath() private var mode: Int = FILE @@ -82,6 +87,14 @@ class FileChooserDialog : DialogFragment(), super.onViewCreated(view, savedInstanceState) ATH.applyBackgroundTint(view) 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 { if (isOnlyListDir) { getString(R.string.folder_chooser) @@ -110,8 +123,8 @@ class FileChooserDialog : DialogFragment(), } else { fileItem?.path?.let { path -> if (mode != DIRECTORY) { - (parentFragment as? CallBack)?.onFilePicked(path) - (activity as? CallBack)?.onFilePicked(path) + (parentFragment as? CallBack)?.onFilePicked(requestCode, path) + (activity as? CallBack)?.onFilePicked(requestCode, path) dismiss() } } @@ -145,6 +158,6 @@ class FileChooserDialog : DialogFragment(), } interface CallBack { - fun onFilePicked(currentPath: String) + fun onFilePicked(requestCode: Int, currentPath: String) {} } } \ No newline at end of file