Skip to content

Commit

Permalink
Added alert id
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanarodr committed May 3, 2024
1 parent 4b76da4 commit 83f85fd
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 5 deletions.
9 changes: 9 additions & 0 deletions design-system/src/main/res/drawable/ic_radar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FF000000"
android:pathData="M480,880q-83,0 -156,-31.5T197,763q-54,-54 -85.5,-127T80,480q0,-114 59.5,-210.5T301,122q1,19 4,38.5t10,45.5q-72,44 -113.5,116.5T160,480q0,134 93,227t227,93q134,0 227,-93t93,-227q0,-85 -41.5,-158T644,205q7,-26 10,-45.5t5,-37.5q102,51 161.5,147T880,480q0,83 -31.5,156T763,763q-54,54 -127,85.5T480,880ZM480,720q-100,0 -170,-70t-70,-170q0,-58 25.5,-109t72.5,-85q5,15 11,34.5t16,48.5q-22,23 -33.5,51T320,480q0,66 47,113t113,47q66,0 113,-47t47,-113q0,-32 -11.5,-60T595,369q8,-24 14.5,-44.5T621,286q47,34 73,85t26,109q0,100 -70,170t-170,70ZM468,340q-13,0 -22.5,-7.5T432,313l-40,-130q-7,-26 -9.5,-45.5T380,100q0,-42 29,-71t71,-29q42,0 71,29t29,71q0,18 -2.5,37.5T568,183l-40,130q-4,12 -13.5,19.5T492,340h-24ZM480,560q-33,0 -56.5,-23.5T400,480q0,-33 23.5,-56.5T480,400q33,0 56.5,23.5T560,480q0,33 -23.5,56.5T480,560Z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal fun PortfolioCard(
OutlinedCard(
modifier = modifier
.fillMaxWidth()
.wrapContentHeight(),
.wrapContentHeight()
) {
Box(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class StockAlertMapper : Mapper<List<StockAlertResponse>, List<StockAle
}

private fun mapperStockAlert(input: StockAlertResponse) = StockAlertModel(
id = input.id,
ticket = input.stockTicket,
alertValue = input.alertValue,
status = StockStatusType.fromString(input.status),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import br.com.stonks.feature.stocks.domain.types.StockAlertType
import br.com.stonks.feature.stocks.domain.types.StockStatusType

internal data class StockAlertModel(
val id: Long,
val ticket: String,
val alertValue: Double,
val status: StockStatusType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package br.com.stonks.feature.stocks.repository.remote.response
import com.google.gson.annotations.SerializedName

internal data class StockAlertResponse(
@SerializedName("id")
val id: Long,
@SerializedName("stock_ticket")
val stockTicket: String,
@SerializedName("alert_value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class StockAlertUiMapper : Mapper<List<StockAlertModel>, StockAlertUiMo
)

private fun mapperStockAlert(input: StockAlertModel) = AlertUiModel(
id = input.id,
ticket = input.ticket,
alertValue = input.alertValue,
status = input.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import br.com.stonks.feature.stocks.domain.types.StockAlertType
import br.com.stonks.feature.stocks.domain.types.StockStatusType

internal data class AlertUiModel(
val id: Long,
val ticket: String,
val alertValue: Double,
val status: StockStatusType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -32,6 +35,8 @@ import timber.log.Timber
private fun StockAlertContent(
uiModel: StockAlertUiModel,
modifier: Modifier = Modifier,
onEditItem: () -> Unit,
onDeleteItem: () -> Unit,
) {
LazyColumn(
modifier = modifier,
Expand All @@ -47,7 +52,11 @@ private fun StockAlertContent(
)
}
items(uiModel.stockAlerts) { alert ->
Text(text = alert.ticket)
AlertCard(
uiModel = alert,
onEditItem = { onEditItem() },
onDeleteItem = { onDeleteItem() },
)
}
}
}
Expand All @@ -61,6 +70,7 @@ fun StockAlertScreen(
),
) {
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
var selected by remember { mutableStateOf(false) }

when (uiState.value) {
is StockUiState.Loading -> {
Expand All @@ -71,6 +81,8 @@ fun StockAlertScreen(
StockAlertContent(
uiModel = (uiState.value as StockUiState.Success).data,
modifier = modifier,
onEditItem = { },
onDeleteItem = { },
)
}

Expand All @@ -91,13 +103,16 @@ private fun StockAlertScreenPreview() {
totalAssets = 60000.0,
stockAlerts = listOf(
AlertUiModel(
id = 1L,
ticket = "GOGL34",
alertValue = 70.93,
status = StockStatusType.AVAILABLE,
alert = StockAlertType.HIGH_PRICE,
tagColor = ColorToken.HighlightGreen,
)
)
)
),
onEditItem = { },
onDeleteItem = { },
)
}
10 changes: 9 additions & 1 deletion feature/stocks/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="total_alert">Estoque alerta</string>
</resources>
<string name="status_available">Estoque</string>
<string name="status_unavailable">Indisponível</string>
<string name="status_unknown">Desconhecido</string>
<string name="alert_price">Valor do produto</string>
<string name="alert_action_delete">Excluir alerta</string>
<string name="alert_action_edit">Editar alerta</string>
<string name="alert_action_save">Salvar</string>
<string name="alert_action_cancel">Cancelar</string>
</resources>
3 changes: 3 additions & 0 deletions mocks/stock-alert.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
[
{
"id": 1,
"stock_ticket": "GOGL34",
"alert_value": 70,
"status": "available",
"notification_trigger": "high"
},
{
"id": 2,
"stock_ticket": "AAPL34",
"alert_value": 150,
"status": "unavailable",
"notification_trigger": "high"
},
{
"id": 3,
"stock_ticket": "ITSA4",
"status": "available",
"alert_value": 12,
Expand Down

0 comments on commit 83f85fd

Please sign in to comment.