pull/1403/head
gedoor 3 years ago
parent f37a9ad879
commit 03287e563f
  1. 2
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  2. 5
      app/src/main/java/io/legado/app/ui/font/FontSelectDialog.kt
  3. 20
      app/src/main/java/io/legado/app/utils/DocumentExtensions.kt

@ -215,7 +215,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
val docList = DocumentUtils.listFiles(path) { val docList = DocumentUtils.listFiles(path) {
when { when {
it.name.startsWith(".") -> false it.name.startsWith(".") -> false
it.isDirectory -> true it.isDir -> true
else -> it.name.matches(bookFileRegex) else -> it.name.matches(bookFileRegex)
} }
} }

@ -22,7 +22,6 @@ import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import splitties.init.appCtx
import java.io.File import java.io.File
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -31,9 +30,6 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
Toolbar.OnMenuItemClickListener, Toolbar.OnMenuItemClickListener,
FontAdapter.CallBack { FontAdapter.CallBack {
private val fontRegex = Regex("(?i).*\\.[ot]tf") 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 binding by viewBinding(DialogFontSelectBinding::bind)
private val adapter by lazy { private val adapter by lazy {
val curFontPath = callBack?.curFontPath ?: "" val curFontPath = callBack?.curFontPath ?: ""
@ -188,7 +184,6 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
override fun onClick(docItem: FileDoc) { override fun onClick(docItem: FileDoc) {
execute { execute {
FileUtils.deleteFile(fontFolder.absolutePath)
callBack?.selectFont(docItem.uri.toString()) callBack?.selectFont(docItem.uri.toString())
}.onSuccess { }.onSuccess {
dismissAllowingStateLoss() dismissAllowingStateLoss()

@ -96,6 +96,9 @@ object DocumentUtils {
@Throws(Exception::class) @Throws(Exception::class)
fun listFiles(uri: Uri, filter: ((file: FileDoc) -> Boolean)? = null): ArrayList<FileDoc> { fun listFiles(uri: Uri, filter: ((file: FileDoc) -> Boolean)? = null): ArrayList<FileDoc> {
if (!uri.isContentScheme()) {
return listFiles(uri.path!!, filter)
}
val docList = arrayListOf<FileDoc>() val docList = arrayListOf<FileDoc>()
var cursor: Cursor? = null var cursor: Cursor? = null
try { try {
@ -139,23 +142,22 @@ object DocumentUtils {
} }
@Throws(Exception::class) @Throws(Exception::class)
fun listFiles(path: String, filter: ((file: File) -> Boolean)? = null): ArrayList<FileDoc> { fun listFiles(path: String, filter: ((file: FileDoc) -> Boolean)? = null): ArrayList<FileDoc> {
val docItems = arrayListOf<FileDoc>() val docList = arrayListOf<FileDoc>()
val file = File(path) val file = File(path)
file.listFiles { pathName -> file.listFiles()?.forEach {
filter?.invoke(pathName) ?: true val item = FileDoc(
}?.forEach {
docItems.add(
FileDoc(
it.name, it.name,
it.isDirectory, it.isDirectory,
it.length(), it.length(),
Date(it.lastModified()), Date(it.lastModified()),
Uri.parse(it.absolutePath) Uri.parse(it.absolutePath)
) )
) if (filter == null || filter.invoke(item)) {
docList.add(item)
} }
return docItems }
return docList
} }
} }

Loading…
Cancel
Save