Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.4 kB
2
Indexable
Never
package tr.com.niximera.koopsis.koopSISComponents

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import tr.com.niximera.koopsis.R
import kotlinx.android.synthetic.main.companent_toolbar.view.*
import tr.com.niximera.koopsis.extentions.showView


class CompanentToolBar : LinearLayout {

    private var mContext: Context



    private var isBackButtonVisible: Boolean = false
        set(value) {
            field = value
            toolBack.showView(field)
        }
    private var isRightTextVisible: Boolean = false
        set(value) {
            field = value
            toolRightText.showView(field)
        }
    private var isRightImageVisible: Boolean = false
        set(value) {
            field = value
            toolRightImage.showView(field)
        }
    private var rightButtonImage: Int = R.drawable.ic_baseline_person_24
        set(value) {
            field = value
            toolRightImage.setImageResource(field)
        }
    private var rightButtonTextString: String = ""
        set(value) {
            field = value
            toolRightText.text = field
        }

    private var titleTextString: String = ""
        set(value) {
            field = value
            toolTitle.text = field
        }


    constructor(context: Context) : super(context) {
        mContext = context
        init(null, 0)
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        mContext = context
        init(attrs, 0)
    }

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
        mContext = context
        init(attrs, defStyle)
    }

    private fun init(attrs: AttributeSet?, defStyle: Int) {
        View.inflate(mContext, R.layout.companent_toolbar, this)
        val typeArray = context.obtainStyledAttributes(attrs, R.styleable.kToolBar, defStyle, 0)
        typeArray.run {

            isBackButtonVisible = typeArray.getBoolean(R.styleable.kToolBar_isBackButtonVisible, false)
            isRightTextVisible = typeArray.getBoolean(R.styleable.kToolBar_isRightTextVisible, false)
            isRightImageVisible = typeArray.getBoolean(R.styleable.kToolBar_isRightImageVisible, false)
            rightButtonImage = typeArray.getResourceId(R.styleable.kToolBar_rightButtonImage, R.drawable.ic_baseline_person_24)
            rightButtonTextString = typeArray.getString(R.styleable.kToolBar_rightButtonTextString).toString()
            titleTextString = typeArray.getString(R.styleable.kToolBar_barTittle).toString()

        }

    }

    fun backButtonVisibility(isVisible: Boolean) {
        this@CompanentToolBar.isBackButtonVisible = isVisible
    }



    fun rightTextButtonVisibility(isVisible: Boolean) {
        this@CompanentToolBar.isRightTextVisible = isVisible
    }

    fun rightImageButtonVisibility(isVisible: Boolean) {
        this@CompanentToolBar.isRightImageVisible = isVisible
    }

    fun rightTextButtonText(text: String) {
        this@CompanentToolBar.rightButtonTextString = text
    }

    fun setTitleText(text: String) {
        this@CompanentToolBar.titleTextString = text
    }

    fun rightImageButtonImage(drawable: Int) {
        this@CompanentToolBar.rightButtonImage = drawable
    }
}