Skip to content

Commit

Permalink
app: Delete cornerStateCode
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Jul 13, 2024
1 parent fe61ad4 commit a7e9ed0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
9 changes: 4 additions & 5 deletions app/src/main/kotlin/top/yukonga/hq_icon/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ fun App(resultsViewModel: ResultsViewModel) {
val country = remember { mutableStateOf(Preferences().perfGet("country") ?: "CN") }
val platformCode = remember { mutableStateOf(Preferences().perfGet("platform") ?: "software") }
val resolutionCode = remember { mutableStateOf(Preferences().perfGet("resolution") ?: "512") }
val cornerStateCode = remember { mutableStateOf(Preferences().perfGet("corner") ?: "1") }
val cornerState = remember { mutableStateOf(Preferences().perfGet("corner") ?: "1") }
val limit = remember { mutableIntStateOf(15) }

val results by resultsViewModel.results.collectAsState()
val corner by resultsViewModel.corner.collectAsState()
val resolution by resultsViewModel.resolution.collectAsState()

LaunchedEffect(cornerStateCode.value, resolutionCode.value) {
resultsViewModel.updateCorner(cornerStateCode.value)
LaunchedEffect(cornerState.value, resolutionCode.value) {
resultsViewModel.updateCorner(cornerState.value)
resultsViewModel.updateResolution(resolutionCode.value)
}

Expand Down Expand Up @@ -137,7 +136,7 @@ fun App(resultsViewModel: ResultsViewModel) {
if (maxWidth < 768.dp) {
Column {
MainCardView(appName, country)
SecondCardView(platformCode, cornerStateCode, resolutionCode)
SecondCardView(platformCode, cornerState, resolutionCode)
ResultsView(results, corner, resolution)
Spacer(Modifier.height(padding.calculateBottomPadding()))
}
Expand All @@ -151,7 +150,7 @@ fun App(resultsViewModel: ResultsViewModel) {
) {
MainCardView(appName, country)
Spacer(modifier = Modifier.height(20.dp))
SecondCardView(platformCode, cornerStateCode, resolutionCode)
SecondCardView(platformCode, cornerState, resolutionCode)
Spacer(modifier = Modifier.height(20.dp))
}
Column(modifier = Modifier.weight(1.0f)) {
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/kotlin/top/yukonga/hq_icon/data/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ class Data {
return cut.resolutionName
}

data class CornerStateData(val cornerStateName: String, val cornerStateCode: String)
data class CornerData(val cornerName: String, val cornerCode: String)

private val cornerStateList = listOf(
CornerStateData("Rounded", "1"),
CornerStateData("Original", "0")
private val cornerList = listOf(
CornerData("Rounded", "1"),
CornerData("Original", "0")
)
val cornerStateNames = cornerStateList.map { it.cornerStateName }
val cornerNames = cornerList.map { it.cornerName }

fun cornerStateCode(cornerStateName: String): String {
val cornerState = cornerStateList.find { it.cornerStateName == cornerStateName } ?: return ""
return cornerState.cornerStateCode
fun cornerCode(cornerName: String): String {
val corner = cornerList.find { it.cornerName == cornerName } ?: return ""
return corner.cornerCode
}

fun cornerStateName(cornerStateCode: String): String {
val cornerState = cornerStateList.find { it.cornerStateCode == cornerStateCode } ?: return ""
return cornerState.cornerStateName
fun cornerName(cornerCode: String): String {
val corner = cornerList.find { it.cornerCode == cornerCode } ?: return ""
return corner.cornerName
}

val country = listOf("CN", "US", "JP", "KR")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import top.yukonga.hq_icon.utils.Preferences
@Composable
fun SecondCardView(
platformCode: MutableState<String>,
cornerStateCode: MutableState<String>,
cornerCode: MutableState<String>,
resolutionCode: MutableState<String>
) {
Row(
Expand Down Expand Up @@ -61,7 +61,7 @@ fun SecondCardView(
.weight(1f)
.padding(start = 10.dp)
) {
CornerView(cornerStateCode)
CornerView(cornerCode)
}
}
Card(
Expand Down Expand Up @@ -127,9 +127,9 @@ fun PlatformView(

@Composable
fun CornerView(
cornerStateCode: MutableState<String>
cornerCode: MutableState<String>
) {
val cornerState = Data().cornerStateNames
val corner = Data().cornerNames
val hapticFeedback = LocalHapticFeedback.current

Column(
Expand All @@ -139,21 +139,22 @@ fun CornerView(
Text(
text = stringResource(R.string.corner)
)
val cornerStateName = Preferences().perfGet("corner")?.let { Data().cornerStateName(it) } ?: cornerState[0]
val (selectedOption, onOptionSelected) = remember { mutableStateOf(cornerStateName) }
val cornerName = Preferences().perfGet("corner")?.let { Data().cornerName(it) } ?: corner[0]
val (selectedOption, onOptionSelected) = remember { mutableStateOf(cornerName) }
Column(
modifier = Modifier.selectableGroup(),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
cornerState.forEach { text ->
corner.forEach { text ->
Row(
Modifier
.selectable(
selected = (text == selectedOption),
onClick = {
onOptionSelected(text)
hapticFeedback.performHapticFeedback(LongPress)
cornerStateCode.value = Data().cornerStateCode(text)
cornerCode.value = Data().cornerCode(text)
Preferences().perfSet("corner", cornerCode.value)
},
role = Role.RadioButton
)
Expand Down

0 comments on commit a7e9ed0

Please sign in to comment.