Skip to content

Commit

Permalink
Merge pull request #11 from nimblehq/feature/4-implement-ui-today-pro…
Browse files Browse the repository at this point in the history
…fit-card-on-home-screen

[#4] Implement UI Today's profit card on Home screen
  • Loading branch information
hoangnguyen92dn authored Jul 26, 2022
2 parents df08bb1 + b1040ce commit 2b7f183
Show file tree
Hide file tree
Showing 24 changed files with 350 additions and 65 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ dependencies {
implementation("androidx.core:core-ktx:${Versions.ANDROIDX_CORE_KTX_VERSION}")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:${Versions.ANDROIDX_LIFECYCLE_VERSION}")

implementation("androidx.activity:activity-compose:${Versions.COMPOSE_ACTIVITY_VERSION}")
implementation("androidx.constraintlayout:constraintlayout-compose:${Versions.COMPOSE_CONSTRAINT_LAYOUT_VERSION}")
implementation("androidx.compose.ui:ui:${Versions.COMPOSE_VERSION}")
implementation("androidx.compose.ui:ui-tooling:${Versions.COMPOSE_VERSION}")
implementation("androidx.compose.foundation:foundation:${Versions.COMPOSE_VERSION}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package co.nimblehq.compose.crypto.ui.screens

import android.view.LayoutInflater
import androidx.activity.viewModels
import co.nimblehq.compose.crypto.databinding.ActivityMainBinding
import co.nimblehq.compose.crypto.ui.base.BaseActivity
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import co.nimblehq.compose.crypto.ui.screens.home.HomeScreen
import co.nimblehq.compose.crypto.ui.theme.ComposeTheme
import dagger.hilt.android.AndroidEntryPoint

// TODO: Consider update BaseActivity to extends ComponentActivity.
@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding>() {
class MainActivity : ComponentActivity() {

override val bindingInflater: (LayoutInflater) -> ActivityMainBinding
get() = { inflater -> ActivityMainBinding.inflate(inflater) }

override val viewModel by viewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeTheme {
HomeScreen()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import co.nimblehq.compose.crypto.util.DispatchersProvider
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

// TODO: Consider to update or remove it on Integrate task.
@HiltViewModel
class MainViewModel @Inject constructor(dispatchers: DispatchersProvider) : BaseViewModel(dispatchers)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package co.nimblehq.compose.crypto.ui.screens.home

import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
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.theme.ComposeTheme
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp16
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp40
import co.nimblehq.compose.crypto.ui.theme.Style
import co.nimblehq.compose.crypto.ui.theme.Style.titleHome

@Composable
fun HomeScreen() {
Surface {
ConstraintLayout(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = Dp16)
) {
val (title, portfolioCard) = createRefs()

Text(
modifier = Modifier
.padding(start = Dp16, top = Dp16, end = Dp16)
.constrainAs(title) {
top.linkTo(parent.top)
linkTo(start = parent.start, end = parent.end)
width = Dimension.preferredWrapContent
},
text = stringResource(id = R.string.home_title),
textAlign = TextAlign.Center,
style = Style.semiBold24(),
color = MaterialTheme.colors.titleHome
)

PortfolioCard(
modifier = Modifier.constrainAs(portfolioCard) {
top.linkTo(title.bottom, margin = Dp40)
}
)
}
}
}

@Composable
@Preview
fun HomeScreenPreview() {
ComposeTheme {
HomeScreen()
}
}

@Composable
@Preview
fun HomeScreenPreviewDark() {
ComposeTheme(darkTheme = true) {
HomeScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package co.nimblehq.compose.crypto.ui.screens.home

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
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.draw.shadow
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.res.stringResource
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
import co.nimblehq.compose.crypto.ui.theme.ComposeTheme
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp0
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.Dp20
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp4
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp40
import co.nimblehq.compose.crypto.ui.theme.Dimension.Dp8
import co.nimblehq.compose.crypto.ui.theme.Style

@Composable
fun PortfolioCard(
modifier: Modifier
) {
ConstraintLayout(
modifier = modifier
.fillMaxWidth()
.clip(RoundedCornerShape(Dp12))
.background(
brush = Brush.linearGradient(
colors = listOf(Color.MetallicSeaweed, Color.TiffanyBlue),
)
)
) {
val (
totalCoinsLabel,
totalCoins,
todayProfitLabel,
todayProfit,
profitPercent
) = createRefs()

Text(
modifier = Modifier
.padding(top = Dp16, start = Dp16)
.constrainAs(totalCoinsLabel) {
start.linkTo(parent.start)
},
text = stringResource(R.string.portfolio_card_total_coin_label),
style = Style.lightSilverMedium16()
)

Text(
modifier = Modifier
.padding(horizontal = Dp16)
.constrainAs(totalCoins) {
top.linkTo(totalCoinsLabel.bottom, margin = Dp8)
},
// TODO: Remove dummy value when work on Integrate.
text = stringResource(R.string.portfolio_card_total_coin, "7,273,291"),
style = Style.whiteSemiBold24()
)

Text(
modifier = Modifier
.padding(start = Dp16)
.constrainAs(todayProfitLabel) {
top.linkTo(totalCoins.bottom, margin = Dp40)
},
text = stringResource(R.string.portfolio_card_today_profit_label),
style = Style.lightSilverMedium16()
)

Text(
modifier = Modifier
.padding(start = Dp16, bottom = Dp16)
.constrainAs(todayProfit) {
top.linkTo(todayProfitLabel.bottom, margin = Dp8)
},
// TODO: Remove dummy value when work on Integrate.
text = stringResource(R.string.portfolio_card_today_profit, "193,280"),
style = Style.whiteSemiBold24()
)

Button(
modifier = Modifier
.padding(start = Dp16, end = Dp16, bottom = Dp16)
.shadow(elevation = Dp0)
.constrainAs(profitPercent) {
linkTo(top = todayProfitLabel.top, bottom = todayProfit.bottom)
end.linkTo(parent.end)
},
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Water,
contentColor = Color.GuppieGreen
),
shape = RoundedCornerShape(Dp20),
onClick = { /* TODO */ }
) {
Icon(
imageVector = Icons.Filled.KeyboardArrowUp,
modifier = Modifier.padding(end = Dp4),
contentDescription = null
)
Text(
// TODO: Remove dummy value when work on Integrate.
text = stringResource(R.string.portfolio_card_profit_percent, 2.41),
style = Style.medium16()
)
}
}
}

@Composable
@Preview
fun PortfolioCardPreview() {
ComposeTheme {
PortfolioCard(
modifier = Modifier
)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package co.nimblehq.compose.crypto.ui.screens.compose.composables
package co.nimblehq.compose.crypto.ui.screens.to_be_removed

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import co.nimblehq.compose.crypto.ui.screens.compose.theme.Dimension
import co.nimblehq.compose.crypto.ui.theme.Dimension

@Composable
fun ContentCard(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nimblehq.compose.crypto.ui.screens.compose.composables
package co.nimblehq.compose.crypto.ui.screens.to_be_removed

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -14,7 +14,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import co.nimblehq.compose.crypto.ui.screens.compose.theme.Dimension
import co.nimblehq.compose.crypto.ui.theme.Dimension

@Suppress("LongMethod")
@ExperimentalComposeUiApi
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/co/nimblehq/compose/crypto/ui/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package co.nimblehq.compose.crypto.ui.theme

import androidx.compose.ui.graphics.Color

@Suppress("MagicNumber")
object Color {
val BlueFreeSpeech = Color(0xFF3F51B5)
val AlmostWhite = Color(0xFFDFE4EA)
val White = Color.White
val MetallicSeaweed = Color(0xFF028090)
val TiffanyBlue = Color(0xFF00BFB2)
val Water = Color(0xFFD6F5F3)
val GuppieGreen = Color(0xFF10DC78)
val DarkJungleGreen = Color(0xFF141B29)
val LightSilver = Color(0xFFD6D7D8)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nimblehq.compose.crypto.ui.screens.compose.theme
package co.nimblehq.compose.crypto.ui.theme

import androidx.compose.ui.unit.dp

Expand All @@ -7,7 +7,10 @@ object Dimension {
val Dp0 = 0.dp
val Dp4 = 4.dp
val Dp8 = 8.dp
val Dp12 = 12.dp
val Dp16 = 16.dp
val Dp20 = 20.dp
val Dp24 = 24.dp
val Dp40 = 40.dp
val Dp52 = 52.dp
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nimblehq.compose.crypto.ui.screens.compose.theme
package co.nimblehq.compose.crypto.ui.theme

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/co/nimblehq/compose/crypto/ui/theme/Style.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package co.nimblehq.compose.crypto.ui.theme

import androidx.compose.material.Colors
import androidx.compose.ui.graphics.Color
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import co.nimblehq.compose.crypto.ui.theme.Color.DarkJungleGreen
import co.nimblehq.compose.crypto.ui.theme.Color.LightSilver
import co.nimblehq.compose.crypto.ui.theme.TextDimension.Sp16
import co.nimblehq.compose.crypto.ui.theme.TextDimension.Sp24

object Style {

val Colors.titleHome: Color
@Composable
get() = if (isLight) DarkJungleGreen else White

@Composable
fun medium16() = TextStyle(fontWeight = FontWeight.Medium, fontSize = Sp16)

@Composable
fun lightSilverMedium16() = medium16().copy(color = LightSilver)

@Composable
fun semiBold24() = TextStyle(fontWeight = FontWeight.SemiBold, fontSize = Sp24)

@Composable
fun whiteSemiBold24() = semiBold24().copy(color = White)
}
Loading

0 comments on commit 2b7f183

Please sign in to comment.