背景配置自由添加

pull/371/head
gedoor 4 years ago
parent d9ce88b841
commit 21f941c64b
  1. 24
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  2. 13
      app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt

@ -31,7 +31,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
val callBack get() = activity as? ReadBookActivity
lateinit var styleAdapter: StyleAdapter
private lateinit var styleAdapter: StyleAdapter
override fun onStart() {
super.onStart()
@ -88,6 +88,18 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
dsb_paragraph_spacing.valueFormat = { (it / 10f).toString() }
styleAdapter = StyleAdapter()
rv_style.adapter = styleAdapter
val footerView = LayoutInflater.from(requireContext())
.inflate(R.layout.item_read_style, rv_style, false)
footerView.iv_style.setPadding(6.dp, 6.dp, 6.dp, 6.dp)
footerView.iv_style.setText(null)
footerView.iv_style.setColorFilter(textColor)
footerView.iv_style.borderColor = textColor
footerView.iv_style.setImageResource(R.drawable.ic_add)
styleAdapter.addFooterView(footerView)
footerView.onClick {
ReadBookConfig.configList.add(ReadBookConfig.Config())
showBgTextConfig(ReadBookConfig.configList.lastIndex)
}
}
private fun initData() {
@ -251,10 +263,16 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
override fun registerListener(holder: ItemViewHolder) {
holder.itemView.apply {
iv_style.onClick {
changeBg(holder.layoutPosition)
if (iv_style.isInView) {
changeBg(holder.layoutPosition)
}
}
iv_style.onLongClick {
showBgTextConfig(holder.layoutPosition)
if (iv_style.isInView) {
showBgTextConfig(holder.layoutPosition)
} else {
false
}
}
}
}

@ -119,6 +119,7 @@ class CircleImageView(context: Context, attrs: AttributeSet) :
private var textColor = context.getCompatColor(R.color.primaryText)
private var textBold = false
var isInView = false
init {
super.setScaleType(SCALE_TYPE)
@ -223,6 +224,11 @@ class CircleImageView(context: Context, attrs: AttributeSet) :
}
}
fun setText(text: String?) {
this.text = text
invalidate()
}
fun setTextColor(@ColorInt textColor: Int) {
this.textColor = textColor
invalidate()
@ -422,7 +428,12 @@ class CircleImageView(context: Context, attrs: AttributeSet) :
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
return inTouchableArea(event.x, event.y) && super.onTouchEvent(event)
when (event.action) {
MotionEvent.ACTION_DOWN -> {
isInView = (inTouchableArea(event.x, event.y))
}
}
return super.onTouchEvent(event)
}
private fun inTouchableArea(x: Float, y: Float): Boolean {

Loading…
Cancel
Save