Skip to content

Commit

Permalink
Merge pull request #46 from nimblehq/release/0.3.0
Browse files Browse the repository at this point in the history
Release - 0.3.0
  • Loading branch information
hoangnguyen92dn authored Sep 26, 2022
2 parents f314906 + b5790da commit c0b983e
Show file tree
Hide file tree
Showing 37 changed files with 1,086 additions and 204 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ dependencies {
implementation("androidx.navigation:navigation-fragment-ktx:${Versions.ANDROIDX_NAVIGATION_VERSION}")
implementation("androidx.navigation:navigation-runtime-ktx:${Versions.ANDROIDX_NAVIGATION_VERSION}")
implementation("androidx.navigation:navigation-ui-ktx:${Versions.ANDROIDX_NAVIGATION_VERSION}")
implementation("androidx.navigation:navigation-compose:${Versions.ANDROIDX_NAVIGATION_COMPOSE_VERSION}")

implementation("com.google.dagger:hilt-android:${Versions.HILT_VERSION}")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package co.nimblehq.compose.crypto.extension

import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.annotation.MainThread
import androidx.lifecycle.*
import androidx.lifecycle.viewmodel.CreationExtras

@MainThread
inline fun <reified VM : ViewModel> ComponentActivity.provideViewModels(
noinline factoryProducer: (() -> CreationExtras)? = null
): Lazy<VM> = OverridableLazy(viewModels(factoryProducer))

class OverridableLazy<T>(var implementation: Lazy<T>) : Lazy<T> {

override val value
get() = implementation.value

override fun isInitialized() = implementation.isInitialized()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nimblehq.compose.crypto.ui.screens.home
package co.nimblehq.compose.crypto.ui.common.price

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
Expand All @@ -11,39 +11,34 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.Dp
import co.nimblehq.compose.crypto.R
import co.nimblehq.compose.crypto.extension.toFormattedString
import co.nimblehq.compose.crypto.ui.preview.CoinItemPreviewParameterProvider
import co.nimblehq.compose.crypto.ui.theme.*
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp13
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp9
import co.nimblehq.compose.crypto.ui.uimodel.CoinItemUiModel
import kotlin.math.abs

@Suppress("FunctionNaming", "LongMethod")
@Composable
fun PriceChange(
priceChangePercentage24hInCurrency: Double,
modifier: Modifier,
iconPaddingEnd: Dp
displayForDetailPage: Boolean = false
) {
val isPositiveNumber = priceChangePercentage24hInCurrency >= 0

Row(modifier = modifier) {
Icon(
modifier = Modifier
.padding(end = iconPaddingEnd)
.padding(end = if (displayForDetailPage) Dp9 else Dp13)
.align(alignment = Alignment.CenterVertically),
painter = if (isPositiveNumber) {
painterResource(id = R.drawable.ic_guppie_green_arrow_up)
} else {
painterResource(id = R.drawable.ic_fire_opal_arrow_down)
},
tint = if (isPositiveNumber) {
Color.GuppieGreen
} else {
Color.FireOpal
},
tint = if (isPositiveNumber) Color.GuppieGreen else Color.FireOpal,
contentDescription = null
)

Expand All @@ -52,16 +47,12 @@ fun PriceChange(
R.string.coin_profit_percent,
abs(priceChangePercentage24hInCurrency).toFormattedString()
),
style = if (isPositiveNumber) {
Style.guppieGreenMedium16()
} else {
Style.fireOpalGreenMedium16()
}
style = if (displayForDetailPage) Style.medium14() else Style.medium16(),
color = if (isPositiveNumber) Color.GuppieGreen else Color.FireOpal
)
}
}

@Suppress("FunctionNaming")
@Composable
@Preview
fun PriceChangePreview(
Expand All @@ -70,8 +61,7 @@ fun PriceChangePreview(
ComposeTheme {
PriceChange(
priceChangePercentage24hInCurrency = coinItem.priceChangePercentage24hInCurrency,
modifier = Modifier,
iconPaddingEnd = Dp13
modifier = Modifier
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package co.nimblehq.compose.crypto.ui.common.price

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import co.nimblehq.compose.crypto.R
import co.nimblehq.compose.crypto.ui.theme.*
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.Color.Water
import co.nimblehq.compose.crypto.ui.theme.Color.WhiteIce
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp0
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp13
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp9

@Composable
fun PriceChangeButton(
modifier: Modifier,
priceChangePercent: String,
displayForDetailPage: Boolean = false,
isPositiveNumber: Boolean = false
) {
Button(
modifier = modifier,
colors = ButtonDefaults.buttonColors(
backgroundColor = if (displayForDetailPage) WhiteIce else Water,
contentColor = if (isPositiveNumber) GuppieGreen else FireOpal
),
shape = RoundedCornerShape(Dimension.Dp20),
contentPadding = PaddingValues(start = Dp13, end = Dimension.Dp8),
elevation = ButtonDefaults.elevation(defaultElevation = Dp0, pressedElevation = Dp0),
onClick = { /* TODO */ },
) {
Icon(
modifier = Modifier
.padding(end = if (displayForDetailPage) Dp9 else Dp13)
.align(alignment = Alignment.CenterVertically),
painter = if (isPositiveNumber) {
painterResource(id = R.drawable.ic_guppie_green_arrow_up)
} else {
painterResource(id = R.drawable.ic_fire_opal_arrow_down)
},
contentDescription = null
)

Text(
text = stringResource(R.string.coin_profit_percent, priceChangePercent),
style = Style.medium16()
)
}
}

@Composable
@Preview
fun PriceChangeButtonPreview() {
ComposeTheme {
PriceChangeButton(
modifier = Modifier,
priceChangePercent = "6.21"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.view.WindowCompat
import co.nimblehq.compose.crypto.ui.screens.home.HomeScreen
import co.nimblehq.compose.crypto.ui.screens.navigation.CryptoNavGraph
import co.nimblehq.compose.crypto.ui.theme.ComposeTheme
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -17,7 +17,7 @@ class MainActivity : ComponentActivity() {
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
ComposeTheme {
HomeScreen()
CryptoNavGraph(this)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package co.nimblehq.compose.crypto.ui.screens.detail

import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import co.nimblehq.compose.crypto.R
import co.nimblehq.compose.crypto.ui.theme.ComposeTheme
import co.nimblehq.compose.crypto.ui.theme.Style
import co.nimblehq.compose.crypto.ui.theme.Style.coinInfoAppBarIconColor
import co.nimblehq.compose.crypto.ui.theme.Style.textColor

@Composable
fun Appbar(
modifier: Modifier
) {
BoxWithConstraints(modifier = modifier.fillMaxWidth()) {
IconButton(
modifier = Modifier.align(Alignment.CenterStart),
onClick = { /*TODO*/ }
) {
Icon(
painter = painterResource(id = R.drawable.ic_back),
tint = MaterialTheme.colors.coinInfoAppBarIconColor,
contentDescription = null
)
}

Text(
modifier = Modifier.align(Alignment.Center),
// TODO: Remove dummy value when work on Integrate.
text = "Ethereum",
color = MaterialTheme.colors.textColor,
style = Style.medium16()
)

IconButton(
modifier = Modifier.align(Alignment.CenterEnd),
onClick = { /*TODO*/ }
) {
Icon(
painter = painterResource(id = R.drawable.ic_heart),
tint = MaterialTheme.colors.coinInfoAppBarIconColor,
contentDescription = null
)
}
}
}

@Preview
@Composable
fun AppbarPreview() {
ComposeTheme {
Surface {
Appbar(modifier = Modifier)
}
}
}

@Preview
@Composable
fun AppbarPreviewDark() {
ComposeTheme(darkTheme = true) {
Surface {
Appbar(modifier = Modifier)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package co.nimblehq.compose.crypto.ui.screens.detail

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import co.nimblehq.compose.crypto.R
import co.nimblehq.compose.crypto.ui.common.price.PriceChange
import co.nimblehq.compose.crypto.ui.theme.ComposeTheme
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp4
import co.nimblehq.compose.crypto.ui.theme.Style
import co.nimblehq.compose.crypto.ui.theme.Style.coinNameColor
import co.nimblehq.compose.crypto.ui.theme.Style.textColor

@Composable
fun DetailItem(
modifier: Modifier,
// TODO Update values to Object on Integrate ticket
title: String,
price: String,
pricePercent: Double
) {
ConstraintLayout(
modifier = modifier.fillMaxWidth()
) {
val (
itemTitle,
itemPrice,
itemPriceChange
) = createRefs()

Text(
modifier = Modifier
.constrainAs(itemTitle) {
top.linkTo(parent.top)
start.linkTo(parent.start)
},
text = title,
color = MaterialTheme.colors.coinNameColor,
style = Style.medium12()
)

Text(
modifier = Modifier
.padding(top = Dp4)
.constrainAs(itemPrice) {
start.linkTo(itemTitle.start)
top.linkTo(itemTitle.bottom)
width = Dimension.preferredWrapContent
},
text = stringResource(R.string.coin_currency, price),
color = MaterialTheme.colors.textColor,
style = Style.medium16()
)

PriceChange(
priceChangePercentage24hInCurrency = pricePercent,
modifier = Modifier
.constrainAs(itemPriceChange) {
end.linkTo(parent.end)
top.linkTo(itemTitle.top)
bottom.linkTo(itemPrice.bottom)
},
displayForDetailPage = true
)
}
}

@Composable
@Preview
fun DetailItemPreview() {
ComposeTheme {
Surface {
DetailItem(
modifier = Modifier,
title = "Market Cap",
price = "387,992,058,833.42",
pricePercent = 7.23
)
}
}
}

@Composable
@Preview
fun DetailItemPreviewDark() {
ComposeTheme(darkTheme = true) {
Surface {
DetailItem(
modifier = Modifier,
title = "Market Cap",
price = "387,992,058,833.42",
pricePercent = -7.23
)
}
}
}
Loading

0 comments on commit c0b983e

Please sign in to comment.