-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FE-1564 Feature/fe 1498 refactor rangeselectorview as a composable (#474
) * [WIP] Range selector view as composable * Fix issue of charts not loading properly when API replies very fast
- Loading branch information
Showing
13 changed files
with
170 additions
and
149 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
54 changes: 0 additions & 54 deletions
54
app/src/main/java/com/weatherxm/ui/components/RangeSelectorView.kt
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/weatherxm/ui/components/compose/RangeSelectorView.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,87 @@ | ||
package com.weatherxm.ui.components.compose | ||
|
||
import androidx.compose.foundation.layout.Arrangement.spacedBy | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.selection.toggleable | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.weatherxm.R | ||
|
||
@Suppress("FunctionNaming") | ||
@Preview | ||
@Composable | ||
fun RangeSelectorView( | ||
selectedChipLabelResId: Int = R.string.seven_days_abbr, | ||
enabledToggle: Boolean = true, | ||
onSelectedChanged: (Int) -> Unit = {}, | ||
) { | ||
val sevenDaysAbbrResId = R.string.seven_days_abbr | ||
val oneMonthAbbrResId = R.string.one_month_abbr | ||
Card( | ||
colors = CardDefaults.cardColors( | ||
containerColor = colorResource(R.color.layer1) | ||
), | ||
shape = RoundedCornerShape(dimensionResource(R.dimen.radius_small)) | ||
) { | ||
Row( | ||
modifier = Modifier.padding(dimensionResource(R.dimen.padding_extra_small)), | ||
horizontalArrangement = spacedBy(dimensionResource(R.dimen.margin_extra_small)) | ||
) { | ||
Chip( | ||
labelResId = sevenDaysAbbrResId, | ||
isSelected = sevenDaysAbbrResId == selectedChipLabelResId, | ||
enabledToggle = enabledToggle, | ||
onSelectionChanged = { onSelectedChanged(it) }, | ||
) | ||
Chip( | ||
labelResId = oneMonthAbbrResId, | ||
isSelected = oneMonthAbbrResId == selectedChipLabelResId, | ||
enabledToggle = enabledToggle, | ||
onSelectionChanged = { onSelectedChanged(it) }, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Suppress("FunctionNaming") | ||
@Preview | ||
@Composable | ||
fun Chip( | ||
labelResId: Int = R.string.seven_days_abbr, | ||
isSelected: Boolean = false, | ||
enabledToggle: Boolean = true, | ||
onSelectionChanged: (Int) -> Unit = {}, | ||
) { | ||
Surface( | ||
shape = RoundedCornerShape(dimensionResource(R.dimen.radius_small)), | ||
color = if (isSelected) colorResource(R.color.layer2) else colorResource(R.color.layer1) | ||
) { | ||
Row(modifier = Modifier | ||
.padding( | ||
dimensionResource(R.dimen.padding_normal), | ||
dimensionResource(R.dimen.padding_small_to_normal) | ||
) | ||
.toggleable( | ||
value = isSelected, | ||
enabled = enabledToggle, | ||
onValueChange = { | ||
onSelectionChanged(labelResId) | ||
} | ||
) | ||
) { | ||
MediumText( | ||
text = stringResource(labelResId), | ||
colorRes = R.color.darkGrey, | ||
) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.