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)