Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

likorn / quick_max

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • quick_max
  • ..
  • quickmax
  • AnswerCardView.kt
Find file
BlameHistoryPermalink
  • likorn's avatar
    Minor refactoring · a9f9c93d
    likorn committed 5 years ago
    a9f9c93d
AnswerCardView.kt 1.48 KB
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
package com.paktalin.quickmax

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import androidx.core.content.ContextCompat
import com.google.android.material.card.MaterialCardView

class AnswerCardView : MaterialCardView {

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    fun initial(context: Context, text: Int) {
        isCheckable = true
        isEnabled = true
        isChecked = false
        setCardBackgroundColor(Color.WHITE)
        getTextView(this).setTextColor(
            color(
                context,
                R.color.transparent_black
            )
        )
        getTextView(this).text = text.toString()
        setOnClickListener { isChecked = true }
    }

    fun markCorrect(context: Context) {
        checkedIcon = context.resources.getDrawable(R.drawable.ic_check, null)
        foregroundTintList = ContextCompat.getColorStateList(context,
            R.color.colorAccent
        )
    }

    fun markWrong(context: Context) {
        checkedIcon = context.resources.getDrawable(R.drawable.ic_cancel, null)
        foregroundTintList = ContextCompat.getColorStateList(context,
            R.color.red
        )
    }

    fun disable() {
        isCheckable = false
        isEnabled = false
    }
}