Skip to content

Commit

Permalink
add price change color
Browse files Browse the repository at this point in the history
  • Loading branch information
root14 committed Mar 29, 2024
1 parent 98a8186 commit 426a44c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.root14.hoopoe.view.binding

import android.graphics.Color
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import com.root14.hoopoe.R
import com.root14.hoopoe.utils.convertMarketCap
import com.root14.hoopoe.utils.convertPriceChange
import com.root14.hoopoe.utils.convertPriceFormat
Expand All @@ -24,5 +27,15 @@ fun setMarketCap(textView: TextView, marketCap: String) {
fun setPriceChange(textView: TextView, priceChange: String) {
priceChange.let {
textView.text = priceChange.convertPriceChange()

val baseView = textView.rootView.resources
if (priceChange.isNotEmpty()) {
val price = priceChange.toDouble()
if (price > 0) {
textView.setTextColor(baseView.getColor(R.color.positiveColor))
} else {
textView.setTextColor(baseView.getColor(R.color.negativeColor))
}
}
}
}
8 changes: 5 additions & 3 deletions app/src/main/res/layout/activity_asset_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
android:id="@+id/tv_assetName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@{asset.data.symbol}"
app:layout_constraintStart_toEndOf="@+id/imageView_asset"
app:layout_constraintTop_toTopOf="@+id/imageView_asset" />
Expand All @@ -161,8 +162,8 @@
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart_asset"
android:layout_width="0dp"
android:layout_height="239dp"
android:layout_marginTop="48dp"
android:layout_height="250dp"
android:layout_marginTop="24dp"
android:textSize="28sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -173,7 +174,7 @@
bindIcon='@{asset.data.symbol??""}'
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="128dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down Expand Up @@ -231,6 +232,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toEndOf="@+id/tv_marketVolume"
app:layout_constraintTop_toTopOf="@+id/tv_marketVolume" />

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="negativeColor">#FFF44336</color>
<color name="positiveColor">#FF4CAF50</color>
</resources>

0 comments on commit 426a44c

Please sign in to comment.