From 39ed24d4dccc6cefde2be8bd86a94df336f0d5c1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 7 Mar 2020 10:50:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 4 - .../ui/book/read/config/ReadStyleDialog.kt | 85 ++++++++----- .../app/ui/book/read/config/ReadTypeDialog.kt | 91 -------------- .../main/res/drawable/ic_type_default_1.xml | 12 -- .../main/res/drawable/ic_type_default_2.xml | 15 --- .../main/res/drawable/ic_type_default_3.xml | 18 --- .../res/layout/dialog_read_book_style.xml | 117 ++++++------------ app/src/main/res/layout/dialog_read_type.xml | 45 ------- .../main/res/layout/dialog_title_config.xml | 51 ++++++++ app/src/main/res/values/arrays.xml | 6 - app/src/main/res/values/strings.xml | 5 +- 11 files changed, 151 insertions(+), 298 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/book/read/config/ReadTypeDialog.kt delete mode 100644 app/src/main/res/drawable/ic_type_default_1.xml delete mode 100644 app/src/main/res/drawable/ic_type_default_2.xml delete mode 100644 app/src/main/res/drawable/ic_type_default_3.xml delete mode 100644 app/src/main/res/layout/dialog_read_type.xml create mode 100644 app/src/main/res/layout/dialog_title_config.xml diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index e85a0db31..de1f1d728 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -152,10 +152,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo PaddingConfigDialog().show(supportFragmentManager, "paddingConfig") } - fun showTypeConfig() { - ReadTypeDialog().show(supportFragmentManager, "readTypeDialog") - } - fun showBgTextConfig() { BgTextConfigDialog().show(supportFragmentManager, "bgTextConfig") } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 3c2bbb78a..9ba703ab1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read.config +import android.annotation.SuppressLint import android.content.DialogInterface import android.os.Bundle import android.util.DisplayMetrics @@ -13,6 +14,7 @@ import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig +import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.bottomBackground @@ -20,12 +22,10 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.font.FontSelectDialog -import io.legado.app.utils.getIndexById -import io.legado.app.utils.getPrefString -import io.legado.app.utils.postEvent -import io.legado.app.utils.putPrefString +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.dialog_read_book_style.* +import kotlinx.android.synthetic.main.dialog_title_config.view.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick @@ -33,7 +33,6 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { val callBack get() = activity as? ReadBookActivity - lateinit var titleModes: Array override fun onStart() { super.onStart() @@ -63,7 +62,6 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - titleModes = requireContext().resources.getStringArray(R.array.title_mode) initView() initData() initViewEvent() @@ -76,6 +74,14 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { private fun initView() { root_view.setBackgroundColor(requireContext().bottomBackground) + dsb_text_size.valueFormat = { + (it + 5).toString() + } + dsb_text_letter_spacing.valueFormat = { + ((it - 50) / 100f).toString() + } + dsb_line_size.valueFormat = { ((it - 10) / 10f).toString() } + dsb_paragraph_spacing.valueFormat = { (it / 10f).toString() } } private fun initData() { @@ -95,11 +101,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { postEvent(EventBus.UP_CONFIG, true) } tv_title_mode.onClick { - requireContext().selector("标题模式", titleModes.toList()) { _, index -> - ReadBookConfig.titleMode = index - tv_title_mode.text = titleModes[index] - postEvent(EventBus.UP_CONFIG, true) - } + showTitleConfig() } tv_text_bold.onClick { ReadBookConfig.apply { @@ -124,15 +126,9 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { dismiss() callBack?.showPaddingConfig() } - tv_type.onClick { - dismiss() - callBack?.showTypeConfig() - } rg_page_anim.onCheckedChange { _, checkedId -> - rg_page_anim.getIndexById(checkedId).let { - ReadBookConfig.pageAnim = it - callBack?.page_view?.upPageAnim() - } + ReadBookConfig.pageAnim = rg_page_anim.getIndexById(checkedId) + callBack?.page_view?.upPageAnim() } cb_share_layout.onCheckedChangeListener = { checkBox, isChecked -> if (checkBox.isPressed) { @@ -141,19 +137,20 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { postEvent(EventBus.UP_CONFIG, true) } } - iv_default1.onClick { - ReadBookConfig.lineSpacingExtra = 16 - ReadBookConfig.paragraphSpacing = 6 + dsb_text_size.onChanged = { + ReadBookConfig.textSize = it + 5 + postEvent(EventBus.UP_CONFIG, true) + } + dsb_text_letter_spacing.onChanged = { + ReadBookConfig.letterSpacing = (it - 50) / 100f postEvent(EventBus.UP_CONFIG, true) } - iv_default2.onClick { - ReadBookConfig.lineSpacingExtra = 13 - ReadBookConfig.paragraphSpacing = 3 + dsb_line_size.onChanged = { + ReadBookConfig.lineSpacingExtra = it postEvent(EventBus.UP_CONFIG, true) } - iv_default3.onClick { - ReadBookConfig.lineSpacingExtra = 10 - ReadBookConfig.paragraphSpacing = 0 + dsb_paragraph_spacing.onChanged = { + ReadBookConfig.paragraphSpacing = it postEvent(EventBus.UP_CONFIG, true) } bg0.onClick { changeBg(0) } @@ -168,6 +165,33 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { bg4.onLongClick { showBgTextConfig(4) } } + @SuppressLint("InflateParams") + private fun showTitleConfig() { + requireContext().alert(R.string.title) { + val rootView = LayoutInflater.from(requireContext()) + .inflate(R.layout.dialog_title_config, null).apply { + ReadBookConfig.apply { + rg_title_mode.checkByIndex(titleMode) + dsb_title_top.progress = titleTopSpacing + dsb_title_bottom.progress = titleBottomSpacing + rg_title_mode.onCheckedChange { _, checkedId -> + titleMode = rg_title_mode.getIndexById(checkedId) + postEvent(EventBus.UP_CONFIG, true) + } + dsb_title_top.onChanged = { + titleTopSpacing = it + postEvent(EventBus.UP_CONFIG, true) + } + dsb_title_bottom.onChanged = { + titleBottomSpacing = it + postEvent(EventBus.UP_CONFIG, true) + } + } + } + customView = rootView + }.show() + } + private fun changeBg(index: Int) { if (ReadBookConfig.styleSelect != index) { ReadBookConfig.styleSelect = index @@ -187,8 +211,11 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { private fun upStyle() { ReadBookConfig.let { - tv_title_mode.text = titleModes.getOrElse(it.titleMode) { titleModes[0] } tv_text_bold.isSelected = it.textBold + dsb_text_size.progress = it.textSize - 5 + dsb_text_letter_spacing.progress = (it.letterSpacing * 100).toInt() + 50 + dsb_line_size.progress = it.lineSpacingExtra + dsb_paragraph_spacing.progress = it.paragraphSpacing } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadTypeDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadTypeDialog.kt deleted file mode 100644 index c5247a455..000000000 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadTypeDialog.kt +++ /dev/null @@ -1,91 +0,0 @@ -package io.legado.app.ui.book.read.config - -import android.content.DialogInterface -import android.os.Bundle -import android.util.DisplayMetrics -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import io.legado.app.R -import io.legado.app.base.BaseDialogFragment -import io.legado.app.constant.EventBus -import io.legado.app.help.ReadBookConfig -import io.legado.app.ui.book.read.Help -import io.legado.app.utils.postEvent -import kotlinx.android.synthetic.main.dialog_read_type.* - -class ReadTypeDialog : BaseDialogFragment() { - - override fun onStart() { - super.onStart() - val dm = DisplayMetrics() - activity?.let { - Help.upSystemUiVisibility(it) - it.windowManager?.defaultDisplay?.getMetrics(dm) - } - dialog?.window?.let { - val attr = it.attributes - attr.dimAmount = 0.0f - it.attributes = attr - it.setLayout((dm.widthPixels * 0.9).toInt(), ViewGroup.LayoutParams.WRAP_CONTENT) - } - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return inflater.inflate(R.layout.dialog_read_type, container) - } - - override fun onDismiss(dialog: DialogInterface) { - super.onDismiss(dialog) - ReadBookConfig.save() - } - - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { - initView() - initViewEvent() - upStyle() - } - - private fun initView() { - dsb_text_size.valueFormat = { - (it + 5).toString() - } - dsb_text_letter_spacing.valueFormat = { - ((it - 50) / 100f).toString() - } - dsb_line_size.valueFormat = { ((it - 10) / 10f).toString() } - dsb_paragraph_spacing.valueFormat = { (it / 10f).toString() } - } - - private fun initViewEvent() { - dsb_text_size.onChanged = { - ReadBookConfig.textSize = it + 5 - postEvent(EventBus.UP_CONFIG, true) - } - dsb_text_letter_spacing.onChanged = { - ReadBookConfig.letterSpacing = (it - 50) / 100f - postEvent(EventBus.UP_CONFIG, true) - } - dsb_line_size.onChanged = { - ReadBookConfig.lineSpacingExtra = it - postEvent(EventBus.UP_CONFIG, true) - } - dsb_paragraph_spacing.onChanged = { - ReadBookConfig.paragraphSpacing = it - postEvent(EventBus.UP_CONFIG, true) - } - } - - private fun upStyle() { - ReadBookConfig.let { - dsb_text_size.progress = it.textSize - 5 - dsb_text_letter_spacing.progress = (it.letterSpacing * 100).toInt() + 50 - dsb_line_size.progress = it.lineSpacingExtra - dsb_paragraph_spacing.progress = it.paragraphSpacing - } - } -} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_type_default_1.xml b/app/src/main/res/drawable/ic_type_default_1.xml deleted file mode 100644 index 14d903eee..000000000 --- a/app/src/main/res/drawable/ic_type_default_1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - diff --git a/app/src/main/res/drawable/ic_type_default_2.xml b/app/src/main/res/drawable/ic_type_default_2.xml deleted file mode 100644 index a0c29bc99..000000000 --- a/app/src/main/res/drawable/ic_type_default_2.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/app/src/main/res/drawable/ic_type_default_3.xml b/app/src/main/res/drawable/ic_type_default_3.xml deleted file mode 100644 index feb07717f..000000000 --- a/app/src/main/res/drawable/ic_type_default_3.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/dialog_read_book_style.xml b/app/src/main/res/layout/dialog_read_book_style.xml index b11e6e9df..da110908f 100644 --- a/app/src/main/res/layout/dialog_read_book_style.xml +++ b/app/src/main/res/layout/dialog_read_book_style.xml @@ -27,7 +27,7 @@ android:paddingRight="6dp" android:paddingTop="4dp" android:paddingBottom="4dp" - android:text="@string/title_center" + android:text="@string/title" android:gravity="center" android:textSize="14sp" /> @@ -98,82 +98,6 @@ android:gravity="center" android:textSize="14sp" /> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + diff --git a/app/src/main/res/layout/dialog_read_type.xml b/app/src/main/res/layout/dialog_read_type.xml deleted file mode 100644 index c27a65f2d..000000000 --- a/app/src/main/res/layout/dialog_read_type.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_title_config.xml b/app/src/main/res/layout/dialog_title_config.xml new file mode 100644 index 000000000..4a2d35cd8 --- /dev/null +++ b/app/src/main/res/layout/dialog_title_config.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 15deecdec..104febad6 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -93,10 +93,4 @@ 系统等宽字体 - - 标题靠左 - 标题居中 - 标题隐藏 - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 368df1c1d..9bf3a423a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -620,7 +620,6 @@ 文本选择结束位置 文本选择开始位置 共用布局 - 标题居中 浏览器 导入默认规则 名称 @@ -634,4 +633,8 @@ 预设一 预设二 预设三 + 标题 + 靠左 + 居中 + 隐藏