-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp the "Market" page #41
Changes from 1 commit
582ac6d
5bff148
9172856
0b4b660
af02be1
c7d10c6
8975fca
0d7409f
200cb12
7cf32c8
9bee684
912ba76
5fb683e
dd43aa7
a5d10c4
bb6370d
cc5a8d1
dd48b53
d6297c4
ef48f0c
22cfeb4
3a34825
69550aa
765b2c4
05fee62
b0dc961
ad2f175
a15193d
a8d6aeb
5e34972
8c6c4ff
c4dfaf4
d8377bd
30fdf85
88a7432
ca3c059
2f88938
ac1bad3
2d44c6f
5efbcd5
38c5ec7
97f6ac2
7d3e433
ab2e0ed
ed98a84
b698c3c
a3182fa
5343bb4
1cfbbc3
9020546
0b3ca2b
577c08c
fe90cff
947dfe0
9f3562b
f1ef868
fd1f70a
5586081
fbd4cab
e87daf0
90ca44d
5b61ccd
3de630e
7ec500a
94d3d49
6ecb1c5
2fa44ea
5d0e3ec
ed8b532
fe8f1f0
35b0bce
cc0cc3b
904b1b5
7639c08
3ff6f73
c739f69
67f2704
6bcf2b6
f77dca6
ce993ad
9a7d0a1
a380c6e
d247eee
75309be
67237d5
f09e5d4
b94bcbe
a860adc
0cb94de
8447757
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
MarketPage
.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,7 +380,7 @@ public fun MarketPage(model: MarketPageModel) { | |
?.find { share -> share.id == selectedShareId!! } | ||
ShareProfile( | ||
share = selectedShare!!, | ||
previousShare = previousShare, | ||
previousPrice = previousShare?.price, | ||
model = model | ||
) | ||
} else { | ||
|
@@ -445,7 +445,7 @@ private fun SharesList( | |
ShareItem( | ||
model = model, | ||
share = share, | ||
previousShare = previousShares?.getShare(index) | ||
previousPrice = previousShares?.getShare(index)?.price | ||
) | ||
} | ||
} | ||
|
@@ -465,13 +465,13 @@ private fun SharesList( | |
* Represents the main information about the share and ways to interact with it. | ||
* | ||
* @param share the share to represent | ||
* @param previousShare the previous state of this share | ||
* @param previousPrice the previous price of this share | ||
* @param model the model of the market page | ||
*/ | ||
@Composable | ||
private fun ShareProfile( | ||
share: Share, | ||
previousShare: Share?, | ||
previousPrice: Money?, | ||
model: MarketPageModel | ||
) { | ||
Column( | ||
|
@@ -481,14 +481,14 @@ private fun ShareProfile( | |
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
ShareIcon(share.companyLogo, share.companyName) | ||
ShareLogo(share) | ||
Text( | ||
text = share.companyName, | ||
style = MaterialTheme.typography.labelMedium, | ||
modifier = Modifier | ||
.padding(top = 10.dp) | ||
) | ||
SharePrice(share, previousShare) | ||
SharePrice(share.price, previousPrice) | ||
ButtonSection( | ||
model = model, | ||
share = share | ||
|
@@ -499,24 +499,27 @@ private fun ShareProfile( | |
/** | ||
* Show information about the share price. | ||
* | ||
* @param share the share which price to be shown | ||
* @param previousShare the previous state of this share to show the price difference with | ||
* @param actualPrice the actual share price to be shown | ||
* @param previousPrice the previous price of this share to show difference with | ||
*/ | ||
@Composable | ||
private fun SharePrice(share: Share, previousShare: Share?) { | ||
private fun SharePrice( | ||
actualPrice: Money, | ||
previousPrice: Money? | ||
) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = Modifier | ||
.padding(top = 10.dp) | ||
.wrapContentHeight() | ||
) { | ||
Text( | ||
text = share.price.asReadableString(), | ||
text = actualPrice.asReadableString(), | ||
style = MaterialTheme.typography.labelSmall, | ||
modifier = Modifier | ||
.padding(end = 10.dp) | ||
) | ||
val (color, price) = definePriceDifferenceConfig(share.price, previousShare?.price) | ||
val (color, price) = definePriceDifferenceConfig(actualPrice, previousPrice) | ||
Text( | ||
text = price, | ||
style = MaterialTheme.typography.headlineSmall, | ||
|
@@ -527,6 +530,9 @@ private fun SharePrice(share: Share, previousShare: Share?) { | |
|
||
/** | ||
* Represents the dialog window for the shares purchase purposes. | ||
* | ||
* @param model the model of the "Market" page | ||
* @param isShown is a dialog window shown to the user | ||
*/ | ||
@Composable | ||
private fun PurchaseDialog( | ||
|
@@ -572,6 +578,8 @@ private fun PurchaseDialog( | |
|
||
/** | ||
* Represents the input component accepting only the numeric values. | ||
* | ||
* @param model the model of the "Market" page | ||
*/ | ||
@Composable | ||
private fun NumericInput(model: MarketPageModel) { | ||
|
@@ -613,13 +621,17 @@ private fun calculatePrice(pricePerOne: Money?, quantity: Int): String { | |
|
||
/** | ||
* Represents the `ShareItem` component. | ||
* | ||
* @param model the model of the "Market" page | ||
* @param share the share to represent | ||
* @param previousPrice the previous price of this share | ||
*/ | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun ShareItem( | ||
model: MarketPageModel, | ||
share: Share, | ||
previousShare: Share? | ||
previousPrice: Money? | ||
) { | ||
Box( | ||
modifier = Modifier | ||
|
@@ -636,17 +648,23 @@ private fun ShareItem( | |
} | ||
), | ||
headlineText = { | ||
MainItemContent(share, previousShare) | ||
MainItemContent(share, previousPrice) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Represents the main `ListItem` content with data about the share. | ||
* | ||
* @param share the share to show inside the item | ||
* @param previousPrice the previous price of this share | ||
*/ | ||
@Composable | ||
private fun MainItemContent(share: Share, previousShare: Share?) { | ||
private fun MainItemContent( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to rename |
||
share: Share, | ||
previousPrice: Money? | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
|
@@ -668,7 +686,7 @@ private fun MainItemContent(share: Share, previousShare: Share?) { | |
verticalArrangement = Arrangement.Center | ||
) { | ||
Text(share.price.asReadableString(), style = MaterialTheme.typography.headlineSmall) | ||
val priceDifference = definePriceDifferenceConfig(share.price, previousShare?.price) | ||
val priceDifference = definePriceDifferenceConfig(share.price, previousPrice) | ||
PriceDifferenceCard(priceDifference) | ||
} | ||
} | ||
|
@@ -734,6 +752,9 @@ private object PriceDifference { | |
|
||
/** | ||
* Represents the search field. | ||
* | ||
* @param value the text to be shown in the search field | ||
* @param onChange the callback that is triggered when the search value change | ||
*/ | ||
@Composable | ||
private fun SearchField( | ||
|
@@ -779,6 +800,9 @@ private fun Modifier.bottomBorder(): Modifier { | |
} | ||
} | ||
|
||
/** | ||
* Returns the difference between this `Money` object and provided as a readable string. | ||
*/ | ||
private fun Money.subtract(money: Money): String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's two operations, not one. First, we subtract, then we transform into some form. |
||
return if (isGreater(this, money)) { | ||
val result = subtract(this, money) | ||
|
@@ -790,10 +814,12 @@ private fun Money.subtract(money: Money): String { | |
} | ||
|
||
/** | ||
* Represents the share icon. | ||
* Represents the share logo. | ||
* | ||
* @param share the share which logo to draw | ||
*/ | ||
@Composable | ||
private fun ShareIcon(companyLogo: String, companyName: String) { | ||
private fun ShareLogo(share: Share) { | ||
val density = LocalDensity.current | ||
Box( | ||
modifier = Modifier | ||
|
@@ -802,18 +828,24 @@ private fun ShareIcon(companyLogo: String, companyName: String) { | |
contentAlignment = Alignment.Center | ||
) { | ||
Image( | ||
load = { loadImage(companyLogo, density) }, | ||
load = { loadImage(share.companyLogo, density) }, | ||
painterFor = { it }, | ||
contentDescription = companyName, | ||
contentDescription = share.companyName, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Represents the button section. | ||
* | ||
* @param model the model of the "Market" page | ||
* @param share the share with which to interact with buttons | ||
*/ | ||
@Composable | ||
private fun ButtonSection(model: MarketPageModel, share: Share) { | ||
private fun ButtonSection( | ||
model: MarketPageModel, | ||
share: Share | ||
) { | ||
val scope = rememberCoroutineScope { Dispatchers.Default } | ||
Row( | ||
modifier = Modifier | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to display"?