From dea2ca2edf650733f76b266504543a2957ad8d3e Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 23 Oct 2021 21:18:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/font/FontAdapter.kt | 8 ++++---- .../java/io/legado/app/ui/font/FontSelectDialog.kt | 4 ++-- .../java/io/legado/app/utils/DocumentExtensions.kt | 11 ++++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/font/FontAdapter.kt index 832666b9e..31bc06f1f 100644 --- a/app/src/main/java/io/legado/app/ui/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/font/FontAdapter.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) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/font/FontSelectDialog.kt index 152a8ca31..d89f8fab5 100644 --- a/app/src/main/java/io/legado/app/ui/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/font/FontSelectDialog.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/utils/DocumentExtensions.kt b/app/src/main/java/io/legado/app/utils/DocumentExtensions.kt index db0ab5279..be1e6720f 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentExtensions.kt @@ -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)