重新设计界面设置布局
This commit is contained in:
@@ -507,7 +507,7 @@ object ReadBookConfig {
|
||||
private var pageAnim: Int = 0,//翻页动画
|
||||
private var pageAnimEInk: Int = 4,
|
||||
var textFont: String = "",//字体
|
||||
var textBold: Int = 0,//是否粗体字 0:正常, 1:粗体, 2:细体
|
||||
var textBold: Int = 500,//是否粗体字 0:正常, 1:粗体, 2:细体
|
||||
var textSize: Int = 20,//文字大小
|
||||
var letterSpacing: Float = 0.1f,//字间距
|
||||
var lineSpacingExtra: Int = 12,//行间距
|
||||
|
||||
@@ -34,7 +34,6 @@ import io.legato.kazusa.ui.book.read.config.BgTextConfigDialog
|
||||
import io.legato.kazusa.ui.book.read.config.ClickActionConfigDialog
|
||||
import io.legato.kazusa.ui.book.read.config.PaddingConfigDialog
|
||||
import io.legato.kazusa.ui.book.read.config.PageKeyDialog
|
||||
import io.legato.kazusa.ui.book.read.config.ReadSpacingDialog
|
||||
import io.legato.kazusa.ui.file.HandleFileContract
|
||||
import io.legato.kazusa.utils.ColorUtils
|
||||
import io.legato.kazusa.utils.FileDoc
|
||||
@@ -125,10 +124,6 @@ abstract class BaseReadBookActivity :
|
||||
|
||||
}
|
||||
|
||||
fun showSpacingDialog() {
|
||||
showDialogFragment<ReadSpacingDialog>()
|
||||
}
|
||||
|
||||
fun showPaddingConfig() {
|
||||
showDialogFragment<PaddingConfigDialog>()
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package io.legato.kazusa.ui.book.read.config
|
||||
|
||||
import android.content.Context
|
||||
import android.text.SpannableString
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.lib.dialogs.alert
|
||||
//import io.legado.app.lib.theme.accentColor
|
||||
import io.legato.kazusa.ui.widget.text.StrokeTextView
|
||||
|
||||
|
||||
class ChineseConverter(context: Context, attrs: AttributeSet?) : MaterialButton(context, attrs) {
|
||||
|
||||
private val spannableString = SpannableString("简/繁")
|
||||
private var onChanged: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
text = spannableString
|
||||
if (!isInEditMode) {
|
||||
upUi(AppConfig.chineseConverterType)
|
||||
}
|
||||
setOnClickListener {
|
||||
selectType()
|
||||
}
|
||||
}
|
||||
|
||||
private fun upUi(type: Int) {
|
||||
val showOptions = context.resources.getStringArray(R.array.chinese_mode)
|
||||
text = showOptions.getOrNull(type) ?: ""
|
||||
}
|
||||
|
||||
private fun selectType() {
|
||||
context.alert(titleResource = R.string.chinese_converter) {
|
||||
items(context.resources.getStringArray(R.array.chinese_mode).toList()) { _, i ->
|
||||
AppConfig.chineseConverterType = i
|
||||
upUi(i)
|
||||
onChanged?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onChanged(unit: () -> Unit) {
|
||||
onChanged = unit
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package io.legato.kazusa.ui.book.read.config
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.base.BaseBottomSheetDialogFragment
|
||||
import io.legato.kazusa.constant.EventBus
|
||||
import io.legato.kazusa.databinding.DialogReadBookSpacingBinding
|
||||
import io.legato.kazusa.help.config.ReadBookConfig
|
||||
import io.legato.kazusa.ui.book.read.ReadBookActivity
|
||||
import io.legato.kazusa.utils.postEvent
|
||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class ReadSpacingDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_spacing) {
|
||||
|
||||
private val binding by viewBinding(DialogReadBookSpacingBinding::bind)
|
||||
private val callBack get() = activity as? ReadBookActivity
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
(activity as ReadBookActivity).bottomDialog++
|
||||
initView()
|
||||
upView()
|
||||
initViewEvent()
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
super.onDismiss(dialog)
|
||||
ReadBookConfig.save()
|
||||
(activity as ReadBookActivity).bottomDialog--
|
||||
}
|
||||
|
||||
private fun initView() = binding.run {
|
||||
dsbTextLetterSpacing.valueFormat = {
|
||||
((it - 50) / 100f).toString()
|
||||
}
|
||||
dsbLineSize.valueFormat = { ((it - 10) / 10f).toString() }
|
||||
dsbParagraphSpacing.valueFormat = { (it / 10f).toString() }
|
||||
}
|
||||
|
||||
private fun initViewEvent() = binding.run {
|
||||
dsbTextLetterSpacing.onChanged = {
|
||||
ReadBookConfig.letterSpacing = (it - 50) / 100f
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||
}
|
||||
dsbLineSize.onChanged = {
|
||||
ReadBookConfig.lineSpacingExtra = it
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||
}
|
||||
dsbParagraphSpacing.onChanged = {
|
||||
ReadBookConfig.paragraphSpacing = it
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||
}
|
||||
}
|
||||
|
||||
private fun upView() = binding.run {
|
||||
ReadBookConfig.let {
|
||||
dsbTextLetterSpacing.progress = (it.letterSpacing * 100).toInt() + 50
|
||||
dsbLineSize.progress = it.lineSpacingExtra
|
||||
dsbParagraphSpacing.progress = it.paragraphSpacing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,8 @@ import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.help.config.ReadBookConfig
|
||||
import io.legato.kazusa.help.config.ThemeConfig
|
||||
import io.legato.kazusa.lib.dialogs.alert
|
||||
import io.legato.kazusa.lib.dialogs.selector
|
||||
import io.legato.kazusa.model.ReadBook
|
||||
import io.legato.kazusa.ui.book.read.ReadBookActivity
|
||||
import io.legato.kazusa.ui.font.FontSelectDialog
|
||||
import io.legato.kazusa.utils.ChineseUtils
|
||||
import io.legato.kazusa.utils.dpToPx
|
||||
import io.legato.kazusa.utils.postEvent
|
||||
@@ -96,21 +94,9 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
||||
}
|
||||
}
|
||||
|
||||
textFontWeightConverter.onChanged {
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6))
|
||||
}
|
||||
tvTextFont.setOnClickListener {
|
||||
showDialogFragment<FontSelectDialog>()
|
||||
}
|
||||
tvTextIndent.setOnClickListener {
|
||||
context?.selector(
|
||||
title = getString(R.string.text_indent),
|
||||
items = resources.getStringArray(R.array.indent).toList()
|
||||
) { _, index ->
|
||||
ReadBookConfig.paragraphIndent = " ".repeat(index)
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||
}
|
||||
}
|
||||
tvPadding.setOnClickListener {
|
||||
dismissAllowingStateLoss()
|
||||
callBack?.showPaddingConfig()
|
||||
@@ -156,10 +142,6 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
||||
ReadBookConfig.textSize = it + 5
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||
}
|
||||
|
||||
btnSpacing.setOnClickListener {
|
||||
callBack?.showSpacingDialog()
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeBgTextConfig(index: Int) {
|
||||
@@ -184,7 +166,6 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
||||
}
|
||||
|
||||
private fun upView() = binding.run {
|
||||
textFontWeightConverter.upUi(ReadBookConfig.textBold)
|
||||
ReadBook.pageAnim().let {
|
||||
if (it >= 0 && it < rgPageAnim.childCount) {
|
||||
rgPageAnim.check(rgPageAnim[it].id)
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package io.legato.kazusa.ui.book.read.config
|
||||
|
||||
import android.content.Context
|
||||
import android.text.SpannableString
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.help.config.ReadBookConfig
|
||||
import io.legato.kazusa.lib.dialogs.alert
|
||||
//import io.legado.app.lib.theme.accentColor
|
||||
import io.legato.kazusa.ui.widget.text.StrokeTextView
|
||||
|
||||
|
||||
class TextFontWeightConverter(context: Context, attrs: AttributeSet?) :
|
||||
MaterialButton(context, attrs) {
|
||||
|
||||
private val spannableString = SpannableString(context.getString(R.string.font_weight_text))
|
||||
private var onChanged: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
text = spannableString
|
||||
if (!isInEditMode) {
|
||||
upUi(ReadBookConfig.textBold)
|
||||
}
|
||||
setOnClickListener {
|
||||
selectType()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
fun upUi(type: Int) {
|
||||
val weightOptions = context.resources.getStringArray(R.array.text_font_weight)
|
||||
text = weightOptions.getOrNull(type) ?: ""
|
||||
}
|
||||
|
||||
private fun selectType() {
|
||||
context.alert(titleResource = R.string.text_font_weight_converter) {
|
||||
items(context.resources.getStringArray(R.array.text_font_weight).toList()) { _, i ->
|
||||
ReadBookConfig.textBold = i
|
||||
upUi(i)
|
||||
onChanged?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onChanged(unit: () -> Unit) {
|
||||
onChanged = unit
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package io.legato.kazusa.ui.font
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.view.ViewGroup
|
||||
import io.legato.kazusa.base.adapter.ItemViewHolder
|
||||
import io.legato.kazusa.base.adapter.RecyclerAdapter
|
||||
import io.legato.kazusa.constant.AppLog
|
||||
import io.legato.kazusa.databinding.ItemFontBinding
|
||||
import io.legato.kazusa.utils.*
|
||||
import java.io.File
|
||||
import java.net.URLDecoder
|
||||
|
||||
class FontAdapter(context: Context, curFilePath: String, val callBack: CallBack) :
|
||||
RecyclerAdapter<FileDoc, ItemFontBinding>(context) {
|
||||
|
||||
private val curName = kotlin.runCatching {
|
||||
URLDecoder.decode(curFilePath, "utf-8")
|
||||
}.getOrNull()?.substringAfterLast(File.separator)
|
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemFontBinding {
|
||||
return ItemFontBinding.inflate(inflater, parent, false)
|
||||
}
|
||||
|
||||
override fun convert(
|
||||
holder: ItemViewHolder,
|
||||
binding: ItemFontBinding,
|
||||
item: FileDoc,
|
||||
payloads: MutableList<Any>
|
||||
) {
|
||||
binding.run {
|
||||
kotlin.runCatching {
|
||||
val typeface: Typeface? = if (item.isContentScheme) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.contentResolver
|
||||
.openFileDescriptor(item.uri, "r")?.use {
|
||||
Typeface.Builder(it.fileDescriptor).build()
|
||||
}
|
||||
} else {
|
||||
Typeface.createFromFile(RealPathUtil.getPath(context, item.uri))
|
||||
}
|
||||
} else {
|
||||
Typeface.createFromFile(item.uri.path!!)
|
||||
}
|
||||
tvFont.typeface = typeface
|
||||
}.onFailure {
|
||||
it.printOnDebug()
|
||||
AppLog.put("读取字体 ${item.name} 出错\n${it.localizedMessage}", it, true)
|
||||
}
|
||||
tvFont.text = item.name
|
||||
root.setOnClickListener { callBack.onFontSelect(item) }
|
||||
if (item.name == curName) {
|
||||
ivChecked.visible()
|
||||
} else {
|
||||
ivChecked.invisible()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemFontBinding) {
|
||||
holder.itemView.setOnClickListener {
|
||||
getItem(holder.layoutPosition)?.let {
|
||||
callBack.onFontSelect(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface CallBack {
|
||||
fun onFontSelect(docItem: FileDoc)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user