From a0390b74cba2d3f0b2394d45d3b7e596650abb50 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 25 Oct 2019 13:59:53 +0800 Subject: [PATCH] up --- .../app/ui/filechooser/FileChooserDialog.kt | 34 ++++++++++++++++--- .../app/ui/filechooser/adapter/FileAdapter.kt | 2 +- .../main/res/layout/dialog_file_chooser.xml | 14 ++------ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 35 insertions(+), 17 deletions(-) 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 86b0bd071..134af7df4 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 @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +import io.legado.app.lib.theme.ATH import io.legado.app.ui.filechooser.adapter.FileAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter import io.legado.app.utils.FileUtils @@ -29,19 +30,34 @@ class FileChooserDialog : DialogFragment(), const val DIRECTORY = 0 const val FILE = 1 - fun show(manager: FragmentManager) { - val fragment = - (manager.findFragmentByTag(tag) as? FileChooserDialog) ?: FileChooserDialog() + fun show( + manager: FragmentManager, + mode: Int = FILE, + title: String? = null, + isShowHomeDir: Boolean = false, + isShowUpDir: Boolean = true, + isShowHideDir: Boolean = false + ) { + val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) + ?: FileChooserDialog().apply { + this.mode = mode + this.title = title + this.isShowHomeDir = isShowHomeDir + this.isShowUpDir = isShowUpDir + this.isShowHideDir = isShowHideDir + } fragment.show(manager, tag) } } override var allowExtensions: Array? = null - override var isOnlyListDir: Boolean = false + override val isOnlyListDir: Boolean + get() = mode == DIRECTORY override var isShowHomeDir: Boolean = false override var isShowUpDir: Boolean = true override var isShowHideDir: Boolean = false + var title: String? = null private var initPath = FileUtils.getSdCardPath() private var mode: Int = FILE private lateinit var fileAdapter: FileAdapter @@ -64,7 +80,15 @@ class FileChooserDialog : DialogFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - tool_bar.title = "文件选择" + ATH.applyBackgroundTint(view) + ATH.applyBackgroundTint(rv_path) + tool_bar.title = title ?: let { + if (isOnlyListDir) { + getString(R.string.folder_chooser) + } else { + getString(R.string.file_chooser) + } + } fileAdapter = FileAdapter(requireContext(), this) pathAdapter = PathAdapter(requireContext(), this) diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt index f0bf5ef6b..a34c705b9 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt @@ -123,7 +123,7 @@ class FileAdapter(context: Context, val callBack: CallBack) : /** * 是否仅仅读取目录 */ - var isOnlyListDir: Boolean + val isOnlyListDir: Boolean /** * 是否显示返回主目录 */ diff --git a/app/src/main/res/layout/dialog_file_chooser.xml b/app/src/main/res/layout/dialog_file_chooser.xml index 3d459d19e..91ab61537 100644 --- a/app/src/main/res/layout/dialog_file_chooser.xml +++ b/app/src/main/res/layout/dialog_file_chooser.xml @@ -9,22 +9,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> - - - - + android:paddingRight="10dp" + android:background="@color/background" + android:elevation="5dp" /> 精准搜索 正在启动服务 + 文件选择 + 文件夹选择