From 5cb6c445e3c35e27516708974b6946e155e906e5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 29 Aug 2019 13:46:51 +0800 Subject: [PATCH] up --- .../legado/app/ui/widget/font/FontAdapter.kt | 34 ++++++++++++ .../main/res/layout/dialog_font_select.xml | 52 +++++++++++++++++-- app/src/main/res/layout/item_font.xml | 27 ++++++++++ 3 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt create mode 100644 app/src/main/res/layout/item_font.xml diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt new file mode 100644 index 000000000..44f4f9974 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -0,0 +1,34 @@ +package io.legado.app.ui.widget.font + +import android.content.Context +import android.graphics.Typeface +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.utils.invisible +import io.legado.app.utils.visible +import kotlinx.android.synthetic.main.item_font.view.* +import org.jetbrains.anko.sdk27.listeners.onClick +import java.io.File + +class FontAdapter(context: Context, val callBack: CallBack) : + SimpleRecyclerAdapter(context, R.layout.item_font) { + + override fun convert(holder: ItemViewHolder, item: File, payloads: MutableList) = + with(holder.itemView) { + val typeface = Typeface.createFromFile(item) + tv_font.typeface = typeface + tv_font.text = item.name + this.onClick { callBack.onClick(item) } + if (item.absolutePath == callBack.curFilePath()) { + iv_checked.visible() + } else { + iv_checked.invisible() + } + } + + interface CallBack { + fun onClick(file: File) + fun curFilePath(): String + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_font_select.xml b/app/src/main/res/layout/dialog_font_select.xml index d829e291c..3e47640d2 100644 --- a/app/src/main/res/layout/dialog_font_select.xml +++ b/app/src/main/res/layout/dialog_font_select.xml @@ -1,7 +1,53 @@ - + android:layout_height="wrap_content" + android:padding="16dp"> - \ No newline at end of file + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_font.xml b/app/src/main/res/layout/item_font.xml new file mode 100644 index 000000000..24c9be27e --- /dev/null +++ b/app/src/main/res/layout/item_font.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file