修复选择字体时有重复字体的问题

pull/475/head
gedoor 4 years ago
parent 652e519f64
commit c141a1fb26
  1. 28
      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<DocItem>,
items2: ArrayList<DocItem>
): ArrayList<DocItem> {
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)

Loading…
Cancel
Save