pull/1403/head
gedoor 3 years ago
parent 03287e563f
commit dea2ca2edf
  1. 8
      app/src/main/java/io/legado/app/ui/font/FontAdapter.kt
  2. 4
      app/src/main/java/io/legado/app/ui/font/FontSelectDialog.kt
  3. 11
      app/src/main/java/io/legado/app/utils/DocumentExtensions.kt

@ -41,7 +41,7 @@ class FontAdapter(context: Context, curFilePath: String, val callBack: CallBack)
Typeface.createFromFile(RealPathUtil.getPath(context, item.uri))
}
} else {
Typeface.createFromFile(item.uri.toString())
Typeface.createFromFile(item.uri.path!!)
}
tvFont.typeface = typeface
}.onFailure {
@ -49,7 +49,7 @@ class FontAdapter(context: Context, curFilePath: String, val callBack: CallBack)
context.toastOnUi("Read ${item.name} Error: ${it.localizedMessage}")
}
tvFont.text = item.name
root.setOnClickListener { callBack.onClick(item) }
root.setOnClickListener { callBack.onFontSelect(item) }
if (item.name == curName) {
ivChecked.visible()
} else {
@ -61,12 +61,12 @@ class FontAdapter(context: Context, curFilePath: String, val callBack: CallBack)
override fun registerListener(holder: ItemViewHolder, binding: ItemFontBinding) {
holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let {
callBack.onClick(it)
callBack.onFontSelect(it)
}
}
}
interface CallBack {
fun onClick(docItem: FileDoc)
fun onFontSelect(docItem: FileDoc)
}
}

@ -182,9 +182,9 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
}
}
override fun onClick(docItem: FileDoc) {
override fun onFontSelect(docItem: FileDoc) {
execute {
callBack?.selectFont(docItem.uri.toString())
callBack?.selectFont(docItem.toString())
}.onSuccess {
dismissAllowingStateLoss()
}

@ -151,7 +151,7 @@ object DocumentUtils {
it.isDirectory,
it.length(),
Date(it.lastModified()),
Uri.parse(it.absolutePath)
Uri.fromFile(it)
)
if (filter == null || filter.invoke(item)) {
docList.add(item)
@ -169,7 +169,16 @@ data class FileDoc(
val date: Date,
val uri: Uri
) {
override fun toString(): String {
return if (uri.isContentScheme()) uri.toString() else uri.path!!
}
val isContentScheme get() = uri.isContentScheme()
fun readBytes(): ByteArray {
return uri.readBytes(appCtx)
}
}
@Throws(Exception::class)

Loading…
Cancel
Save