Skip to content

Commit

Permalink
gradient to Chart.kt added
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Apr 6, 2022
1 parent 81b8db2 commit 39e4b16
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 9 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = "ru.tech.papricoin"
minSdk = 21
targetSdk = 32
versionCode = 1
versionName = "1.0"
versionCode = 2
versionName = "1.0.1"

}

Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"versionCode": 2,
"versionName": "1.0.1",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ data class CoinCurrencyDto(

val CoinCurrencyDto.coinCurrency
get() = CoinCurrency(
currency = (low + high) / 2
currency = open
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ fun CoinDetailsScreen(
)

Surface(color = backgroundColor) {
MediumTopAppBar(
LargeTopAppBar(
modifier = Modifier.statusBarsPadding(),
colors = foregroundColors,
title = {
val st = viewModel.coinDetailState.value
if (st is UIState.Success<CoinDetail?>) {
st.data?.let { details ->
Text("${details.rank}. ${details.name} (${details.symbol})")
Text(
"${details.rank}. ${details.name} (${details.symbol})",
maxLines = 2
)
}
}
},
Expand Down Expand Up @@ -168,7 +171,7 @@ fun CoinDetailsScreen(
is UIState.Success -> {
Chart(
lineChartData = hState.data.map { it.currency },
MaterialTheme.colorScheme.primary
color = MaterialTheme.colorScheme.primary
)
}
is UIState.Loading -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.clipPath
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.graphics.ColorUtils
import java.math.RoundingMode
import java.text.DecimalFormat

Expand Down Expand Up @@ -63,16 +68,46 @@ fun Chart(lineChartData: List<Double>, color: Color) {
}
}

val clipPath = Path().apply {
lineTo(points.first().x, size.height)
lineTo(points.first().x, points.last().y)
}

for (i in 0 until points.size - 1) {
drawLine(
start = Offset(points[i].x, points[i].y),
end = Offset(points[i + 1].x, points[i + 1].y),
color = color,
strokeWidth = 2f
)
clipPath.lineTo(points[i].x, points[i].y)
}

clipPath.apply {
lineTo(points.last().x, points.last().y)
lineTo(points.last().x, size.height)
lineTo(points.first().x, size.height)
}

clipPath(clipPath) {
drawRect(
Brush.verticalGradient(
colors = listOf(
Color(
ColorUtils.blendARGB(
color.toArgb(),
Color.Gray.toArgb(),
0.6f
)
),
Color.Transparent
)
)
)
}
}

Spacer(Modifier.height(20.dp))

Row(
verticalAlignment = Alignment.Bottom
) {
Expand Down

0 comments on commit 39e4b16

Please sign in to comment.