Move app icon composables outside of mutable Fragment class.

This way, the composables do not receive an implicit mutable parameter, which allows the compiler to mark them as skippable.
This commit is contained in:
Nicholas Tinsley 2023-05-19 10:57:07 -04:00 committed by Greyson Parrelli
parent d7c06fff50
commit 131f9c4bc9

View file

@ -87,11 +87,20 @@ class AppIconSelectionFragment : ComposeFragment() {
findNavController().safeNavigate(R.id.action_appIconSelectionFragment_to_appIconTutorialFragment)
}
/**
companion object {
val TAG = Log.tag(AppIconSelectionFragment::class.java)
}
}
private const val LEARN_MORE_TAG = "learn_more"
private const val URL_TAG = "URL"
private const val COLUMN_COUNT = 4
/**
* Screen allowing the user to view all the possible icon and select a new one to use.
*/
@Composable
fun IconSelectionScreen(activeIcon: AppIconPreset, onItemConfirmed: (AppIconPreset) -> Unit, onWarningClick: () -> Unit, modifier: Modifier = Modifier) {
@Composable
fun IconSelectionScreen(activeIcon: AppIconPreset, onItemConfirmed: (AppIconPreset) -> Unit, onWarningClick: () -> Unit, modifier: Modifier = Modifier) {
var showDialog: Boolean by remember { mutableStateOf(false) }
var pendingIcon: AppIconPreset by remember {
mutableStateOf(activeIcon)
@ -136,10 +145,10 @@ class AppIconSelectionFragment : ComposeFragment() {
}
}
}
}
}
@Composable
fun ChangeIconDialog(pendingIcon: AppIconPreset, onConfirm: () -> Unit, onDismiss: () -> Unit, modifier: Modifier = Modifier) {
@Composable
fun ChangeIconDialog(pendingIcon: AppIconPreset, onConfirm: () -> Unit, onDismiss: () -> Unit, modifier: Modifier = Modifier) {
AlertDialog(
modifier = modifier,
onDismissRequest = onDismiss,
@ -175,13 +184,13 @@ class AppIconSelectionFragment : ComposeFragment() {
)
}
)
}
}
/**
/**
* Composable rendering the one row of icons that the user may choose from.
*/
@Composable
fun IconRow(presets: ImmutableList<AppIconPreset>, isSelected: (AppIconPreset) -> Boolean, onItemClick: (AppIconPreset) -> Unit, modifier: Modifier = Modifier) {
@Composable
fun IconRow(presets: ImmutableList<AppIconPreset>, isSelected: (AppIconPreset) -> Boolean, onItemClick: (AppIconPreset) -> Unit, modifier: Modifier = Modifier) {
Row(modifier = modifier.fillMaxWidth()) {
presets.forEach { preset ->
val currentlySelected = isSelected(preset)
@ -199,13 +208,13 @@ class AppIconSelectionFragment : ComposeFragment() {
)
}
}
}
}
/**
/**
* Composable rendering an individual icon inside that grid, including the black border of the selected icon.
*/
@Composable
fun IconGridElement(preset: AppIconPreset, isSelected: Boolean, onClickHandler: () -> Unit, modifier: Modifier = Modifier) {
@Composable
fun IconGridElement(preset: AppIconPreset, isSelected: Boolean, onClickHandler: () -> Unit, modifier: Modifier = Modifier) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
@ -224,13 +233,13 @@ class AppIconSelectionFragment : ComposeFragment() {
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
}
/**
* Composable rendering the multiple layers of an adaptive icon onto one flattened rasterized Canvas.
/**
* Composable rendering the icon and optionally a border, to indicate selection.
*/
@Composable
fun AppIcon(preset: AppIconPreset, isSelected: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier) {
@Composable
fun AppIcon(preset: AppIconPreset, isSelected: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier) {
val bitmapSize by animateFloatAsState(if (isSelected) 48f else 64f, label = "Icon Size")
val imageModifier = modifier
.size(bitmapSize.dp)
@ -245,13 +254,13 @@ class AppIconSelectionFragment : ComposeFragment() {
contentDescription = stringResource(id = preset.labelResId),
modifier = imageModifier
)
}
}
/**
/**
* A clickable "learn more" block of text.
*/
@Composable
fun CaveatWarning(onClick: () -> Unit, modifier: Modifier = Modifier) {
@Composable
fun CaveatWarning(onClick: () -> Unit, modifier: Modifier = Modifier) {
val learnMoreString = stringResource(R.string.preferences__app_icon_learn_more)
val completeString = stringResource(R.string.preferences__app_icon_warning_learn_more)
val learnMoreStartIndex = completeString.indexOf(learnMoreString).coerceAtLeast(0)
@ -283,39 +292,28 @@ class AppIconSelectionFragment : ComposeFragment() {
}
ClickableText(
text = annotatedText,
onClick = { _ ->
onClick()
},
onClick = { onClick() },
style = MaterialTheme.typography.bodyMedium,
modifier = modifier
)
}
}
@Preview(name = "Light Theme")
@Composable
private fun MainScreenPreviewLight() {
@Preview(name = "Light Theme")
@Composable
private fun MainScreenPreviewLight() {
SignalTheme(isDarkMode = false) {
Surface {
IconSelectionScreen(AppIconPreset.DEFAULT, onItemConfirmed = {}, onWarningClick = {})
}
}
}
}
@Preview(name = "Dark Theme")
@Composable
private fun MainScreenPreviewDark() {
@Preview(name = "Dark Theme")
@Composable
private fun MainScreenPreviewDark() {
SignalTheme(isDarkMode = true) {
Surface {
IconSelectionScreen(AppIconPreset.DEFAULT, onItemConfirmed = {}, onWarningClick = {})
}
}
}
companion object {
val TAG = Log.tag(AppIconSelectionFragment::class.java)
private const val LEARN_MORE_TAG = "learn_more"
private const val URL_TAG = "URL"
private const val COLUMN_COUNT = 4
}
}