-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf66cfd
commit 8e2d6a8
Showing
16 changed files
with
246 additions
and
182 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
...xample/kkneed/viewmodel/ScannerUiState.kt → ...com/example/kkneed/data/ScannerUiState.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.example.kkneed.data | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.example.kkneed.R | ||
import com.example.kkneed.data.fake.fakeLevel | ||
import com.example.kkneed.ui.theme.* | ||
|
||
@Composable | ||
fun findLevel(score: String): LevelItem { | ||
val matchLevel: LevelItem = fakeLevel | ||
when (score) { | ||
"a" -> { | ||
matchLevel.gradeImage = R.drawable.alevel | ||
matchLevel.matchText = "健康匹配度高" | ||
matchLevel.matchColor = LevelA | ||
} | ||
|
||
"b" -> { | ||
matchLevel.gradeImage = R.drawable.blevel | ||
matchLevel.matchText = "健康匹配度较高" | ||
matchLevel.matchColor = LevelB | ||
} | ||
|
||
"c" -> { | ||
matchLevel.gradeImage = R.drawable.clevel | ||
matchLevel.matchText = "健康匹配度一般" | ||
matchLevel.matchColor = LevelC | ||
} | ||
|
||
"d" -> { | ||
matchLevel.gradeImage = R.drawable.dlevel | ||
matchLevel.matchText = "健康匹配度较低" | ||
matchLevel.matchColor = LevelD | ||
} | ||
|
||
"e" -> { | ||
matchLevel.gradeImage = R.drawable.elevel | ||
matchLevel.matchText = "健康匹配度低" | ||
matchLevel.matchColor = LevelE | ||
} | ||
} | ||
return matchLevel | ||
} | ||
|
||
@Composable | ||
fun productCalculator(productLeft: Double, productRight: Double): ProductValue { | ||
val total = productLeft + productRight | ||
val left = productLeft / total | ||
val right = productRight / total | ||
return ProductValue(left, right) | ||
} |
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
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
71 changes: 44 additions & 27 deletions
71
app/src/main/java/com/example/kkneed/screen/search/CompareScreen.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 |
---|---|---|
@@ -1,62 +1,79 @@ | ||
package com.example.kkneed.screen.search | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.* | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavController | ||
import androidx.navigation.compose.rememberNavController | ||
import com.example.kkneed.R | ||
import com.example.kkneed.screen.shop.SearchScreen | ||
import com.example.kkneed.ui.* | ||
import com.example.kkneed.ui.theme.KKNeedTheme | ||
import com.example.kkneed.viewmodel.ProductViewModel | ||
|
||
@OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class) | ||
@SuppressLint("UnusedMaterialScaffoldPaddingParameter") | ||
@Composable | ||
fun CompareScreen(navController: NavController) { | ||
fun CompareScreen(navController: NavController, barcode: String, viewModel: ProductViewModel = hiltViewModel()) { | ||
val productLeft = viewModel.queryProduct(barcode) | ||
// Log.d("m",productLeft.nutriments.energyKj100g!!.toFloat().toString()) | ||
val productRight = viewModel.nowProduct.value | ||
Scaffold( | ||
topBar = { | ||
MostUseTopAppBar(appBarHeight = 64.dp, navController =navController, "产品对比") }) | ||
MostUseTopAppBar(appBarHeight = 64.dp, navController = navController, "产品对比") | ||
}) | ||
{ | ||
Column(modifier = Modifier.fillMaxWidth(), | ||
LazyColumn( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.spacedBy(12.dp)) { | ||
Row(modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(start = 16.dp, end = 16.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween){ | ||
CompareCard("百事可乐") | ||
CompareCard("农夫山泉东方树叶红茶500ml") | ||
verticalArrangement = Arrangement.spacedBy(12.dp) | ||
) { | ||
item { | ||
Column { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(start = 16.dp, end = 16.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween | ||
) { | ||
CompareCard( | ||
navController, | ||
productLeft.productName, | ||
productLeft.imageUrl, | ||
productLeft.scoreGrade, | ||
) | ||
CompareCard( | ||
navController, | ||
productRight?.productName ?: productLeft.productName, | ||
productRight?.productName ?: productLeft.imageUrl, | ||
productRight?.productName ?: productLeft.scoreGrade, | ||
) | ||
} | ||
Spacer(modifier = Modifier.size(12.dp)) | ||
NutriCompareCard(productLeft, productRight ?: productLeft) | ||
Spacer(modifier = Modifier.size(12.dp)) | ||
ComponentCompareCard(productLeft,productRight ?: productLeft) | ||
} | ||
} | ||
item { | ||
Spacer(modifier = Modifier.size(40.dp)) | ||
} | ||
NutriCompareCard() | ||
ComponentCompareCard() | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
} | ||
@Preview | ||
@Composable | ||
fun PreviewCompareScreen() { | ||
KKNeedTheme { | ||
val navController = rememberNavController() | ||
CompareScreen(navController) | ||
// CompareScreen(navController) | ||
} | ||
} | ||
|
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.