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