VancedManager/app/src/main/java/com/vanced/manager/ui/core/PreferenceCategory.kt

38 lines
1.2 KiB
Kotlin
Raw Normal View History

2020-10-31 19:45:39 +00:00
package com.vanced.manager.ui.core
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.vanced.manager.R
import com.vanced.manager.databinding.ViewPreferenceCategoryBinding
2020-10-31 19:45:39 +00:00
class PreferenceCategory @JvmOverloads constructor(
2021-01-15 14:24:07 +00:00
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
2020-10-31 19:45:39 +00:00
) : LinearLayout(context, attrs, defStyle) {
private var _binding: ViewPreferenceCategoryBinding? = null
val binding: ViewPreferenceCategoryBinding
get() = requireNotNull(_binding)
2020-10-31 19:45:39 +00:00
init {
_binding = ViewPreferenceCategoryBinding.inflate(LayoutInflater.from(context), this, true)
2020-10-31 19:45:39 +00:00
initAttrs(context, attrs)
setPadding(0, 4, 0, 0)
orientation = VERTICAL
}
private fun initAttrs(context: Context, attrs: AttributeSet?) {
attrs.let { mAttrs ->
val typedArray = context.obtainStyledAttributes(mAttrs, R.styleable.PreferenceCategory, 0, 0)
val title = typedArray.getText(R.styleable.PreferenceCategory_category_title)
binding.categoryTitle.text = title
2020-10-31 19:45:39 +00:00
typedArray.recycle()
}
}
}