feat: 优化代码

pull/141/head
kunfei 5 years ago
parent 9a46411a37
commit a2bde00a9e
  1. 9
      app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt

@ -9,6 +9,7 @@ import io.legado.app.utils.invisible
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_font.view.* import kotlinx.android.synthetic.main.item_font.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.toast
import java.io.File import java.io.File
class FontAdapter(context: Context, val callBack: CallBack) : class FontAdapter(context: Context, val callBack: CallBack) :
@ -16,8 +17,12 @@ class FontAdapter(context: Context, val callBack: CallBack) :
override fun convert(holder: ItemViewHolder, item: File, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: File, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {
val typeface = Typeface.createFromFile(item) try {
tv_font.typeface = typeface val typeface = Typeface.createFromFile(item)
tv_font.typeface = typeface
} catch (e: Exception) {
context.toast("读取${item.name}字体失败")
}
tv_font.text = item.name tv_font.text = item.name
this.onClick { callBack.onClick(item) } this.onClick { callBack.onClick(item) }
if (item.name == callBack.curFilePath.substringAfterLast(File.separator)) { if (item.name == callBack.curFilePath.substringAfterLast(File.separator)) {

Loading…
Cancel
Save