From c141a1fb265b43bf54b30adc9aa2d27f2f2eb1db Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 13 Nov 2020 11:30:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=89=E6=8B=A9=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E6=97=B6=E6=9C=89=E9=87=8D=E5=A4=8D=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/widget/font/FontSelectDialog.kt | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 5a8134c43..3c4716d56 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -28,6 +28,7 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import java.io.File import java.util.* +import kotlin.collections.ArrayList class FontSelectDialog : BaseDialogFragment(), FilePickerDialog.CallBack, @@ -150,8 +151,7 @@ class FontSelectDialog : BaseDialogFragment(), fontItems.add(item) } } - fontItems.addAll(getLocalFonts()) - fontItems.sortedBy { it.name } + mergeFontItems(fontItems, getLocalFonts()) }.onSuccess { adapter?.setItems(it) }.onError { @@ -186,8 +186,7 @@ class FontSelectDialog : BaseDialogFragment(), ) ) } - fontItems.addAll(getLocalFonts()) - fontItems.sortedBy { it.name } + mergeFontItems(fontItems, getLocalFonts()) }.onSuccess { adapter?.setItems(it) }.onError { @@ -195,6 +194,27 @@ class FontSelectDialog : BaseDialogFragment(), } } + private fun mergeFontItems( + items1: ArrayList, + items2: ArrayList + ): ArrayList { + val items = ArrayList(items1) + items2.forEach { item2 -> + var isInFirst = false + items1.forEach for1@{ item1 -> + if (item2.name == item1.name) { + isInFirst = true + return@for1 + } + } + if (!isInFirst) { + items.add(item2) + } + } + items.sortBy { it.name } + return items + } + override fun onClick(docItem: DocItem) { execute { FileUtils.deleteFile(fontFolder.absolutePath)