更新Dialog界面与SCV控件
This commit is contained in:
10 files changed
+332
-142
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package io.legato.kazusa.base
|
package io.legato.kazusa.base
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.content.DialogInterface.OnDismissListener
|
import android.content.DialogInterface.OnDismissListener
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -8,11 +9,11 @@ import androidx.annotation.LayoutRes
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import io.legato.kazusa.R
|
import io.legato.kazusa.R
|
||||||
import io.legato.kazusa.constant.AppLog
|
import io.legato.kazusa.constant.AppLog
|
||||||
import io.legato.kazusa.help.config.AppConfig
|
import io.legato.kazusa.help.config.AppConfig
|
||||||
import io.legato.kazusa.help.coroutine.Coroutine
|
import io.legato.kazusa.help.coroutine.Coroutine
|
||||||
import io.legato.kazusa.lib.theme.ThemeStore
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
@@ -25,6 +26,17 @@ abstract class BaseDialogFragment(
|
|||||||
|
|
||||||
private var onDismissListener: OnDismissListener? = null
|
private var onDismissListener: OnDismissListener? = null
|
||||||
|
|
||||||
|
private lateinit var dialogView: View
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
dialogView = onCreateView(layoutInflater, null, savedInstanceState)!!
|
||||||
|
return MaterialAlertDialogBuilder(requireContext(), theme)
|
||||||
|
.setView(dialogView)
|
||||||
|
.create()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(): View? = dialogView
|
||||||
|
|
||||||
fun setOnDismissListener(onDismissListener: OnDismissListener?) {
|
fun setOnDismissListener(onDismissListener: OnDismissListener?) {
|
||||||
this.onDismissListener = onDismissListener
|
this.onDismissListener = onDismissListener
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import android.content.DialogInterface
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import io.legato.kazusa.R
|
import io.legato.kazusa.R
|
||||||
import io.legato.kazusa.base.BaseBottomSheetDialogFragment
|
import io.legato.kazusa.base.BaseDialogFragment
|
||||||
import io.legato.kazusa.constant.EventBus
|
import io.legato.kazusa.constant.EventBus
|
||||||
import io.legato.kazusa.databinding.DialogReadPaddingBinding
|
import io.legato.kazusa.databinding.DialogReadPaddingBinding
|
||||||
import io.legato.kazusa.help.config.ReadBookConfig
|
import io.legato.kazusa.help.config.ReadBookConfig
|
||||||
import io.legato.kazusa.utils.postEvent
|
import io.legato.kazusa.utils.postEvent
|
||||||
|
import io.legato.kazusa.utils.setLayout
|
||||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||||
|
|
||||||
class PaddingConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_padding) {
|
class PaddingConfigDialog : BaseDialogFragment(R.layout.dialog_read_padding) {
|
||||||
|
|
||||||
private val binding by viewBinding(DialogReadPaddingBinding::bind)
|
private val binding by viewBinding(DialogReadPaddingBinding::bind)
|
||||||
|
|
||||||
@@ -25,6 +26,11 @@ class PaddingConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_p
|
|||||||
ReadBookConfig.save()
|
ReadBookConfig.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
setLayout(0.9f, 0.9f)
|
||||||
|
}
|
||||||
|
|
||||||
private fun initData() = binding.run {
|
private fun initData() = binding.run {
|
||||||
//正文
|
//正文
|
||||||
dsbPaddingTop.progress = ReadBookConfig.paddingTop
|
dsbPaddingTop.progress = ReadBookConfig.paddingTop
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import io.legato.kazusa.databinding.ItemReadStyleBinding
|
|||||||
import io.legato.kazusa.help.config.AppConfig
|
import io.legato.kazusa.help.config.AppConfig
|
||||||
import io.legato.kazusa.help.config.ReadBookConfig
|
import io.legato.kazusa.help.config.ReadBookConfig
|
||||||
import io.legato.kazusa.help.config.ThemeConfig
|
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.lib.dialogs.selector
|
||||||
import io.legato.kazusa.model.ReadBook
|
import io.legato.kazusa.model.ReadBook
|
||||||
import io.legato.kazusa.ui.book.read.ReadBookActivity
|
import io.legato.kazusa.ui.book.read.ReadBookActivity
|
||||||
@@ -56,11 +57,7 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
|||||||
dsbTextSize.valueFormat = {
|
dsbTextSize.valueFormat = {
|
||||||
(it + 5).toString()
|
(it + 5).toString()
|
||||||
}
|
}
|
||||||
dsbTextLetterSpacing.valueFormat = {
|
|
||||||
((it - 50) / 100f).toString()
|
|
||||||
}
|
|
||||||
dsbLineSize.valueFormat = { ((it - 10) / 10f).toString() }
|
|
||||||
dsbParagraphSpacing.valueFormat = { (it / 10f).toString() }
|
|
||||||
styleAdapter = StyleAdapter()
|
styleAdapter = StyleAdapter()
|
||||||
rvStyle.adapter = styleAdapter
|
rvStyle.adapter = styleAdapter
|
||||||
styleAdapter.addFooterView {
|
styleAdapter.addFooterView {
|
||||||
@@ -76,6 +73,8 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
@@ -85,10 +84,18 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initViewEvent() = binding.run {
|
private fun initViewEvent() = binding.run {
|
||||||
chineseConverter.onChanged {
|
btnChineseConverter.setOnClickListener {
|
||||||
ChineseUtils.unLoad(*TransType.entries.toTypedArray())
|
alert(titleResource = R.string.chinese_converter) {
|
||||||
postEvent(EventBus.UP_CONFIG, arrayListOf(5))
|
items(resources.getStringArray(R.array.chinese_mode).toList()) { _, i ->
|
||||||
|
AppConfig.chineseConverterType = i
|
||||||
|
|
||||||
|
// 不需要更新文字,也不需要切换图标
|
||||||
|
ChineseUtils.unLoad(*TransType.entries.toTypedArray())
|
||||||
|
postEvent(EventBus.UP_CONFIG, arrayListOf(5))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textFontWeightConverter.onChanged {
|
textFontWeightConverter.onChanged {
|
||||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6))
|
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 9, 6))
|
||||||
}
|
}
|
||||||
@@ -149,17 +156,9 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
|||||||
ReadBookConfig.textSize = it + 5
|
ReadBookConfig.textSize = it + 5
|
||||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
||||||
}
|
}
|
||||||
dsbTextLetterSpacing.onChanged = {
|
|
||||||
ReadBookConfig.letterSpacing = (it - 50) / 100f
|
btnSpacing.setOnClickListener {
|
||||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
callBack?.showSpacingDialog()
|
||||||
}
|
|
||||||
dsbLineSize.onChanged = {
|
|
||||||
ReadBookConfig.lineSpacingExtra = it
|
|
||||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
|
||||||
}
|
|
||||||
dsbParagraphSpacing.onChanged = {
|
|
||||||
ReadBookConfig.paragraphSpacing = it
|
|
||||||
postEvent(EventBus.UP_CONFIG, arrayListOf(8, 5))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,9 +192,6 @@ class ReadStyleDialog : BaseBottomSheetDialogFragment(R.layout.dialog_read_book_
|
|||||||
}
|
}
|
||||||
ReadBookConfig.let {
|
ReadBookConfig.let {
|
||||||
dsbTextSize.progress = it.textSize - 5
|
dsbTextSize.progress = it.textSize - 5
|
||||||
dsbTextLetterSpacing.progress = (it.letterSpacing * 100).toInt() + 50
|
|
||||||
dsbLineSize.progress = it.lineSpacingExtra
|
|
||||||
dsbParagraphSpacing.progress = it.paragraphSpacing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ import android.util.AttributeSet
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.appcompat.widget.TooltipCompat
|
import androidx.appcompat.widget.TooltipCompat
|
||||||
import io.legato.kazusa.R
|
import io.legato.kazusa.R
|
||||||
import io.legato.kazusa.databinding.ViewSimpleCounterBinding
|
import io.legato.kazusa.databinding.ViewSimpleCounterBinding
|
||||||
import io.legato.kazusa.lib.dialogs.alert
|
import io.legato.kazusa.lib.dialogs.alert
|
||||||
|
import io.legato.kazusa.utils.gone
|
||||||
|
import io.legato.kazusa.utils.visible
|
||||||
|
|
||||||
@SuppressLint("ViewConstructor", "ClickableViewAccessibility")
|
@SuppressLint("ViewConstructor", "ClickableViewAccessibility")
|
||||||
class SimpleCounterView @JvmOverloads constructor(
|
class SimpleCounterView @JvmOverloads constructor(
|
||||||
@@ -20,7 +23,7 @@ class SimpleCounterView @JvmOverloads constructor(
|
|||||||
) : FrameLayout(context, attrs) {
|
) : FrameLayout(context, attrs) {
|
||||||
|
|
||||||
private val binding = ViewSimpleCounterBinding.inflate(LayoutInflater.from(context), this)
|
private val binding = ViewSimpleCounterBinding.inflate(LayoutInflater.from(context), this)
|
||||||
|
private var _orientation: Int = 1
|
||||||
private var _progress = 0
|
private var _progress = 0
|
||||||
private var _max = 100
|
private var _max = 100
|
||||||
private var _min = 0
|
private var _min = 0
|
||||||
@@ -36,6 +39,7 @@ class SimpleCounterView @JvmOverloads constructor(
|
|||||||
private val longPressDelay = 400L
|
private val longPressDelay = 400L
|
||||||
private val repeatInterval = 320L
|
private val repeatInterval = 320L
|
||||||
|
|
||||||
|
private val tvTit: TextView
|
||||||