This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give life to some settings items in settings screen
- Loading branch information
Showing
10 changed files
with
389 additions
and
28 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
...ings/src/main/java/com/ankitsuda/rebound/ui/components/settings/PopupItemsSettingsItem.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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) 2022 Ankit Suda. | ||
* | ||
* Licensed under the GNU General Public License v3 | ||
* | ||
* This is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
*/ | ||
|
||
package com.ankitsuda.rebound.ui.components.settings | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.unit.dp | ||
import com.ankitsuda.base.util.isDark | ||
import com.ankitsuda.rebound.ui.theme.LocalThemeState | ||
import com.ankitsuda.rebound.ui.theme.ReboundTheme | ||
|
||
@Composable | ||
fun <A> PopupItemsSettingsItem( | ||
modifier: Modifier = Modifier, | ||
icon: ImageVector? = null, | ||
text: String, | ||
description: String = "", | ||
selectedItem: A? = null, | ||
items: List<Pair<A, String>>, | ||
onItemSelected: (A) -> Unit | ||
) { | ||
var isMenuExpanded by remember { | ||
mutableStateOf(false) | ||
} | ||
|
||
Box(modifier = modifier.clickable(onClick = { | ||
isMenuExpanded = true | ||
})) { | ||
Row( | ||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 20.dp), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
if (icon != null) { | ||
Icon( | ||
imageVector = icon, | ||
contentDescription = text, | ||
tint = LocalThemeState.current.onBackgroundColor, | ||
modifier = Modifier.padding(start = 2.dp, end = 18.dp) | ||
) | ||
} | ||
Column( | ||
modifier = Modifier.weight(1f) | ||
) { | ||
Text( | ||
text = text, | ||
color = LocalThemeState.current.onBackgroundColor | ||
) | ||
if (description.isNotEmpty()) { | ||
Text( | ||
text = description, | ||
style = ReboundTheme.typography.caption, | ||
color = ReboundTheme.colors.onBackground.copy(alpha = 0.8f), | ||
) | ||
} | ||
} | ||
Box { | ||
DropdownMenu( | ||
expanded = isMenuExpanded, | ||
onDismissRequest = { isMenuExpanded = false }) { | ||
for (item in items) { | ||
val bgColor = if (selectedItem == item.first) { | ||
if (MaterialTheme.colors.surface.isDark()) { | ||
Color.White | ||
} else { | ||
Color.Black | ||
}.copy(alpha = 0.1f) | ||
} else { | ||
Color.Transparent | ||
} | ||
|
||
DropdownMenuItem( | ||
modifier = Modifier.background(bgColor), | ||
onClick = { | ||
isMenuExpanded = false | ||
onItemSelected(item.first) | ||
}) { | ||
Text(text = item.second) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
57 changes: 57 additions & 0 deletions
57
modules/domain/src/main/java/com/ankitsuda/rebound/domain/DistanceUnit.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2022 Ankit Suda. | ||
* | ||
* Licensed under the GNU General Public License v3 | ||
* | ||
* This is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
*/ | ||
|
||
package com.ankitsuda.rebound.domain | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.Serializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
@Serializable | ||
enum class DistanceUnit(val value: String) { | ||
KM("km"), | ||
MILES("miles"); | ||
|
||
companion object { | ||
fun fromValue(value: String): DistanceUnit { | ||
return values().find { it.value == value } ?: KM | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Serializer(forClass = DistanceUnit::class) | ||
object DistanceUnitSerializer : KSerializer<DistanceUnit> { | ||
override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("DistanceUnit", PrimitiveKind.STRING) | ||
|
||
override fun serialize(encoder: Encoder, value: DistanceUnit) { | ||
encoder.encodeString(value.value) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): DistanceUnit { | ||
return try { | ||
val key = decoder.decodeString() | ||
DistanceUnit.fromValue(key) | ||
} catch (e: IllegalArgumentException) { | ||
DistanceUnit.KM | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
modules/domain/src/main/java/com/ankitsuda/rebound/domain/WeightUnit.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2022 Ankit Suda. | ||
* | ||
* Licensed under the GNU General Public License v3 | ||
* | ||
* This is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
*/ | ||
|
||
package com.ankitsuda.rebound.domain | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.Serializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
@Serializable | ||
enum class WeightUnit(val value: String) { | ||
KG("kg"), | ||
LBS("lbs"); | ||
|
||
companion object { | ||
fun fromValue(value: String): WeightUnit { | ||
return values().find { it.value == value } ?: KG | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Serializer(forClass = WeightUnit::class) | ||
object WeightUnitSerializer : KSerializer<WeightUnit> { | ||
override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("WeightUnit", PrimitiveKind.STRING) | ||
|
||
override fun serialize(encoder: Encoder, value: WeightUnit) { | ||
encoder.encodeString(value.value) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): WeightUnit { | ||
return try { | ||
val key = decoder.decodeString() | ||
WeightUnit.fromValue(key) | ||
} catch (e: IllegalArgumentException) { | ||
WeightUnit.KG | ||
} | ||
} | ||
} |
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.