pull/32/head
kunfei 5 years ago
parent 0f7e071ff7
commit cd7620943b
  1. 25
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 31
      app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt

@ -13,6 +13,7 @@ import android.view.WindowManager
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
@ -20,6 +21,7 @@ import io.legado.app.constant.Status
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.dialogs.okButton
@ -28,6 +30,8 @@ import io.legado.app.service.ReadAloudService
import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.ui.readbook.config.* import io.legado.app.ui.readbook.config.*
import io.legado.app.ui.readbook.config.BgTextConfigDialog.Companion.BG_COLOR
import io.legado.app.ui.readbook.config.BgTextConfigDialog.Companion.TEXT_COLOR
import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity
import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.ui.sourceedit.SourceEditActivity
import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.ui.widget.page.ChapterProvider
@ -42,6 +46,7 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import okhttp3.internal.toHexString
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
@ -50,7 +55,8 @@ import org.jetbrains.anko.toast
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book), class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book),
PageView.CallBack, PageView.CallBack,
ChangeSourceDialog.CallBack, ChangeSourceDialog.CallBack,
ReadBookViewModel.CallBack { ReadBookViewModel.CallBack,
ColorPickerDialogListener {
override val viewModel: ReadBookViewModel override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java) get() = getViewModel(ReadBookViewModel::class.java)
@ -430,6 +436,23 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
window.attributes = params window.attributes = params
} }
override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.getConfig()) {
when (dialogId) {
TEXT_COLOR -> {
setTextColor(color)
postEvent(Bus.UP_CONFIG, false)
}
BG_COLOR -> {
setBg(0, "#${color.toHexString()}")
postEvent(Bus.UP_CONFIG, false)
}
}
}
override fun onDialogDismissed(dialogId: Int) {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {

@ -9,20 +9,18 @@ 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.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 import org.jetbrains.anko.sdk27.listeners.onClick
class BgTextConfigDialog : DialogFragment(), ColorPickerDialogListener { class BgTextConfigDialog : DialogFragment() {
val selectTextColor = 121 companion object {
val selectBgColor = 122 const val TEXT_COLOR = 121
const val BG_COLOR = 122
}
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -64,7 +62,7 @@ class BgTextConfigDialog : DialogFragment(), ColorPickerDialogListener {
.setColor(textColor()) .setColor(textColor())
.setShowAlphaSlider(false) .setShowAlphaSlider(false)
.setDialogType(ColorPickerDialog.TYPE_CUSTOM) .setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setDialogId(selectTextColor) .setDialogId(TEXT_COLOR)
.show(requireActivity()) .show(requireActivity())
} }
tv_bg_color.onClick { tv_bg_color.onClick {
@ -75,7 +73,7 @@ class BgTextConfigDialog : DialogFragment(), ColorPickerDialogListener {
.setColor(bgColor) .setColor(bgColor)
.setShowAlphaSlider(false) .setShowAlphaSlider(false)
.setDialogType(ColorPickerDialog.TYPE_CUSTOM) .setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setDialogId(selectTextColor) .setDialogId(TEXT_COLOR)
.show(requireActivity()) .show(requireActivity())
} }
tv_default.onClick { tv_default.onClick {
@ -83,20 +81,5 @@ class BgTextConfigDialog : DialogFragment(), ColorPickerDialogListener {
} }
} }
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) {
} }
}
Loading…
Cancel
Save