From 44030aedfbb4da267e6af450024f9332c0e28315 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 21 Aug 2019 15:27:39 +0800 Subject: [PATCH] up --- .../app/ui/readbook/ReadBookActivity.kt | 3 +- .../{ReadStylePopup.kt => ReadStyleDialog.kt} | 55 ++++++++++--------- .../legado/app/ui/widget/KeyboardToolPop.kt | 2 +- ...k_style.xml => dialog_read_book_style.xml} | 0 ...board_tool.xml => popup_keyboard_tool.xml} | 0 5 files changed, 32 insertions(+), 28 deletions(-) rename app/src/main/java/io/legado/app/ui/readbook/config/{ReadStylePopup.kt => ReadStyleDialog.kt} (50%) rename app/src/main/res/layout/{pop_read_book_style.xml => dialog_read_book_style.xml} (100%) rename app/src/main/res/layout/{pop_keyboard_tool.xml => popup_keyboard_tool.xml} (100%) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 993f20c2b..07b5b3002 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -19,6 +19,7 @@ import io.legado.app.receiver.TimeElectricityReceiver import io.legado.app.service.ReadAloudService import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity +import io.legado.app.ui.readbook.config.ReadStyleDialog import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.ui.widget.page.PageView @@ -160,7 +161,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } override fun showReadStyle() { - + ReadStyleDialog().show(supportFragmentManager, "readStyle") } override fun showMoreSetting() { diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt similarity index 50% rename from app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt rename to app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt index 5a3931388..3c3b40633 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStylePopup.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt @@ -1,59 +1,62 @@ package io.legado.app.ui.readbook.config -import android.annotation.SuppressLint -import android.content.Context +import android.os.Bundle import android.view.LayoutInflater -import android.widget.PopupWindow +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.constant.Bus import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.postEvent -import kotlinx.android.synthetic.main.pop_read_book_style.view.* +import kotlinx.android.synthetic.main.dialog_read_book_style.* import org.jetbrains.anko.sdk27.listeners.onClick -class ReadStylePopup(context: Context?) : PopupWindow(context) { +class ReadStyleDialog : DialogFragment() { - init { - @SuppressLint("InflateParams") - contentView = LayoutInflater.from(context).inflate(R.layout.pop_read_book_style, null) + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.dialog_read_book_style, container) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) initData() initOnClick() } - private fun initData() = with(contentView) { + private fun initData() { upBg() } - private fun initOnClick() = with(contentView) { - bg0.onClick { + private fun initOnClick() { + tv_bg0.onClick { ReadBookConfig.styleSelect = 0 ReadBookConfig.upBg() upBg() postEvent(Bus.UP_CONFIG, 0) } - bg1.onClick { + tv_bg1.onClick { ReadBookConfig.styleSelect = 1 ReadBookConfig.upBg() upBg() postEvent(Bus.UP_CONFIG, 0) } - bg2.onClick { + tv_bg2.onClick { ReadBookConfig.styleSelect = 2 ReadBookConfig.upBg() upBg() postEvent(Bus.UP_CONFIG, 0) } - bg3.onClick { + tv_bg3.onClick { ReadBookConfig.styleSelect = 3 ReadBookConfig.upBg() upBg() postEvent(Bus.UP_CONFIG, 0) } - bg4.onClick { + tv_bg4.onClick { ReadBookConfig.styleSelect = 4 ReadBookConfig.upBg() upBg() @@ -61,27 +64,27 @@ class ReadStylePopup(context: Context?) : PopupWindow(context) { } } - private fun upBg() = with(contentView) { - bg0.borderColor = context.primaryTextColor - bg1.borderColor = context.primaryTextColor - bg2.borderColor = context.primaryTextColor - bg3.borderColor = context.primaryTextColor - bg4.borderColor = context.primaryTextColor + private fun upBg() { + bg0.borderColor = requireContext().primaryTextColor + bg1.borderColor = requireContext().primaryTextColor + bg2.borderColor = requireContext().primaryTextColor + bg3.borderColor = requireContext().primaryTextColor + bg4.borderColor = requireContext().primaryTextColor when (ReadBookConfig.styleSelect) { 1 -> { - bg1.borderColor = context.accentColor + bg1.borderColor = requireContext().accentColor } 2 -> { - bg2.borderColor = context.accentColor + bg2.borderColor = requireContext().accentColor } 3 -> { - bg3.borderColor = context.accentColor + bg3.borderColor = requireContext().accentColor } 4 -> { - bg4.borderColor = context.accentColor + bg4.borderColor = requireContext().accentColor } else -> { - bg0.borderColor = context.accentColor + bg0.borderColor = requireContext().accentColor } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt index f75e01a1b..b97e32e97 100644 --- a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt +++ b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt @@ -14,7 +14,7 @@ class KeyboardToolPop(context: Context, onClickListener: OnClickListener?) : Pop init { @SuppressLint("InflateParams") - val view = LayoutInflater.from(context).inflate(R.layout.pop_keyboard_tool, null) + val view = LayoutInflater.from(context).inflate(R.layout.popup_keyboard_tool, null) this.contentView = view isTouchable = true diff --git a/app/src/main/res/layout/pop_read_book_style.xml b/app/src/main/res/layout/dialog_read_book_style.xml similarity index 100% rename from app/src/main/res/layout/pop_read_book_style.xml rename to app/src/main/res/layout/dialog_read_book_style.xml diff --git a/app/src/main/res/layout/pop_keyboard_tool.xml b/app/src/main/res/layout/popup_keyboard_tool.xml similarity index 100% rename from app/src/main/res/layout/pop_keyboard_tool.xml rename to app/src/main/res/layout/popup_keyboard_tool.xml