aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/EmbeddedMenuLayout.kt
blob: 726bc68bffa37058bc67ef3b2782a1934a804cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package net.lacolaco.smileessence.view

import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.menu_item_simple_text.view.*
import net.lacolaco.smileessence.R

class EmbeddedMenuLayout : LinearLayout {
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) :
            super(context, attrs, defStyleAttr, defStyleRes)

    @JvmOverloads
    constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
            super(context, attrs, defStyleAttr)

    init {
        orientation = VERTICAL
    }

    fun add(name: String, title: String, cb: (View) -> Unit) {
        val layoutInflater = LayoutInflater.from(context)
        val layout = layoutInflater.inflate(R.layout.menu_item_simple_text, this, false)
        layout.text_view_content.text = name
        layout.text_view_title.text = title
        layout.setOnClickListener { cb(it) }
        addView(layout)
    }
}