generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from nimblehq/feature/5-implement-ui-my-coins-…
…list-on-home-screen [#5] Implement UI My coins list on home page
- Loading branch information
Showing
13 changed files
with
341 additions
and
48 deletions.
There are no files selected for viewing
156 changes: 156 additions & 0 deletions
156
app/src/main/java/co/nimblehq/compose/crypto/ui/screens/home/CoinItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package co.nimblehq.compose.crypto.ui.screens.home | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.KeyboardArrowDown | ||
import androidx.compose.material.icons.filled.KeyboardArrowUp | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.constraintlayout.compose.Dimension | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import co.nimblehq.compose.crypto.R | ||
import co.nimblehq.compose.crypto.ui.theme.Color.FireOpal | ||
import co.nimblehq.compose.crypto.ui.theme.Color.GuppieGreen | ||
import co.nimblehq.compose.crypto.ui.theme.ComposeTheme | ||
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp12 | ||
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp16 | ||
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp22 | ||
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp25 | ||
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp4 | ||
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp60 | ||
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp8 | ||
import co.nimblehq.compose.crypto.ui.theme.Style | ||
import co.nimblehq.compose.crypto.ui.theme.Style.coinItemColor | ||
import co.nimblehq.compose.crypto.ui.theme.Style.coinNameColor | ||
import co.nimblehq.compose.crypto.ui.theme.Style.textColor | ||
|
||
@Suppress("FunctionNaming", "LongMethod") | ||
@Composable | ||
fun CoinItem( | ||
isPositiveNumber: Boolean = false /* TODO Update value to Object on Integrate ticket */ | ||
) { | ||
ConstraintLayout( | ||
modifier = Modifier | ||
.wrapContentWidth() | ||
.clip(RoundedCornerShape(Dp12)) | ||
.background(color = MaterialTheme.colors.coinItemColor) | ||
.padding(horizontal = Dp8, vertical = Dp8) | ||
) { | ||
val ( | ||
logo, | ||
coinSymbol, | ||
coinName, | ||
price, | ||
icon, | ||
priceChange | ||
) = createRefs() | ||
|
||
Image( | ||
modifier = Modifier | ||
.size(Dp60) | ||
.padding(end = Dp16) | ||
.constrainAs(logo) { | ||
top.linkTo(coinSymbol.top) | ||
bottom.linkTo(coinName.bottom) | ||
start.linkTo(parent.start) | ||
}, | ||
// TODO: Remove dummy image when work on Integrate. | ||
painter = painterResource(id = R.drawable.ic_btc_bitcoin), | ||
contentDescription = null | ||
) | ||
|
||
Text( | ||
modifier = Modifier | ||
.constrainAs(coinSymbol) { | ||
top.linkTo(parent.top) | ||
start.linkTo(logo.end) | ||
}, | ||
// TODO: Remove dummy value when work on Integrate. | ||
text = "BTC", | ||
color = MaterialTheme.colors.textColor, | ||
style = Style.semiBold16() | ||
) | ||
|
||
Text( | ||
modifier = Modifier | ||
.padding(top = Dp4) | ||
.constrainAs(coinName) { | ||
start.linkTo(coinSymbol.start) | ||
top.linkTo(coinSymbol.bottom) | ||
width = Dimension.preferredWrapContent | ||
}, | ||
// TODO: Remove dummy value when work on Integrate. | ||
text = "Bitcoin", | ||
color = MaterialTheme.colors.coinNameColor, | ||
style = Style.medium14() | ||
) | ||
|
||
Text( | ||
modifier = Modifier | ||
.padding(top = Dp22) | ||
.constrainAs(price) { | ||
start.linkTo(logo.start) | ||
top.linkTo(coinName.bottom) | ||
width = Dimension.preferredWrapContent | ||
}, | ||
// TODO: Remove dummy value when work on Integrate. | ||
text = stringResource(R.string.coin_currency, "24,209"), | ||
color = MaterialTheme.colors.textColor, | ||
style = Style.semiBold16() | ||
) | ||
|
||
Icon( | ||
modifier = Modifier | ||
.padding(start = Dp25) | ||
.constrainAs(icon) { | ||
start.linkTo(price.end) | ||
top.linkTo(priceChange.top) | ||
bottom.linkTo(priceChange.bottom) | ||
width = Dimension.preferredWrapContent | ||
}, | ||
imageVector = if (isPositiveNumber) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown, | ||
tint = if (isPositiveNumber) GuppieGreen else FireOpal, | ||
contentDescription = null | ||
) | ||
|
||
Text( | ||
modifier = Modifier | ||
.constrainAs(priceChange) { | ||
start.linkTo(icon.end) | ||
bottom.linkTo(parent.bottom) | ||
width = Dimension.preferredWrapContent | ||
}, | ||
// TODO: Remove dummy value when work on Integrate. | ||
text = stringResource(R.string.coin_profit_percent, "6.21"), | ||
style = if (isPositiveNumber) Style.guppieGreenMedium16() else Style.fireOpalGreenMedium16() | ||
) | ||
} | ||
} | ||
|
||
@Suppress("FunctionNaming") | ||
@Composable | ||
@Preview | ||
fun CoinItemPreview() { | ||
ComposeTheme { | ||
CoinItem() | ||
} | ||
} | ||
|
||
@Suppress("FunctionNaming") | ||
@Composable | ||
@Preview | ||
fun CoinItemPreviewDark() { | ||
ComposeTheme(darkTheme = true) { | ||
CoinItem() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.