pull/32/head
kunfei 5 years ago
parent 71d0b7ceb2
commit 0f7e071ff7
  1. 55
      app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt
  2. 6
      app/src/main/res/layout/dialog_read_bg_text.xml

@ -1,5 +1,6 @@
package io.legado.app.ui.readbook.config package io.legado.app.ui.readbook.config
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.Gravity import android.view.Gravity
@ -7,12 +8,21 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.DialogFragment 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.R
import io.legado.app.constant.Bus
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.readbook.Help import io.legado.app.ui.readbook.Help
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.dialog_read_bg_text.* 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( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -41,9 +51,52 @@ class BgTextConfigDialog : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
initData() initData()
initView()
} }
private fun initData() = with(ReadBookConfig.getConfig()) { private fun initData() = with(ReadBookConfig.getConfig()) {
sw_dark_status_icon.isChecked = statusIconDark() 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) {
}
} }

@ -21,7 +21,7 @@
android:padding="6dp"> android:padding="6dp">
<io.legado.app.lib.theme.view.ATEStrokeTextView <io.legado.app.lib.theme.view.ATEStrokeTextView
android:id="@+id/tvSelectTextColor" android:id="@+id/tv_text_color"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
@ -36,7 +36,7 @@
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
<io.legado.app.lib.theme.view.ATEStrokeTextView <io.legado.app.lib.theme.view.ATEStrokeTextView
android:id="@+id/tvSelectBgColor" android:id="@+id/tv_bg_color"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
@ -51,7 +51,7 @@
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
<io.legado.app.lib.theme.view.ATEStrokeTextView <io.legado.app.lib.theme.view.ATEStrokeTextView
android:id="@+id/tvDefault" android:id="@+id/tv_default"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"

Loading…
Cancel
Save