pull/2718/head
Horis 2 years ago
parent eebdbd41ec
commit 82afa372d9
  1. 9
      app/src/main/java/io/legado/app/ui/font/FontSelectDialog.kt

@ -1,6 +1,7 @@
package io.legado.app.ui.font package io.legado.app.ui.font
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -9,6 +10,7 @@ import androidx.documentfile.provider.DocumentFile
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.AppLog
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.databinding.DialogFontSelectBinding import io.legado.app.databinding.DialogFontSelectBinding
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
@ -113,10 +115,12 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
launch(Main) { launch(Main) {
val defaultPath = "SD${File.separator}Fonts" val defaultPath = "SD${File.separator}Fonts"
selectFontDir.launch { selectFontDir.launch {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
otherActions = arrayListOf(SelectItem(defaultPath, -1)) otherActions = arrayListOf(SelectItem(defaultPath, -1))
} }
} }
} }
}
private fun getLocalFonts(): ArrayList<FileDoc> { private fun getLocalFonts(): ArrayList<FileDoc> {
val path = FileUtils.getPath(requireContext().externalFiles, "font") val path = FileUtils.getPath(requireContext().externalFiles, "font")
@ -141,11 +145,12 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
execute { execute {
val fontItems = fileDoc.list { val fontItems = fileDoc.list {
it.name.matches(fontRegex) it.name.matches(fontRegex)
} } ?: ArrayList()
mergeFontItems(fontItems!!, getLocalFonts()) mergeFontItems(fontItems, getLocalFonts())
}.onSuccess { }.onSuccess {
adapter.setItems(it) adapter.setItems(it)
}.onError { }.onError {
AppLog.put("加载字体文件失败\n${it.localizedMessage}", it)
toastOnUi("getFontFiles:${it.localizedMessage}") toastOnUi("getFontFiles:${it.localizedMessage}")
} }
} }

Loading…
Cancel
Save