mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
f37a9ad879
commit
03287e563f
@ -215,7 +215,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
|
||||
val docList = DocumentUtils.listFiles(path) {
|
||||
when {
|
||||
it.name.startsWith(".") -> false
|
||||
it.isDirectory -> true
|
||||
it.isDir -> true
|
||||
else -> it.name.matches(bookFileRegex)
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import kotlinx.coroutines.launch
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
@ -31,9 +30,6 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
|
||||
Toolbar.OnMenuItemClickListener,
|
||||
FontAdapter.CallBack {
|
||||
private val fontRegex = Regex("(?i).*\\.[ot]tf")
|
||||
private val fontFolder by lazy {
|
||||
FileUtils.createFolderIfNotExist(appCtx.filesDir, "Fonts")
|
||||
}
|
||||
private val binding by viewBinding(DialogFontSelectBinding::bind)
|
||||
private val adapter by lazy {
|
||||
val curFontPath = callBack?.curFontPath ?: ""
|
||||
@ -188,7 +184,6 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
|
||||
|
||||
override fun onClick(docItem: FileDoc) {
|
||||
execute {
|
||||
FileUtils.deleteFile(fontFolder.absolutePath)
|
||||
callBack?.selectFont(docItem.uri.toString())
|
||||
}.onSuccess {
|
||||
dismissAllowingStateLoss()
|
||||
|
@ -96,6 +96,9 @@ object DocumentUtils {
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun listFiles(uri: Uri, filter: ((file: FileDoc) -> Boolean)? = null): ArrayList<FileDoc> {
|
||||
if (!uri.isContentScheme()) {
|
||||
return listFiles(uri.path!!, filter)
|
||||
}
|
||||
val docList = arrayListOf<FileDoc>()
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
@ -139,23 +142,22 @@ object DocumentUtils {
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun listFiles(path: String, filter: ((file: File) -> Boolean)? = null): ArrayList<FileDoc> {
|
||||
val docItems = arrayListOf<FileDoc>()
|
||||
fun listFiles(path: String, filter: ((file: FileDoc) -> Boolean)? = null): ArrayList<FileDoc> {
|
||||
val docList = arrayListOf<FileDoc>()
|
||||
val file = File(path)
|
||||
file.listFiles { pathName ->
|
||||
filter?.invoke(pathName) ?: true
|
||||
}?.forEach {
|
||||
docItems.add(
|
||||
FileDoc(
|
||||
it.name,
|
||||
it.isDirectory,
|
||||
it.length(),
|
||||
Date(it.lastModified()),
|
||||
Uri.parse(it.absolutePath)
|
||||
)
|
||||
file.listFiles()?.forEach {
|
||||
val item = FileDoc(
|
||||
it.name,
|
||||
it.isDirectory,
|
||||
it.length(),
|
||||
Date(it.lastModified()),
|
||||
Uri.parse(it.absolutePath)
|
||||
)
|
||||
if (filter == null || filter.invoke(item)) {
|
||||
docList.add(item)
|
||||
}
|
||||
}
|
||||
return docItems
|
||||
return docList
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user