2021-07-09 05:18:48 +02:00
|
|
|
package org.thoughtcrime.securesms.components
|
2019-12-18 11:36:09 +01:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.graphics.Canvas
|
|
|
|
import android.graphics.Paint
|
|
|
|
import android.graphics.Path
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.widget.RelativeLayout
|
|
|
|
import network.loki.messenger.R
|
2022-01-14 06:56:15 +01:00
|
|
|
import network.loki.messenger.databinding.ViewSeparatorBinding
|
2021-07-09 05:18:48 +02:00
|
|
|
import org.thoughtcrime.securesms.util.toPx
|
2021-01-15 05:36:30 +01:00
|
|
|
import org.session.libsession.utilities.ThemeUtil
|
2019-12-18 11:36:09 +01:00
|
|
|
|
2020-02-12 06:42:33 +01:00
|
|
|
class LabeledSeparatorView : RelativeLayout {
|
2019-12-18 11:36:09 +01:00
|
|
|
|
2022-01-14 06:56:15 +01:00
|
|
|
private lateinit var binding: ViewSeparatorBinding
|
2019-12-18 11:36:09 +01:00
|
|
|
private val path = Path()
|
|
|
|
|
2020-09-08 07:38:39 +02:00
|
|
|
private val paint: Paint by lazy {
|
2019-12-18 11:36:09 +01:00
|
|
|
val result = Paint()
|
|
|
|
result.style = Paint.Style.STROKE
|
2020-08-21 09:10:49 +02:00
|
|
|
result.color = ThemeUtil.getThemedColor(context, R.attr.dividerHorizontal)
|
2019-12-18 14:31:12 +01:00
|
|
|
result.strokeWidth = toPx(1, resources).toFloat()
|
2019-12-18 11:36:09 +01:00
|
|
|
result.isAntiAlias = true
|
|
|
|
result
|
2020-08-21 09:10:49 +02:00
|
|
|
}
|
2019-12-18 11:36:09 +01:00
|
|
|
|
|
|
|
// region Lifecycle
|
|
|
|
constructor(context: Context) : super(context) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setUpViewHierarchy() {
|
2022-01-14 06:56:15 +01:00
|
|
|
binding = ViewSeparatorBinding.inflate(LayoutInflater.from(context))
|
2019-12-18 11:36:09 +01:00
|
|
|
val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
2022-01-14 06:56:15 +01:00
|
|
|
addView(binding.root, layoutParams)
|
2019-12-18 11:36:09 +01:00
|
|
|
setWillNotDraw(false)
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Updating
|
|
|
|
override fun onDraw(c: Canvas) {
|
|
|
|
super.onDraw(c)
|
|
|
|
val w = width.toFloat()
|
|
|
|
val h = height.toFloat()
|
2020-08-21 09:10:49 +02:00
|
|
|
val hMargin = toPx(16, resources).toFloat()
|
2019-12-18 11:36:09 +01:00
|
|
|
path.reset()
|
|
|
|
path.moveTo(0.0f, h / 2)
|
2022-01-14 06:56:15 +01:00
|
|
|
path.lineTo(binding.titleTextView.left - hMargin, h / 2)
|
|
|
|
path.addRoundRect(binding.titleTextView.left - hMargin, toPx(1, resources).toFloat(), binding.titleTextView.right + hMargin, h - toPx(1, resources).toFloat(), h / 2, h / 2, Path.Direction.CCW)
|
|
|
|
path.moveTo(binding.titleTextView.right + hMargin, h / 2)
|
2019-12-18 11:36:09 +01:00
|
|
|
path.lineTo(w, h / 2)
|
|
|
|
path.close()
|
|
|
|
c.drawPath(path, paint)
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
}
|