From 0f7e071ff7c88d9aadb33b0cf9be43cbbdf25eff Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 30 Aug 2019 23:01:59 +0800 Subject: [PATCH] up --- .../ui/readbook/config/BgTextConfigDialog.kt | 55 ++++++++++++++++++- .../main/res/layout/dialog_read_bg_text.xml | 6 +- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt index d1ee637d4..3e72e6df6 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.readbook.config +import android.graphics.Color import android.os.Bundle import android.util.DisplayMetrics import android.view.Gravity @@ -7,12 +8,21 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment +import com.jaredrummler.android.colorpicker.ColorPickerDialog +import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import io.legado.app.R +import io.legado.app.constant.Bus import io.legado.app.help.ReadBookConfig import io.legado.app.ui.readbook.Help +import io.legado.app.utils.postEvent import kotlinx.android.synthetic.main.dialog_read_bg_text.* +import okhttp3.internal.toHexString +import org.jetbrains.anko.sdk27.listeners.onClick -class BgTextConfigDialog : DialogFragment() { +class BgTextConfigDialog : DialogFragment(), ColorPickerDialogListener { + + val selectTextColor = 121 + val selectBgColor = 122 override fun onCreateView( inflater: LayoutInflater, @@ -41,9 +51,52 @@ class BgTextConfigDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) initData() + initView() } private fun initData() = with(ReadBookConfig.getConfig()) { sw_dark_status_icon.isChecked = statusIconDark() } + + private fun initView() = with(ReadBookConfig.getConfig()) { + tv_text_color.onClick { + ColorPickerDialog.newBuilder() + .setColor(textColor()) + .setShowAlphaSlider(false) + .setDialogType(ColorPickerDialog.TYPE_CUSTOM) + .setDialogId(selectTextColor) + .show(requireActivity()) + } + tv_bg_color.onClick { + val bgColor = + if (bgType() == 0) Color.parseColor(bgStr()) + else Color.parseColor("#015A86") + ColorPickerDialog.newBuilder() + .setColor(bgColor) + .setShowAlphaSlider(false) + .setDialogType(ColorPickerDialog.TYPE_CUSTOM) + .setDialogId(selectTextColor) + .show(requireActivity()) + } + tv_default.onClick { + + } + } + + override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.getConfig()) { + when (dialogId) { + selectTextColor -> { + setTextColor(color) + postEvent(Bus.UP_CONFIG, false) + } + selectBgColor -> { + setBg(0, "#${color.toHexString()}") + postEvent(Bus.UP_CONFIG, false) + } + } + } + + override fun onDialogDismissed(dialogId: Int) { + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_read_bg_text.xml b/app/src/main/res/layout/dialog_read_bg_text.xml index 073e9b720..b1d5df162 100644 --- a/app/src/main/res/layout/dialog_read_bg_text.xml +++ b/app/src/main/res/layout/dialog_read_bg_text.xml @@ -21,7 +21,7 @@ android:padding="6dp">