Skip to content

Commit

Permalink
fix(android): fix widget aspect ratio and height in creator
Browse files Browse the repository at this point in the history
  • Loading branch information
autoreleasefool committed Jun 22, 2024
1 parent 06813b4 commit 23b604c
Showing 1 changed file with 78 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ca.josephroque.bowlingcompanion.feature.statisticswidget.ui.editor

import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredWidthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.HorizontalDivider
Expand All @@ -28,84 +30,91 @@ fun StatisticsWidgetEditor(
onAction: (StatisticsWidgetEditorUiAction) -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
BoxWithConstraints(
modifier = modifier.fillMaxSize(),
) {
if (state.widget != null) {
StatisticsWidgetCard(
widget = state.widget,
chart = state.preview?.chart,
chartEntryModelProducer = state.preview?.modelProducer,
modifier = Modifier
.aspectRatio(2f)
.padding(horizontal = 16.dp),
)
val shouldLimitSize = maxWidth >= 500.dp

Text(
text = stringResource(R.string.statistics_widget_editor_preview),
style = MaterialTheme.typography.labelSmall,
modifier = Modifier
.padding(horizontal = 16.dp)
.padding(top = 4.dp, bottom = 8.dp)
.align(Alignment.CenterHorizontally),
)
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
) {
if (state.widget != null) {
StatisticsWidgetCard(
widget = state.widget,
chart = state.preview?.chart,
chartEntryModelProducer = state.preview?.modelProducer,
modifier = Modifier
.then(if (shouldLimitSize) Modifier.requiredWidthIn(max = 320.dp) else Modifier)
.aspectRatio(2f)
.padding(horizontal = 16.dp),
)

HorizontalDivider()
}
Text(
text = stringResource(R.string.statistics_widget_editor_preview),
style = MaterialTheme.typography.labelSmall,
modifier = Modifier
.padding(horizontal = 16.dp)
.padding(top = 4.dp, bottom = 8.dp)
.align(Alignment.CenterHorizontally),
)

ListSectionFooter(
footer = stringResource(R.string.statistics_widget_editor_filter_description),
)
HorizontalDivider()
}

PickableResourceCard(
resourceName = stringResource(R.string.statistics_widget_editor_filter_bowler),
selectedName = state.bowler?.name ?: stringResource(
ca.josephroque.bowlingcompanion.core.designsystem.R.string.none,
),
onClick = { onAction(StatisticsWidgetEditorUiAction.BowlerClicked) },
)
ListSectionFooter(
footer = stringResource(R.string.statistics_widget_editor_filter_description),
)

PickableResourceCard(
resourceName = stringResource(R.string.statistics_widget_editor_filter_league),
selectedName = state.league?.name ?: stringResource(
ca.josephroque.bowlingcompanion.core.designsystem.R.string.none,
),
onClick = { onAction(StatisticsWidgetEditorUiAction.LeagueClicked) },
enabled = state.bowler != null,
)
PickableResourceCard(
resourceName = stringResource(R.string.statistics_widget_editor_filter_bowler),
selectedName = state.bowler?.name ?: stringResource(
ca.josephroque.bowlingcompanion.core.designsystem.R.string.none,
),
onClick = { onAction(StatisticsWidgetEditorUiAction.BowlerClicked) },
)

HorizontalDivider()
PickableResourceCard(
resourceName = stringResource(R.string.statistics_widget_editor_filter_league),
selectedName = state.league?.name ?: stringResource(
ca.josephroque.bowlingcompanion.core.designsystem.R.string.none,
),
onClick = { onAction(StatisticsWidgetEditorUiAction.LeagueClicked) },
enabled = state.bowler != null,
)

PickableResourceCard(
resourceName = stringResource(R.string.statistics_widget_editor_statistic),
selectedName = stringResource(state.statistic.id.titleResourceId),
onClick = { onAction(StatisticsWidgetEditorUiAction.StatisticClicked) },
)
HorizontalDivider()

PickableResourceCard(
resourceName = stringResource(R.string.statistics_widget_editor_statistic),
selectedName = stringResource(state.statistic.id.titleResourceId),
onClick = { onAction(StatisticsWidgetEditorUiAction.StatisticClicked) },
)

HorizontalDivider()
HorizontalDivider()

FormRadioGroup(
titleResourceId = R.string.statistics_widget_timeline,
subtitleResourceId = R.string.statistics_widget_editor_timeline_description,
options = StatisticsWidgetTimeline.entries.toTypedArray(),
selected = state.timeline,
titleForOption = {
if (it == null) {
""
} else {
stringResource(it.titleResourceId())
}
},
onOptionSelected = {
it?.let {
onAction(
StatisticsWidgetEditorUiAction.TimelineSelected(it),
)
}
},
modifier = Modifier.padding(top = 16.dp),
)
FormRadioGroup(
titleResourceId = R.string.statistics_widget_timeline,
subtitleResourceId = R.string.statistics_widget_editor_timeline_description,
options = StatisticsWidgetTimeline.entries.toTypedArray(),
selected = state.timeline,
titleForOption = {
if (it == null) {
""
} else {
stringResource(it.titleResourceId())
}
},
onOptionSelected = {
it?.let {
onAction(
StatisticsWidgetEditorUiAction.TimelineSelected(it),
)
}
},
modifier = Modifier.padding(top = 16.dp),
)
}
}
}

0 comments on commit 23b604c

Please sign in to comment.