Skip to content

Commit

Permalink
[UPD][ali.yuce][SampleView new styles added.]
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuce committed Oct 18, 2020
1 parent 4d43019 commit 4c90d25
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,40 @@ package com.labters.stylerdemo.components.sampleview

import android.content.Context
import android.util.AttributeSet
import com.labters.styler.core.StyleR
import com.labters.stylerdemo.BaseView
import com.labters.stylerdemo.R
import com.labters.stylerdemo.databinding.ViewSampleBinding

class SampleView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : BaseView<ViewSampleBinding>(context, attrs, defStyleAttr) {

companion object {
private const val STYLE_NORMAL = "SampleView"
private const val STYLE_REVERSE = "SampleView.Reverse"
private const val STYLE_HUGE = "SampleView.HugeHeader"
}

private var styleName = STYLE_NORMAL
set(value) {
field = value
applyStyleDif()
}

private fun applyStyleDif() {
StyleR.applyStyle(binding.root, styleName)
}

override fun initView() {
binding.run {

root.setOnClickListener {
styleName = when (styleName) {
STYLE_NORMAL -> STYLE_REVERSE
STYLE_REVERSE -> STYLE_HUGE
else -> STYLE_NORMAL
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,27 @@
"id": "tv_description",
"style": "AppText"
}
],
"SampleView.Reverse": [
{
"id": "tv_header",
"style": "AppText"
},
{
"id": "tv_description",
"style": "AppText.Header"
}
],
"SampleView.HugeHeader": [
{
"id": "tv_header",
"style": "AppText.Header",
"textSize": 60,
"textColor": "red"
},
{
"id": "tv_description",
"style": "AppText"
}
]
}
22 changes: 22 additions & 0 deletions app/src/main/res/raw/styler.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@
"id": "tv_description",
"style": "AppText"
}
],
"SampleView.Reverse": [
{
"id": "tv_header",
"style": "AppText"
},
{
"id": "tv_description",
"style": "AppText.Header"
}
],
"SampleView.HugeHeader": [
{
"id": "tv_header",
"style": "AppText.Header",
"textSize": 60,
"textColor": "red"
},
{
"id": "tv_description",
"style": "AppText"
}
]
,

Expand Down

0 comments on commit 4c90d25

Please sign in to comment.