Update Jetpack Compose
This commit is contained in:
parent
23d0b72e12
commit
e3f82512b7
@ -61,7 +61,7 @@ dependencyResolutionManagement {
|
||||
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")
|
||||
.to("androidx.compose.runtime", "runtime")
|
||||
.versionRef("androidx.compose")
|
||||
@ -94,7 +94,7 @@ dependencyResolutionManagement {
|
||||
.versionRef("androidx.compose")
|
||||
alias("androidx.compose.material3")
|
||||
.to("androidx.compose.material3", "material3")
|
||||
.version("1.0.0-alpha04")
|
||||
.version("1.0.0-alpha05")
|
||||
|
||||
version("androidx.lifecycle", "2.4.0-rc01")
|
||||
alias("androidx.lifecycle.viewmodel")
|
||||
|
||||
@ -2,23 +2,15 @@ package de.mm20.launcher2.ui.component
|
||||
|
||||
import androidx.compose.animation.animateContentSize
|
||||
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.rounded.*
|
||||
import androidx.compose.material.icons.rounded.MoreVert
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.integerResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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 org.koin.androidx.compose.getViewModel
|
||||
import org.koin.androidx.compose.inject
|
||||
import kotlin.math.min
|
||||
|
||||
@Composable
|
||||
@ -49,7 +41,8 @@ fun Icons(actions: List<ToolbarAction>, slots: Int) {
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = showMenu,
|
||||
onDismissRequest = { showMenu = false }
|
||||
onDismissRequest = { showMenu = false },
|
||||
modifier = Modifier.animateContentSize()
|
||||
) {
|
||||
OverflowMenuItems(items = actions.subList(slots - 1, actions.size)) {
|
||||
showMenu = false
|
||||
@ -64,11 +57,6 @@ fun Icons(actions: List<ToolbarAction>, slots: Int) {
|
||||
Icon(action.icon, contentDescription = action.label)
|
||||
}
|
||||
}
|
||||
is ToggleToolbarAction -> {
|
||||
IconToggleButton(action.isChecked, action.onCheckedChange) {
|
||||
Icon(action.icon, contentDescription = action.label)
|
||||
}
|
||||
}
|
||||
is SubmenuToolbarAction -> {
|
||||
Box {
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
@ -102,34 +90,25 @@ fun ColumnScope.OverflowMenuItems(items: List<ToolbarAction>, onDismiss: () -> U
|
||||
is SubmenuToolbarAction -> {
|
||||
DropdownMenuItem(
|
||||
onClick = { selectedSubMenu = i },
|
||||
) {
|
||||
Text(
|
||||
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
|
||||
)
|
||||
}
|
||||
text = {
|
||||
Text(
|
||||
action.label, modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
is DefaultToolbarAction -> {
|
||||
DropdownMenuItem(onClick = {
|
||||
action.action
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(
|
||||
action.label,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
}
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
action.action()
|
||||
onDismiss()
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
action.label,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -154,11 +133,4 @@ data class SubmenuToolbarAction(
|
||||
override val label: String,
|
||||
override val icon: ImageVector,
|
||||
val children: List<ToolbarAction>
|
||||
) : ToolbarAction
|
||||
|
||||
data class ToggleToolbarAction(
|
||||
override val label: String,
|
||||
override val icon: ImageVector,
|
||||
val isChecked: Boolean,
|
||||
val onCheckedChange: (Boolean) -> Unit
|
||||
) : ToolbarAction
|
||||
) : ToolbarAction
|
||||
@ -9,14 +9,12 @@ import androidx.compose.animation.graphics.res.animatedVectorResource
|
||||
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
|
||||
import androidx.compose.animation.graphics.vector.AnimatedImageVector
|
||||
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.rounded.AcUnit
|
||||
import androidx.compose.material.icons.rounded.Air
|
||||
import androidx.compose.material.icons.rounded.Bolt
|
||||
import androidx.compose.material.icons.rounded.Thermostat
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@ -69,7 +67,7 @@ private fun SunMoon(icon: WeatherIcon, night: Boolean) {
|
||||
val transition = updateTransition(targetState = icon, "AnimatedWeatherIcon")
|
||||
|
||||
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") {
|
||||
when (it) {
|
||||
@ -487,12 +485,15 @@ fun AnimatedWeatherIconTestPanel() {
|
||||
var menu by remember { mutableStateOf(false) }
|
||||
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
|
||||
for (ic in icons) {
|
||||
DropdownMenuItem(onClick = {
|
||||
icon = ic
|
||||
menu = false
|
||||
}) {
|
||||
Text(text = ic.name)
|
||||
}
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
icon = ic
|
||||
menu = false
|
||||
},
|
||||
text = {
|
||||
Text(text = ic.name)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Button(onClick = { menu = true }) {
|
||||
|
||||
@ -18,8 +18,6 @@ import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
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.rounded.Search
|
||||
import androidx.compose.material3.*
|
||||
@ -78,35 +76,47 @@ fun SearchBar(
|
||||
style = style,
|
||||
overflowMenu = { show, onDismissRequest ->
|
||||
DropdownMenu(expanded = show, onDismissRequest = onDismissRequest) {
|
||||
DropdownMenuItem(onClick = {
|
||||
activityViewModel.showEditFavorites()
|
||||
onDismissRequest()
|
||||
}) {
|
||||
Text(stringResource(R.string.menu_item_edit_favs))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
activityViewModel.showHiddenItems()
|
||||
onDismissRequest()
|
||||
}) {
|
||||
Text(stringResource(R.string.menu_hidden_items))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
context.startActivity(
|
||||
Intent.createChooser(
|
||||
Intent(Intent.ACTION_SET_WALLPAPER),
|
||||
null
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
activityViewModel.showEditFavorites()
|
||||
onDismissRequest()
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.menu_item_edit_favs))
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
activityViewModel.showHiddenItems()
|
||||
onDismissRequest()
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.menu_hidden_items))
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
context.startActivity(
|
||||
Intent.createChooser(
|
||||
Intent(Intent.ACTION_SET_WALLPAPER),
|
||||
null
|
||||
)
|
||||
)
|
||||
)
|
||||
onDismissRequest()
|
||||
}) {
|
||||
Text(stringResource(R.string.wallpaper))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
context.startActivity(Intent(context, SettingsActivity::class.java))
|
||||
onDismissRequest()
|
||||
}) {
|
||||
Text(stringResource(R.string.settings))
|
||||
}
|
||||
onDismissRequest()
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.wallpaper))
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
context.startActivity(Intent(context, SettingsActivity::class.java))
|
||||
onDismissRequest()
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.settings))
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
onFocus = onFocus,
|
||||
|
||||
@ -10,8 +10,6 @@ import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
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.rounded.ArrowDropDown
|
||||
import androidx.compose.material.icons.rounded.LightMode
|
||||
@ -73,7 +71,10 @@ fun WeatherWidget() {
|
||||
TextButton(onClick = {
|
||||
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 = {
|
||||
menuExpanded.value = false
|
||||
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()) {
|
||||
DropdownMenuItem(onClick = {
|
||||
menuExpanded.value = false
|
||||
onTimeSelected(i)
|
||||
}) {
|
||||
Row {
|
||||
WeatherIcon(icon = weatherIconById(fc.icon), night = fc.night)
|
||||
Text(
|
||||
text = dateFormat.format(fc.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, fc.temperature)}°",
|
||||
softWrap = false,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
modifier = Modifier.align(Alignment.CenterVertically)
|
||||
)
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
menuExpanded.value = false
|
||||
onTimeSelected(i)
|
||||
},
|
||||
text = {
|
||||
Row {
|
||||
WeatherIcon(icon = weatherIconById(fc.icon), night = fc.night)
|
||||
Text(
|
||||
text = dateFormat.format(fc.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, fc.temperature)}°",
|
||||
softWrap = false,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
modifier = Modifier.align(Alignment.CenterVertically)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -12,8 +12,6 @@ import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
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.TextField
|
||||
import androidx.compose.material.icons.Icons
|
||||
@ -232,15 +230,16 @@ fun EditWebsearchDialog(
|
||||
DropdownMenu(
|
||||
expanded = showDropdown,
|
||||
onDismissRequest = { showDropdown = false }) {
|
||||
DropdownMenuItem(onClick = {
|
||||
onValueDeleted(value)
|
||||
onCancel()
|
||||
}) {
|
||||
Text(
|
||||
text = stringResource(R.string.menu_delete),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
)
|
||||
}
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(R.string.menu_delete)
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
onValueDeleted(value)
|
||||
onCancel()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -266,7 +265,10 @@ fun EditWebsearchDialog(
|
||||
},
|
||||
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(
|
||||
onClick = {
|
||||
@ -277,7 +279,10 @@ fun EditWebsearchDialog(
|
||||
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 {
|
||||
@ -411,7 +416,11 @@ private fun ColorPicker(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
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(
|
||||
value = textFieldValue,
|
||||
leadingIcon = {
|
||||
@ -425,7 +434,7 @@ private fun ColorPicker(
|
||||
},
|
||||
singleLine = true,
|
||||
modifier = Modifier.width(150.dp)
|
||||
)
|
||||
)
|
||||
TextButton(onClick = { showCustomColorPicker = false }) {
|
||||
Text(
|
||||
stringResource(android.R.string.ok),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user