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

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

Loading…
Cancel
Save