pull/357/head
gedoor 4 years ago
parent 2c56a43332
commit 7e8fc8622c
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  2. 15
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt
  3. 60
      app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt

@ -41,6 +41,8 @@ class BgTextConfigDialog : BaseDialogFragment() {
} }
private val requestCodeBg = 123 private val requestCodeBg = 123
private val requestCodeExport = 131
private val requestCodeImport = 132
private lateinit var adapter: BgAdapter private lateinit var adapter: BgAdapter
var primaryTextColor = 0 var primaryTextColor = 0
var secondaryTextColor = 0 var secondaryTextColor = 0

@ -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.FileAdapter
import io.legado.app.ui.filechooser.adapter.PathAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.FileUtils import io.legado.app.utils.*
import io.legado.app.utils.applyTint
import io.legado.app.utils.gone
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.dialog_file_chooser.* import kotlinx.android.synthetic.main.dialog_file_chooser.*
@ -62,7 +59,7 @@ class FileChooserDialog : DialogFragment(),
} }
override var allowExtensions: Array<String>? = null override var allowExtensions: Array<String>? = null
override val isOnlyListDir: Boolean override val isSelectDir: Boolean
get() = mode == DIRECTORY get() = mode == DIRECTORY
override var isShowHomeDir: Boolean = false override var isShowHomeDir: Boolean = false
override var isShowUpDir: Boolean = true override var isShowUpDir: Boolean = true
@ -109,7 +106,7 @@ class FileChooserDialog : DialogFragment(),
menus = it.getStringArray("menus") menus = it.getStringArray("menus")
} }
tool_bar.title = title ?: let { tool_bar.title = title ?: let {
if (isOnlyListDir) { if (isSelectDir) {
getString(R.string.folder_chooser) getString(R.string.folder_chooser)
} else { } else {
getString(R.string.file_chooser) getString(R.string.file_chooser)
@ -122,7 +119,7 @@ class FileChooserDialog : DialogFragment(),
private fun initMenu() { private fun initMenu() {
tool_bar.inflateMenu(R.menu.file_chooser) tool_bar.inflateMenu(R.menu.file_chooser)
if (isOnlyListDir) { if (isSelectDir) {
tool_bar.menu.findItem(R.id.menu_ok).isVisible = true tool_bar.menu.findItem(R.id.menu_ok).isVisible = true
} }
menus?.let { menus?.let {
@ -169,7 +166,9 @@ class FileChooserDialog : DialogFragment(),
refreshCurrentDirPath(fileItem.path) refreshCurrentDirPath(fileItem.path)
} else { } else {
fileItem?.path?.let { path -> fileItem?.path?.let { path ->
if (mode != DIRECTORY) { if (mode == DIRECTORY) {
toast("这是文件夹选择,不能选择文件,点击右上角的确定选择文件夹")
} else {
(parentFragment as? CallBack)?.onFilePicked(requestCode, path) (parentFragment as? CallBack)?.onFilePicked(requestCode, path)
(activity as? CallBack)?.onFilePicked(requestCode, path) (activity as? CallBack)?.onFilePicked(requestCode, path)
dismiss() dismiss()

@ -2,10 +2,12 @@ package io.legado.app.ui.filechooser.adapter
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter 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.entity.FileItem
import io.legado.app.ui.filechooser.utils.ConvertUtils import io.legado.app.ui.filechooser.utils.ConvertUtils
import io.legado.app.ui.filechooser.utils.FilePickerIcon import io.legado.app.ui.filechooser.utils.FilePickerIcon
@ -21,27 +23,17 @@ class FileAdapter(context: Context, val callBack: CallBack) :
private var rootPath: String? = null private var rootPath: String? = null
var currentPath: String? = null var currentPath: String? = null
private set private set
private var homeIcon: Drawable? = null private val homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHOME())
private var upIcon: Drawable? = null private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUPDIR())
private var folderIcon: Drawable? = null private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFOLDER())
private var fileIcon: Drawable? = null 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?) { fun loadData(path: String?) {
if (path == null) { if (path == null) {
return 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<FileItem>() val data = ArrayList<FileItem>()
if (rootPath == null) { if (rootPath == null) {
rootPath = path rootPath = path
@ -69,17 +61,9 @@ class FileAdapter(context: Context, val callBack: CallBack) :
} }
currentPath?.let { currentPath -> currentPath?.let { currentPath ->
val files: Array<File?>? = callBack.allowExtensions?.let { allowExtensions -> val files: Array<File?>? = callBack.allowExtensions?.let { allowExtensions ->
if (callBack.isOnlyListDir) { FileUtils.listDirsAndFiles(currentPath, allowExtensions)
FileUtils.listDirs(currentPath, allowExtensions)
} else {
FileUtils.listDirsAndFiles(currentPath, allowExtensions)
}
} ?: let { } ?: let {
if (callBack.isOnlyListDir) { FileUtils.listDirsAndFiles(currentPath)
FileUtils.listDirs(currentPath)
} else {
FileUtils.listDirsAndFiles(currentPath)
}
} }
if (files != null) { if (files != null) {
for (file in files) { for (file in files) {
@ -110,6 +94,21 @@ class FileAdapter(context: Context, val callBack: CallBack) :
holder.itemView.apply { holder.itemView.apply {
image_view.setImageDrawable(item.icon) image_view.setImageDrawable(item.icon)
text_view.text = item.name 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 { interface CallBack {
fun onFileClick(position: Int) fun onFileClick(position: Int)
//允许的扩展名 //允许的扩展名
var allowExtensions: Array<String>? var allowExtensions: Array<String>?
/** /**
* 是否仅仅读取目录 * 是否取目录
*/ */
val isOnlyListDir: Boolean val isSelectDir: Boolean
/** /**
* 是否显示返回主目录 * 是否显示返回主目录
*/ */

Loading…
Cancel
Save