pull/32/head
kunfei 5 years ago
parent 9dc54f52e1
commit 5cb6c445e3
  1. 34
      app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt
  2. 52
      app/src/main/res/layout/dialog_font_select.xml
  3. 27
      app/src/main/res/layout/item_font.xml

@ -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<File>(context, R.layout.item_font) {
override fun convert(holder: ItemViewHolder, item: File, payloads: MutableList<Any>) =
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
}
}

@ -1,7 +1,53 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:padding="16dp">
</LinearLayout> <TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="16sp"
android:text="@string/select_font"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/tv_title"
app:layout_constraintBottom_toTopOf="@+id/tv_font_default" />
<TextView
android:id="@+id/tv_no_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/fonts_folder"
app:layout_constraintTop_toBottomOf="@+id/tv_title"
app:layout_constraintBottom_toTopOf="@+id/tv_font_default" />
<TextView
android:id="@+id/tv_font_default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="@string/default_font"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="@string/cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_font_default" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="@+id/tv_font"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:textColor="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_checked"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_check"
android:visibility="invisible"
app:tint="@color/tv_text_default" />
</LinearLayout>
Loading…
Cancel
Save