Advertisement
safall

Untitled

Feb 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.83 KB | None | 0 0
  1. package no.getspiff.spiff.adapters.viewHolders
  2.  
  3. import android.app.Activity
  4. import android.content.Context
  5. import android.graphics.Color
  6. import android.support.text.emoji.EmojiCompat
  7. import android.support.v4.content.ContextCompat
  8. import android.support.v7.widget.CardView
  9. import android.support.v7.widget.RecyclerView
  10. import android.view.View
  11. import android.widget.TextView
  12. import kotlinx.android.synthetic.main.row_savings_plan.view.*
  13. import no.getspiff.spiff.R
  14. import no.getspiff.spiff.model.SavingsPlanPresentation
  15. import android.support.v4.graphics.drawable.DrawableCompat
  16.  
  17.  
  18. class SavingsPlanNewViewHolder(val view: View,
  19.                                val context: Context?,
  20.                                val activity: Activity? = null) : RecyclerView.ViewHolder(view) {
  21.     private val titleTextView: TextView = view.titleTextView
  22.     private val savingsPlanCardView: CardView = view.savingsPlanCardView
  23.     private val progressTextView : TextView = view.progressTextView
  24.  
  25.  
  26.     fun set(position: Int, data: SavingsPlanPresentation?) {
  27.         data?.let {
  28.             itemView.id = position
  29.             titleTextView.text = EmojiCompat.get().process(data.title)
  30.             progressTextView.text = data.humanReadableIndividualProgress.toString()
  31.             val normalColor = data.color
  32.             val disabledColor = Color.argb(
  33.                     99,
  34.                     Color.red(normalColor),
  35.                     Color.green(normalColor),
  36.                     Color.blue(normalColor))
  37.             if(data.categoryId=="wallet"){
  38.                 savingsPlanCardView.background = ContextCompat.getDrawable(this.context!!, R.drawable.wallet_border)
  39.                 titleTextView.setTextColor(ContextCompat.getColor(context, R.color.colorDurple))
  40.                 val drawable1 = ContextCompat.getDrawable(context, R.drawable.ic_wallet)
  41.                 drawable1?.let { it1 -> DrawableCompat.setTint(it1,ContextCompat.getColor(context,R.color.colorDurple)) }
  42.                 titleTextView.setCompoundDrawablesWithIntrinsicBounds(drawable1, null, null, null)
  43.                 progressTextView.setTextColor(ContextCompat.getColor(context, R.color.colorDurple))
  44.                 titleTextView.compoundDrawablePadding = 12
  45.             }
  46.             if(data.isSelected){
  47.                 if(data.categoryId=="wallet"){
  48.                     titleTextView.setTextColor(ContextCompat.getColor(this.context!!,R.color.colorGreyLight))
  49.                     progressTextView.setTextColor(ContextCompat.getColor(context, R.color.colorGreyLight))
  50.                     val drawable = ContextCompat.getDrawable(context, R.drawable.ic_wallet)
  51.                     drawable?.let { it1 -> DrawableCompat.setTint(it1,ContextCompat.getColor(context,R.color.colorGreyLight)) }
  52.                     titleTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
  53.                     titleTextView.compoundDrawablePadding = 12
  54.                 }else{
  55.                     savingsPlanCardView.setCardBackgroundColor(disabledColor)
  56.                 }
  57.  
  58.             }else{
  59.  
  60.                 if(data.categoryId=="wallet"){
  61.  
  62.                     titleTextView.setTextColor(ContextCompat.getColor(this.context!!,R.color.colorDurple))
  63.                     progressTextView.setTextColor(ContextCompat.getColor(context, R.color.colorDurple))
  64.                     val drawable = ContextCompat.getDrawable(context, R.drawable.ic_wallet)
  65.                     drawable?.let { it1 -> DrawableCompat.setTint(it1,ContextCompat.getColor(context,R.color.colorDurple)) }
  66.                     titleTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
  67.                     titleTextView.compoundDrawablePadding = 12
  68.  
  69.                 }else{
  70.                     savingsPlanCardView.setCardBackgroundColor(normalColor)
  71.                 }
  72.  
  73.             }
  74.         }
  75.  
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement