|
|
@ -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,18 +61,10 @@ 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.listDirs(currentPath, allowExtensions) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
FileUtils.listDirsAndFiles(currentPath, allowExtensions) |
|
|
|
FileUtils.listDirsAndFiles(currentPath, allowExtensions) |
|
|
|
} |
|
|
|
|
|
|
|
} ?: let { |
|
|
|
} ?: let { |
|
|
|
if (callBack.isOnlyListDir) { |
|
|
|
|
|
|
|
FileUtils.listDirs(currentPath) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
FileUtils.listDirsAndFiles(currentPath) |
|
|
|
FileUtils.listDirsAndFiles(currentPath) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (files != null) { |
|
|
|
if (files != null) { |
|
|
|
for (file in files) { |
|
|
|
for (file in files) { |
|
|
|
if (file == null || (!callBack.isShowHideDir && file.name.startsWith("."))) { |
|
|
|
if (file == null || (!callBack.isShowHideDir && file.name.startsWith("."))) { |
|
|
@ -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 |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 是否显示返回主目录 |
|
|
|
* 是否显示返回主目录 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|