parent
f69e564eee
commit
aa07613554
@ -1,56 +0,0 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import android.content.Context |
||||
import android.util.AttributeSet |
||||
import androidx.appcompat.widget.AppCompatTextView |
||||
import androidx.core.content.ContextCompat |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.util.toCurrency |
||||
|
||||
class PokerAnalyticsTextView: AppCompatTextView { |
||||
|
||||
var isCurrency: Boolean = false |
||||
var amount: Double = 0.0 |
||||
set(value) { |
||||
field = value |
||||
updateUI() |
||||
} |
||||
|
||||
constructor(context: Context?) : super(context) { |
||||
init(null) |
||||
} |
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { |
||||
init(attrs) |
||||
} |
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
||||
init(attrs) |
||||
} |
||||
|
||||
/** |
||||
* Init class |
||||
*/ |
||||
private fun init(attrs: AttributeSet?) { |
||||
context.theme.obtainStyledAttributes( attrs, R.styleable.PokerAnalyticsTextView, 0, 0).apply { |
||||
try { |
||||
isCurrency = getBoolean(R.styleable.PokerAnalyticsTextView_isCurrency, false) |
||||
amount = getFloat(R.styleable.PokerAnalyticsTextView_amount, 0f).toDouble() |
||||
updateUI() |
||||
} finally { |
||||
recycle() |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Update the UI to manage currency format & color management |
||||
*/ |
||||
private fun updateUI() { |
||||
if (isCurrency) { |
||||
setTextColor(ContextCompat.getColor(context, if (amount >= 0) R.color.green else R.color.red)) |
||||
text = amount.toCurrency() |
||||
} |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue