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 requestCodeExport = 131
private val requestCodeImport = 132
private lateinit var adapter: BgAdapter
var primaryTextColor = 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.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<String>? = 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()

@ -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<FileItem>()
if (rootPath == null) {
rootPath = path
@ -69,17 +61,9 @@ class FileAdapter(context: Context, val callBack: CallBack) :
}
currentPath?.let { currentPath ->
val files: Array<File?>? = 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<String>?
/**
* 是否仅仅读取目录
* 是否取目录
*/
val isOnlyListDir: Boolean
val isSelectDir: Boolean
/**
* 是否显示返回主目录
*/

Loading…
Cancel
Save