Update Jetpack Compose

This commit is contained in:
MM20 2022-02-09 20:07:47 +01:00
parent 23d0b72e12
commit e3f82512b7
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
6 changed files with 154 additions and 157 deletions

View File

@ -61,7 +61,7 @@ dependencyResolutionManagement {
listOf("kotlin.stdlib", "kotlinx.coroutines.core", "kotlinx.coroutines.android") listOf("kotlin.stdlib", "kotlinx.coroutines.core", "kotlinx.coroutines.android")
) )
version("androidx.compose", "1.2.0-alpha02") version("androidx.compose", "1.2.0-alpha03")
alias("androidx.compose.runtime") alias("androidx.compose.runtime")
.to("androidx.compose.runtime", "runtime") .to("androidx.compose.runtime", "runtime")
.versionRef("androidx.compose") .versionRef("androidx.compose")
@ -94,7 +94,7 @@ dependencyResolutionManagement {
.versionRef("androidx.compose") .versionRef("androidx.compose")
alias("androidx.compose.material3") alias("androidx.compose.material3")
.to("androidx.compose.material3", "material3") .to("androidx.compose.material3", "material3")
.version("1.0.0-alpha04") .version("1.0.0-alpha05")
version("androidx.lifecycle", "2.4.0-rc01") version("androidx.lifecycle", "2.4.0-rc01")
alias("androidx.lifecycle.viewmodel") alias("androidx.lifecycle.viewmodel")

View File

@ -2,23 +2,15 @@ package de.mm20.launcher2.ui.component
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material3.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.* import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.integerResource import androidx.compose.ui.res.integerResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import de.mm20.launcher2.favorites.FavoritesRepository
import de.mm20.launcher2.search.data.Searchable
import de.mm20.launcher2.ui.R import de.mm20.launcher2.ui.R
import org.koin.androidx.compose.getViewModel
import org.koin.androidx.compose.inject
import kotlin.math.min import kotlin.math.min
@Composable @Composable
@ -49,7 +41,8 @@ fun Icons(actions: List<ToolbarAction>, slots: Int) {
} }
DropdownMenu( DropdownMenu(
expanded = showMenu, expanded = showMenu,
onDismissRequest = { showMenu = false } onDismissRequest = { showMenu = false },
modifier = Modifier.animateContentSize()
) { ) {
OverflowMenuItems(items = actions.subList(slots - 1, actions.size)) { OverflowMenuItems(items = actions.subList(slots - 1, actions.size)) {
showMenu = false showMenu = false
@ -64,11 +57,6 @@ fun Icons(actions: List<ToolbarAction>, slots: Int) {
Icon(action.icon, contentDescription = action.label) Icon(action.icon, contentDescription = action.label)
} }
} }
is ToggleToolbarAction -> {
IconToggleButton(action.isChecked, action.onCheckedChange) {
Icon(action.icon, contentDescription = action.label)
}
}
is SubmenuToolbarAction -> { is SubmenuToolbarAction -> {
Box { Box {
var showMenu by remember { mutableStateOf(false) } var showMenu by remember { mutableStateOf(false) }
@ -102,34 +90,25 @@ fun ColumnScope.OverflowMenuItems(items: List<ToolbarAction>, onDismiss: () -> U
is SubmenuToolbarAction -> { is SubmenuToolbarAction -> {
DropdownMenuItem( DropdownMenuItem(
onClick = { selectedSubMenu = i }, onClick = { selectedSubMenu = i },
) { text = {
Text( Text(
action.label, modifier = Modifier.weight(1f), action.label, modifier = Modifier.weight(1f),
style = MaterialTheme.typography.titleMedium )
) }
Icon(imageVector = Icons.Rounded.ArrowRight, contentDescription = null) )
}
}
is ToggleToolbarAction -> {
DropdownMenuItem(
onClick = { action.onCheckedChange(!action.isChecked) },
) {
Text(
action.label,
style = MaterialTheme.typography.titleMedium
)
}
} }
is DefaultToolbarAction -> { is DefaultToolbarAction -> {
DropdownMenuItem(onClick = { DropdownMenuItem(
action.action onClick = {
onDismiss() action.action()
}) { onDismiss()
Text( },
action.label, text = {
style = MaterialTheme.typography.titleMedium Text(
) action.label,
} )
}
)
} }
} }
} }
@ -155,10 +134,3 @@ data class SubmenuToolbarAction(
override val icon: ImageVector, override val icon: ImageVector,
val children: List<ToolbarAction> val children: List<ToolbarAction>
) : ToolbarAction ) : ToolbarAction
data class ToggleToolbarAction(
override val label: String,
override val icon: ImageVector,
val isChecked: Boolean,
val onCheckedChange: (Boolean) -> Unit
) : ToolbarAction

View File

@ -9,14 +9,12 @@ import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material3.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AcUnit import androidx.compose.material.icons.rounded.AcUnit
import androidx.compose.material.icons.rounded.Air import androidx.compose.material.icons.rounded.Air
import androidx.compose.material.icons.rounded.Bolt import androidx.compose.material.icons.rounded.Bolt
import androidx.compose.material.icons.rounded.Thermostat import androidx.compose.material.icons.rounded.Thermostat
import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -69,7 +67,7 @@ private fun SunMoon(icon: WeatherIcon, night: Boolean) {
val transition = updateTransition(targetState = icon, "AnimatedWeatherIcon") val transition = updateTransition(targetState = icon, "AnimatedWeatherIcon")
val color by animateColorAsState( val color by animateColorAsState(
if (night)colorResource(id = R.color.weather_moon) else colorResource(id = R.color.weather_sun) if (night) colorResource(id = R.color.weather_moon) else colorResource(id = R.color.weather_sun)
) )
val scale by transition.animateFloat(label = "sunScale") { val scale by transition.animateFloat(label = "sunScale") {
when (it) { when (it) {
@ -487,12 +485,15 @@ fun AnimatedWeatherIconTestPanel() {
var menu by remember { mutableStateOf(false) } var menu by remember { mutableStateOf(false) }
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) { DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
for (ic in icons) { for (ic in icons) {
DropdownMenuItem(onClick = { DropdownMenuItem(
icon = ic onClick = {
menu = false icon = ic
}) { menu = false
Text(text = ic.name) },
} text = {
Text(text = ic.name)
}
)
} }
} }
Button(onClick = { menu = true }) { Button(onClick = { menu = true }) {

View File

@ -18,8 +18,6 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Search import androidx.compose.material.icons.rounded.Search
import androidx.compose.material3.* import androidx.compose.material3.*
@ -78,35 +76,47 @@ fun SearchBar(
style = style, style = style,
overflowMenu = { show, onDismissRequest -> overflowMenu = { show, onDismissRequest ->
DropdownMenu(expanded = show, onDismissRequest = onDismissRequest) { DropdownMenu(expanded = show, onDismissRequest = onDismissRequest) {
DropdownMenuItem(onClick = { DropdownMenuItem(
activityViewModel.showEditFavorites() onClick = {
onDismissRequest() activityViewModel.showEditFavorites()
}) { onDismissRequest()
Text(stringResource(R.string.menu_item_edit_favs)) },
} text = {
DropdownMenuItem(onClick = { Text(stringResource(R.string.menu_item_edit_favs))
activityViewModel.showHiddenItems() }
onDismissRequest() )
}) { DropdownMenuItem(
Text(stringResource(R.string.menu_hidden_items)) onClick = {
} activityViewModel.showHiddenItems()
DropdownMenuItem(onClick = { onDismissRequest()
context.startActivity( },
Intent.createChooser( text = {
Intent(Intent.ACTION_SET_WALLPAPER), Text(stringResource(R.string.menu_hidden_items))
null }
)
DropdownMenuItem(
onClick = {
context.startActivity(
Intent.createChooser(
Intent(Intent.ACTION_SET_WALLPAPER),
null
)
) )
) onDismissRequest()
onDismissRequest() },
}) { text = {
Text(stringResource(R.string.wallpaper)) Text(stringResource(R.string.wallpaper))
} }
DropdownMenuItem(onClick = { )
context.startActivity(Intent(context, SettingsActivity::class.java)) DropdownMenuItem(
onDismissRequest() onClick = {
}) { context.startActivity(Intent(context, SettingsActivity::class.java))
Text(stringResource(R.string.settings)) onDismissRequest()
} },
text = {
Text(stringResource(R.string.settings))
}
)
} }
}, },
onFocus = onFocus, onFocus = onFocus,

View File

@ -10,8 +10,6 @@ import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowDropDown import androidx.compose.material.icons.rounded.ArrowDropDown
import androidx.compose.material.icons.rounded.LightMode import androidx.compose.material.icons.rounded.LightMode
@ -73,7 +71,10 @@ fun WeatherWidget() {
TextButton(onClick = { TextButton(onClick = {
showLocationDialog = true showLocationDialog = true
}) { }) {
Text(stringResource(R.string.weather_widget_set_location), style = MaterialTheme.typography.labelLarge) Text(
stringResource(R.string.weather_widget_set_location),
style = MaterialTheme.typography.labelLarge
)
} }
} }
) )
@ -291,32 +292,33 @@ fun WeatherDaySelector(
onClick = { onClick = {
menuExpanded.value = false menuExpanded.value = false
onDaySelected(i) onDaySelected(i)
},
text = {
Row {
WeatherIcon(icon = weatherIconById(d.icon))
Text(
text = dateFormat.format(d.timestamp),
style = MaterialTheme.typography.titleSmall,
softWrap = false,
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(start = 16.dp, end = 8.dp)
.weight(1f)
)
Text(
text = "${
convertTemperature(
imperialUnits,
d.minTemp
)
}° / ${convertTemperature(imperialUnits, d.maxTemp)}°",
softWrap = false,
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.align(Alignment.CenterVertically)
)
}
} }
) { )
Row {
WeatherIcon(icon = weatherIconById(d.icon))
Text(
text = dateFormat.format(d.timestamp),
style = MaterialTheme.typography.titleSmall,
softWrap = false,
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(start = 16.dp, end = 8.dp)
.weight(1f)
)
Text(
text = "${
convertTemperature(
imperialUnits,
d.minTemp
)
}° / ${convertTemperature(imperialUnits, d.maxTemp)}°",
softWrap = false,
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.align(Alignment.CenterVertically)
)
}
}
} }
} }
} }
@ -362,29 +364,32 @@ fun WeatherTimeSelector(
}) { }) {
for ((i, fc) in forecasts.withIndex()) { for ((i, fc) in forecasts.withIndex()) {
DropdownMenuItem(onClick = { DropdownMenuItem(
menuExpanded.value = false onClick = {
onTimeSelected(i) menuExpanded.value = false
}) { onTimeSelected(i)
Row { },
WeatherIcon(icon = weatherIconById(fc.icon), night = fc.night) text = {
Text( Row {
text = dateFormat.format(fc.timestamp), WeatherIcon(icon = weatherIconById(fc.icon), night = fc.night)
style = MaterialTheme.typography.titleSmall, Text(
softWrap = false, text = dateFormat.format(fc.timestamp),
modifier = Modifier style = MaterialTheme.typography.titleSmall,
.align(Alignment.CenterVertically) softWrap = false,
.padding(start = 16.dp, end = 8.dp) modifier = Modifier
.weight(1f) .align(Alignment.CenterVertically)
) .padding(start = 16.dp, end = 8.dp)
Text( .weight(1f)
text = "${convertTemperature(imperialUnits, fc.temperature)}°", )
softWrap = false, Text(
style = MaterialTheme.typography.titleSmall, text = "${convertTemperature(imperialUnits, fc.temperature)}°",
modifier = Modifier.align(Alignment.CenterVertically) softWrap = false,
) style = MaterialTheme.typography.titleSmall,
modifier = Modifier.align(Alignment.CenterVertically)
)
}
} }
} )
} }
} }

View File

@ -12,8 +12,6 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.OutlinedTextField import androidx.compose.material.OutlinedTextField
import androidx.compose.material.TextField import androidx.compose.material.TextField
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@ -232,15 +230,16 @@ fun EditWebsearchDialog(
DropdownMenu( DropdownMenu(
expanded = showDropdown, expanded = showDropdown,
onDismissRequest = { showDropdown = false }) { onDismissRequest = { showDropdown = false }) {
DropdownMenuItem(onClick = { DropdownMenuItem(
onValueDeleted(value) text = {
onCancel() Text(
}) { text = stringResource(R.string.menu_delete)
Text( )
text = stringResource(R.string.menu_delete), },
style = MaterialTheme.typography.labelLarge onClick = {
) onValueDeleted(value)
} onCancel()
})
} }
} }
} }
@ -266,7 +265,10 @@ fun EditWebsearchDialog(
}, },
modifier = Modifier.padding(4.dp) modifier = Modifier.padding(4.dp)
) { ) {
Text(stringResource(R.string.websearch_dialog_replace_icon), style = MaterialTheme.typography.labelLarge) Text(
stringResource(R.string.websearch_dialog_replace_icon),
style = MaterialTheme.typography.labelLarge
)
} }
TextButton( TextButton(
onClick = { onClick = {
@ -277,7 +279,10 @@ fun EditWebsearchDialog(
contentColor = MaterialTheme.colorScheme.error contentColor = MaterialTheme.colorScheme.error
) )
) { ) {
Text(stringResource(R.string.websearch_dialog_delete_icon), style = MaterialTheme.typography.labelLarge) Text(
stringResource(R.string.websearch_dialog_delete_icon),
style = MaterialTheme.typography.labelLarge
)
} }
} }
} else { } else {
@ -411,7 +416,11 @@ private fun ColorPicker(
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
var textFieldValue by remember(value) { mutableStateOf(Color(value).toHexString().substring(1)) } var textFieldValue by remember(value) {
mutableStateOf(
Color(value).toHexString().substring(1)
)
}
TextField( TextField(
value = textFieldValue, value = textFieldValue,
leadingIcon = { leadingIcon = {
@ -425,7 +434,7 @@ private fun ColorPicker(
}, },
singleLine = true, singleLine = true,
modifier = Modifier.width(150.dp) modifier = Modifier.width(150.dp)
) )
TextButton(onClick = { showCustomColorPicker = false }) { TextButton(onClick = { showCustomColorPicker = false }) {
Text( Text(
stringResource(android.R.string.ok), stringResource(android.R.string.ok),