From 7e8fc8622c6e0be869c8b451f4e85a759033c50f Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 4 Sep 2020 22:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/config/BgTextConfigDialog.kt | 2 + .../app/ui/filechooser/FileChooserDialog.kt | 15 +++-- .../app/ui/filechooser/adapter/FileAdapter.kt | 60 ++++++++++--------- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 98252c6d3..f42c77e65 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -41,6 +41,8 @@ class BgTextConfigDialog : BaseDialogFragment() { } private val requestCodeBg = 123 + private val requestCodeExport = 131 + private val requestCodeImport = 132 private lateinit var adapter: BgAdapter var primaryTextColor = 0 var secondaryTextColor = 0 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 fb2e5ac19..79d674d70 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 @@ -16,10 +16,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.filechooser.adapter.FileAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter import io.legado.app.ui.widget.recycler.VerticalDivider -import io.legado.app.utils.FileUtils -import io.legado.app.utils.applyTint -import io.legado.app.utils.gone -import io.legado.app.utils.visible +import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_file_chooser.* @@ -62,7 +59,7 @@ class FileChooserDialog : DialogFragment(), } override var allowExtensions: Array? = null - override val isOnlyListDir: Boolean + override val isSelectDir: Boolean get() = mode == DIRECTORY override var isShowHomeDir: Boolean = false override var isShowUpDir: Boolean = true @@ -109,7 +106,7 @@ class FileChooserDialog : DialogFragment(), menus = it.getStringArray("menus") } tool_bar.title = title ?: let { - if (isOnlyListDir) { + if (isSelectDir) { getString(R.string.folder_chooser) } else { getString(R.string.file_chooser) @@ -122,7 +119,7 @@ class FileChooserDialog : DialogFragment(), private fun initMenu() { tool_bar.inflateMenu(R.menu.file_chooser) - if (isOnlyListDir) { + if (isSelectDir) { tool_bar.menu.findItem(R.id.menu_ok).isVisible = true } menus?.let { @@ -169,7 +166,9 @@ class FileChooserDialog : DialogFragment(), refreshCurrentDirPath(fileItem.path) } else { fileItem?.path?.let { path -> - if (mode != DIRECTORY) { + if (mode == DIRECTORY) { + toast("这是文件夹选择,不能选择文件,点击右上角的确定选择文件夹") + } else { (parentFragment as? CallBack)?.onFilePicked(requestCode, path) (activity as? CallBack)?.onFilePicked(requestCode, path) dismiss() 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 42e34dfb1..766532d61 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 @@ -2,10 +2,12 @@ package io.legado.app.ui.filechooser.adapter import android.content.Context -import android.graphics.drawable.Drawable import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.help.AppConfig +import io.legado.app.lib.theme.getPrimaryDisabledTextColor +import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.ui.filechooser.entity.FileItem import io.legado.app.ui.filechooser.utils.ConvertUtils import io.legado.app.ui.filechooser.utils.FilePickerIcon @@ -21,27 +23,17 @@ class FileAdapter(context: Context, val callBack: CallBack) : private var rootPath: String? = null var currentPath: String? = null private set - private var homeIcon: Drawable? = null - private var upIcon: Drawable? = null - private var folderIcon: Drawable? = null - private var fileIcon: Drawable? = null + private val homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHOME()) + private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUPDIR()) + private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFOLDER()) + private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFILE()) + private val primaryTextColor = context.getPrimaryTextColor(!AppConfig.isNightTheme) + private val disabledTextColor = context.getPrimaryDisabledTextColor(!AppConfig.isNightTheme) fun loadData(path: String?) { if (path == null) { return } - if (homeIcon == null) { - homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHOME()) - } - if (upIcon == null) { - upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUPDIR()) - } - if (folderIcon == null) { - folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFOLDER()) - } - if (fileIcon == null) { - fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFILE()) - } val data = ArrayList() if (rootPath == null) { rootPath = path @@ -69,17 +61,9 @@ class FileAdapter(context: Context, val callBack: CallBack) : } currentPath?.let { currentPath -> val files: Array? = callBack.allowExtensions?.let { allowExtensions -> - if (callBack.isOnlyListDir) { - FileUtils.listDirs(currentPath, allowExtensions) - } else { - FileUtils.listDirsAndFiles(currentPath, allowExtensions) - } + FileUtils.listDirsAndFiles(currentPath, allowExtensions) } ?: let { - if (callBack.isOnlyListDir) { - FileUtils.listDirs(currentPath) - } else { - FileUtils.listDirsAndFiles(currentPath) - } + FileUtils.listDirsAndFiles(currentPath) } if (files != null) { for (file in files) { @@ -110,6 +94,21 @@ class FileAdapter(context: Context, val callBack: CallBack) : holder.itemView.apply { image_view.setImageDrawable(item.icon) text_view.text = item.name + if (item.isDirectory) { + text_view.setTextColor(primaryTextColor) + } else { + if (callBack.isSelectDir) { + text_view.setTextColor(disabledTextColor) + } else { + callBack.allowExtensions?.let { + if (it.contains(FileUtils.getExtension(item.path))) { + text_view.setTextColor(primaryTextColor) + } else { + text_view.setTextColor(disabledTextColor) + } + } ?: text_view.setTextColor(primaryTextColor) + } + } } } @@ -121,12 +120,15 @@ class FileAdapter(context: Context, val callBack: CallBack) : interface CallBack { fun onFileClick(position: Int) + //允许的扩展名 var allowExtensions: Array? + /** - * 是否仅仅读取目录 + * 是否选取目录 */ - val isOnlyListDir: Boolean + val isSelectDir: Boolean + /** * 是否显示返回主目录 */